1 18 package org.apache.batik.transcoder.image; 19 20 import java.awt.Color ; 21 import java.awt.Graphics2D ; 22 import java.awt.image.BufferedImage ; 23 24 import java.io.ByteArrayOutputStream ; 25 26 import java.util.Map ; 27 import java.util.HashMap ; 28 29 import org.apache.batik.transcoder.TranscoderInput; 30 import org.apache.batik.transcoder.TranscoderOutput; 31 32 import org.apache.batik.dom.svg.SVGDOMImplementation; 33 34 import org.w3c.dom.Document ; 35 import org.w3c.dom.Element ; 36 import org.w3c.dom.DOMImplementation ; 37 38 44 public class BackgroundColorTest extends AbstractImageTranscoderTest { 45 46 49 public BackgroundColorTest() { 50 } 51 52 55 protected TranscoderInput createTranscoderInput() { 56 DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); 57 String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; 58 Document doc = impl.createDocument(svgNS, "svg", null); 59 60 Element root = doc.getDocumentElement(); 61 62 root.setAttributeNS(null, "width", "400"); 63 root.setAttributeNS(null, "height", "400"); 64 65 Element r = doc.createElementNS(svgNS, "rect"); 66 r.setAttributeNS(null, "x", "100"); 67 r.setAttributeNS(null, "y", "50"); 68 r.setAttributeNS(null, "width", "100"); 69 r.setAttributeNS(null, "height", "50"); 70 r.setAttributeNS(null, "style", "fill:red"); 71 root.appendChild(r); 72 73 return new TranscoderInput(doc); 74 } 75 76 79 protected Map createTranscodingHints() { 80 Map hints = new HashMap (7); 81 hints.put(ImageTranscoder.KEY_BACKGROUND_COLOR, Color.blue); 82 return hints; 83 } 84 85 88 protected byte [] getReferenceImageData() { 89 try { 90 BufferedImage img = new BufferedImage 91 (400, 400, BufferedImage.TYPE_INT_ARGB); 92 Graphics2D g2d = img.createGraphics(); 93 g2d.setColor(Color.blue); 94 g2d.fillRect(0, 0, 400, 400); 95 g2d.setColor(Color.red); 96 g2d.fillRect(100, 50, 100, 50); 97 ByteArrayOutputStream ostream = new ByteArrayOutputStream (); 98 PNGTranscoder t = new PNGTranscoder(); 99 TranscoderOutput output = new TranscoderOutput(ostream); 100 t.writeImage(img, output); 101 return ostream.toByteArray(); 102 } catch (Exception ex) { 103 throw new RuntimeException ("BackgroundColorTest error"); 104 } 105 } 106 } 107 | Popular Tags |