1 18 package org.apache.batik.ext.awt.image.renderable; 19 20 import java.awt.Rectangle ; 21 import java.awt.RenderingHints ; 22 import java.awt.Shape ; 23 import java.awt.geom.AffineTransform ; 24 import java.awt.geom.Rectangle2D ; 25 import java.awt.image.RenderedImage ; 26 import java.awt.image.renderable.RenderContext ; 27 28 import org.apache.batik.ext.awt.image.rendered.AffineRed; 29 import org.apache.batik.ext.awt.image.rendered.CachableRed; 30 import org.apache.batik.ext.awt.image.rendered.TranslateRed; 31 32 39 public class RedRable 40 extends AbstractRable { 41 CachableRed src; 42 43 public RedRable(CachableRed src) { 44 super((Filter)null); 45 this.src = src; 46 } 47 48 public CachableRed getSource() { 49 return src; 50 } 51 52 public Object getProperty(String name) { 53 return src.getProperty(name); 54 } 55 56 public String [] getPropertyNames() { 57 return src.getPropertyNames(); 58 } 59 60 public Rectangle2D getBounds2D() { 61 return getSource().getBounds(); 62 } 63 64 public RenderedImage createDefaultRendering() { 65 return getSource(); 66 } 67 68 69 public RenderedImage createRendering(RenderContext rc) { 70 72 RenderingHints rh = rc.getRenderingHints(); 74 if (rh == null) rh = new RenderingHints (null); 75 76 Shape aoi = rc.getAreaOfInterest(); 77 Rectangle aoiR; 78 if (aoi != null) 79 aoiR = aoi.getBounds(); 80 else 81 aoiR = getBounds2D().getBounds(); 82 83 AffineTransform at = rc.getTransform(); 85 86 CachableRed cr = getSource(); 90 91 if (aoiR.intersects(cr.getBounds()) == false) 92 return null; 93 94 if (at.isIdentity()) { 95 return cr; 97 } 98 99 if ((at.getScaleX() == 1.0) && (at.getScaleY() == 1.0) && 100 (at.getShearX() == 0.0) && (at.getShearY() == 0.0)) { 101 int xloc = (int)(cr.getMinX()+at.getTranslateX()); 102 int yloc = (int)(cr.getMinY()+at.getTranslateY()); 103 double dx = xloc - (cr.getMinX()+at.getTranslateX()); 104 double dy = yloc - (cr.getMinY()+at.getTranslateY()); 105 if (((dx > -0.0001) && (dx < 0.0001)) && 106 ((dy > -0.0001) && (dy < 0.0001))) { 107 return new TranslateRed(cr, xloc, yloc); 109 } 110 } 111 112 return new AffineRed(cr, at, rh); 114 } 115 } 116 | Popular Tags |