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.Rectangle ; 23 import java.awt.RenderingHints ; 24 import java.awt.Shape ; 25 import java.awt.color.ColorSpace ; 26 import java.awt.geom.AffineTransform ; 27 import java.awt.geom.Rectangle2D ; 28 import java.awt.image.RenderedImage ; 29 import java.awt.image.renderable.RenderContext ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 import java.util.Vector ; 33 34 import org.apache.batik.ext.awt.image.CompositeRule; 35 import org.apache.batik.ext.awt.image.GraphicsUtil; 36 import org.apache.batik.ext.awt.image.SVGComposite; 37 import org.apache.batik.ext.awt.image.rendered.CachableRed; 38 import org.apache.batik.ext.awt.image.rendered.CompositeRed; 39 import org.apache.batik.ext.awt.image.rendered.FloodRed; 40 41 48 public class CompositeRable8Bit 49 extends AbstractColorInterpolationRable 50 implements CompositeRable, PaintRable { 51 52 protected CompositeRule rule; 53 54 public CompositeRable8Bit(List srcs, 55 CompositeRule rule, 56 boolean csIsLinear) { 57 super(srcs); 58 59 setColorSpaceLinear(csIsLinear); 60 61 this.rule = rule; 62 } 63 64 68 public void setSources(List srcs) { 69 init(srcs, null); 70 } 71 72 76 public void setCompositeRule(CompositeRule cr) { 77 touch(); 78 this.rule = cr; 79 } 80 81 85 public CompositeRule getCompositeRule() { 86 return this.rule; 87 } 88 89 99 public boolean paintRable(Graphics2D g2d) { 100 Composite c = g2d.getComposite(); 103 if (!SVGComposite.OVER.equals(c)) 104 return false; 105 106 if (getCompositeRule() != CompositeRule.OVER) 108 return false; 109 110 ColorSpace crCS = getOperationColorSpace(); 111 ColorSpace g2dCS = GraphicsUtil.getDestinationColorSpace(g2d); 112 if ((g2dCS == null) || (g2dCS != crCS)) { 113 return false; 114 } 115 116 Iterator i = getSources().iterator(); 119 while (i.hasNext()) { 120 GraphicsUtil.drawImage(g2d, (Filter)i.next()); 121 } 122 return true; 123 } 124 125 public RenderedImage createRendering(RenderContext rc) { 126 if (srcs.size() == 0) 127 return null; 128 129 RenderingHints rh = rc.getRenderingHints(); 131 if (rh == null) rh = new RenderingHints (null); 132 133 AffineTransform at = rc.getTransform(); 135 136 Shape aoi = rc.getAreaOfInterest(); 137 Rectangle2D aoiR; 138 if (aoi == null) 139 aoiR = getBounds2D(); 140 else { 141 aoiR = aoi.getBounds2D(); 142 Rectangle2D bounds2d = getBounds2D(); 143 if (bounds2d.intersects(aoiR) == false) 144 return null; 145 146 Rectangle2D.intersect(aoiR, bounds2d, aoiR); 147 } 148 149 Rectangle devRect = at.createTransformedShape(aoiR).getBounds(); 150 151 rc = new RenderContext (at, aoiR, rh); 152 153 Vector srcs = new Vector (); 154 155 Iterator i = getSources().iterator(); 156 while (i.hasNext()) { 157 Filter filt = (Filter)i.next(); 159 160 RenderedImage ri = filt.createRendering(rc); 162 if (ri != null) { 163 CachableRed cr; 164 cr = convertSourceCS(ri); 165 srcs.add(cr); 166 } else { 167 168 switch (rule.getRule()) { 170 case CompositeRule.RULE_IN: 171 return null; 174 175 case CompositeRule.RULE_OUT: 176 srcs.clear(); 179 break; 180 181 case CompositeRule.RULE_ARITHMETIC: 182 srcs.add(new FloodRed(devRect)); 183 break; 184 185 default: 186 break; 189 } 190 } 191 } 192 193 if (srcs.size() == 0) 194 return null; 195 196 CachableRed cr = new CompositeRed(srcs, rule); 198 return cr; 199 } 200 } 201 | Popular Tags |