1 18 package org.apache.batik.ext.awt.image.renderable; 19 20 import java.awt.Composite ; 21 import java.awt.Graphics2D ; 22 import java.awt.RenderingHints ; 23 import java.awt.Shape ; 24 import java.awt.geom.AffineTransform ; 25 import java.awt.geom.Rectangle2D ; 26 import java.awt.image.BufferedImage ; 27 import java.awt.image.RenderedImage ; 28 import java.awt.image.renderable.RenderContext ; 29 30 import org.apache.batik.ext.awt.image.GraphicsUtil; 31 import org.apache.batik.ext.awt.image.PadMode; 32 import org.apache.batik.ext.awt.image.SVGComposite; 33 import org.apache.batik.ext.awt.image.rendered.CachableRed; 34 import org.apache.batik.ext.awt.image.rendered.PadRed; 35 36 43 public class PadRable8Bit extends AbstractRable 44 implements PadRable, PaintRable { 45 46 PadMode padMode; 47 Rectangle2D padRect; 48 49 public PadRable8Bit(Filter src, 50 Rectangle2D padRect, 51 PadMode padMode) { 52 super.init(src, null); 53 this.padRect = padRect; 54 this.padMode = padMode; 55 } 56 57 60 public Filter getSource() { 61 return (Filter)srcs.get(0); 62 } 63 64 68 public void setSource(Filter src) { 69 super.init(src, null); 70 } 71 72 public Rectangle2D getBounds2D() { 73 return (Rectangle2D )padRect.clone(); 74 } 75 76 80 public void setPadRect(Rectangle2D rect) { 81 touch(); 82 this.padRect = rect; 83 } 84 85 89 public Rectangle2D getPadRect() { 90 return (Rectangle2D )padRect.clone(); 91 } 92 93 97 public void setPadMode(PadMode padMode) { 98 touch(); 99 this.padMode = padMode; 100 } 101 102 106 public PadMode getPadMode() { 107 return padMode; 108 } 109 110 120 public boolean paintRable(Graphics2D g2d) { 121 Composite c = g2d.getComposite(); 124 if (!SVGComposite.OVER.equals(c)) 125 return false; 126 127 if (getPadMode() != PadMode.ZERO_PAD) 128 return false; 129 130 Rectangle2D padBounds = getPadRect(); 131 132 Shape clip = g2d.getClip(); 133 g2d.clip(padBounds); 134 GraphicsUtil.drawImage(g2d, getSource()); 135 g2d.setClip(clip); 136 return true; 137 } 138 139 public RenderedImage createRendering(RenderContext rc) { 140 RenderingHints rh = rc.getRenderingHints(); 141 if (rh == null) rh = new RenderingHints (null); 142 143 Filter src = getSource(); 144 Shape aoi = rc.getAreaOfInterest(); 145 146 if(aoi == null){ 147 aoi = getBounds2D(); 148 } 149 150 AffineTransform usr2dev = rc.getTransform(); 151 152 Rectangle2D srect = src.getBounds2D(); 156 Rectangle2D rect = getBounds2D(); 157 Rectangle2D arect = aoi.getBounds2D(); 158 159 if (arect.intersects(rect) == false) 163 return null; 164 Rectangle2D.intersect(arect, rect, arect); 165 166 RenderedImage ri = null; 167 if (arect.intersects(srect) == true) { 168 srect = (Rectangle2D )srect.clone(); 169 Rectangle2D.intersect(srect, arect, srect); 170 171 RenderContext srcRC = new RenderContext (usr2dev, srect, rh); 172 ri = src.createRendering(srcRC); 173 174 } 177 178 if (ri == null) 180 ri = new BufferedImage (1, 1, BufferedImage.TYPE_INT_ARGB); 181 182 185 CachableRed cr = GraphicsUtil.wrap(ri); 186 187 arect = usr2dev.createTransformedShape(arect).getBounds2D(); 188 189 cr = new PadRed(cr, arect.getBounds(), padMode, rh); 192 return cr; 193 } 194 195 public Shape getDependencyRegion(int srcIndex, Rectangle2D outputRgn) { 196 if (srcIndex != 0) 197 throw new IndexOutOfBoundsException ("Affine only has one input"); 198 199 Rectangle2D srect = getSource().getBounds2D(); 203 if (srect.intersects(outputRgn) == false) 204 return new Rectangle2D.Float (); 205 Rectangle2D.intersect(srect, outputRgn, srect); 206 207 Rectangle2D bounds = getBounds2D(); 208 if (srect.intersects(bounds) == false) 209 return new Rectangle2D.Float (); 210 Rectangle2D.intersect(srect, bounds, srect); 211 return srect; 212 } 213 214 public Shape getDirtyRegion(int srcIndex, Rectangle2D inputRgn) { 215 if (srcIndex != 0) 216 throw new IndexOutOfBoundsException ("Affine only has one input"); 217 218 inputRgn = (Rectangle2D )inputRgn.clone(); 219 Rectangle2D bounds = getBounds2D(); 220 if (inputRgn.intersects(bounds) == false) 223 return new Rectangle2D.Float (); 224 Rectangle2D.intersect(inputRgn, bounds, inputRgn); 225 return inputRgn; 226 } 227 228 } 229 | Popular Tags |