1 28 package net.sf.jasperreports.engine; 29 30 import java.awt.Color ; 31 import java.awt.Graphics2D ; 32 import java.awt.Rectangle ; 33 import java.awt.geom.Dimension2D ; 34 import java.awt.image.BufferedImage ; 35 36 import net.sf.jasperreports.engine.util.JRImageLoader; 37 38 39 43 public abstract class JRAbstractSvgRenderer extends JRAbstractRenderer 44 { 45 46 49 private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID; 50 51 52 55 public byte getType() 56 { 57 return TYPE_SVG; 58 } 59 60 61 64 public byte getImageType() 65 { 66 return IMAGE_TYPE_PNG; 67 } 68 69 70 73 public Dimension2D getDimension() 74 { 75 return null; 76 } 77 78 79 82 public Color getBackcolor() 83 { 84 return null; 85 } 86 87 88 91 public byte[] getImageData() throws JRException 92 { 93 Dimension2D dimension = getDimension(); 94 if (dimension != null) 95 { 96 byte imageType = getImageType(); 97 BufferedImage bi = 98 new BufferedImage ( 99 (int)dimension.getWidth(), 100 (int)dimension.getHeight(), 101 (imageType == JRRenderable.IMAGE_TYPE_GIF || imageType == JRRenderable.IMAGE_TYPE_PNG) 104 ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB 105 ); 106 107 Graphics2D g = bi.createGraphics(); 108 Color backcolor = getBackcolor(); 109 if (backcolor != null) 110 { 111 g.setColor(backcolor); 112 g.fillRect(0, 0, (int)dimension.getWidth(), (int)dimension.getHeight()); 113 } 114 render(g, new Rectangle ((int)dimension.getWidth(), (int)dimension.getHeight())); 115 g.dispose(); 116 117 return JRImageLoader.loadImageDataFromAWTImage(bi, getImageType()); 118 } 119 return null; 120 } 121 122 123 } 124 | Popular Tags |