1 18 package org.apache.batik.bridge; 19 20 import java.awt.geom.Rectangle2D ; 21 import java.util.ArrayList ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import org.apache.batik.ext.awt.image.CompositeRule; 26 import org.apache.batik.ext.awt.image.PadMode; 27 import org.apache.batik.ext.awt.image.renderable.CompositeRable8Bit; 28 import org.apache.batik.ext.awt.image.renderable.Filter; 29 import org.apache.batik.ext.awt.image.renderable.PadRable8Bit; 30 import org.apache.batik.gvt.GraphicsNode; 31 import org.w3c.dom.Element ; 32 33 39 public class SVGFeBlendElementBridge 40 extends AbstractSVGFilterPrimitiveElementBridge { 41 42 43 46 public SVGFeBlendElementBridge() {} 47 48 51 public String getLocalName() { 52 return SVG_FE_BLEND_TAG; 53 } 54 55 73 public Filter createFilter(BridgeContext ctx, 74 Element filterElement, 75 Element filteredElement, 76 GraphicsNode filteredNode, 77 Filter inputFilter, 78 Rectangle2D filterRegion, 79 Map filterMap) { 80 81 82 CompositeRule rule = convertMode(filterElement); 84 85 Filter in = getIn(filterElement, 87 filteredElement, 88 filteredNode, 89 inputFilter, 90 filterMap, 91 ctx); 92 if (in == null) { 93 return null; } 95 96 Filter in2 = getIn2(filterElement, 98 filteredElement, 99 filteredNode, 100 inputFilter, 101 filterMap, 102 ctx); 103 if (in2 == null) { 104 return null; } 106 107 Rectangle2D defaultRegion; 108 defaultRegion = (Rectangle2D )in.getBounds2D().clone(); 109 defaultRegion.add(in2.getBounds2D()); 110 111 Rectangle2D primitiveRegion 113 = SVGUtilities.convertFilterPrimitiveRegion(filterElement, 114 filteredElement, 115 filteredNode, 116 defaultRegion, 117 filterRegion, 118 ctx); 119 120 List srcs = new ArrayList (2); 122 srcs.add(in2); 123 srcs.add(in); 124 125 Filter filter = new CompositeRable8Bit(srcs, rule, true); 126 handleColorInterpolationFilters(filter, filterElement); 128 129 filter = new PadRable8Bit(filter, primitiveRegion, PadMode.ZERO_PAD); 130 131 updateFilterMap(filterElement, filter, filterMap); 133 134 135 return filter; 136 } 137 138 143 protected static CompositeRule convertMode(Element filterElement) { 144 String rule = filterElement.getAttributeNS(null, SVG_MODE_ATTRIBUTE); 145 if (rule.length() == 0) { 146 return CompositeRule.OVER; 147 } 148 if (SVG_NORMAL_VALUE.equals(rule)) { 149 return CompositeRule.OVER; 150 } 151 if (SVG_MULTIPLY_VALUE.equals(rule)) { 152 return CompositeRule.MULTIPLY; 153 } 154 if (SVG_SCREEN_VALUE.equals(rule)) { 155 return CompositeRule.SCREEN; 156 } 157 if (SVG_DARKEN_VALUE.equals(rule)) { 158 return CompositeRule.DARKEN; 159 } 160 if (SVG_LIGHTEN_VALUE.equals(rule)) { 161 return CompositeRule.LIGHTEN; 162 } 163 throw new BridgeException(filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED, 164 new Object [] {SVG_MODE_ATTRIBUTE, rule}); 165 } 166 } 167 | Popular Tags |