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 SVGFeCompositeElementBridge 40 extends AbstractSVGFilterPrimitiveElementBridge { 41 42 43 46 public SVGFeCompositeElementBridge() {} 47 48 51 public String getLocalName() { 52 return SVG_FE_COMPOSITE_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 CompositeRule rule = convertOperator(filterElement); 83 84 Filter in = getIn(filterElement, 86 filteredElement, 87 filteredNode, 88 inputFilter, 89 filterMap, 90 ctx); 91 if (in == null) { 92 return null; } 94 95 Filter in2 = getIn2(filterElement, 97 filteredElement, 98 filteredNode, 99 inputFilter, 100 filterMap, 101 ctx); 102 if (in2 == null) { 103 return null; } 105 106 Rectangle2D defaultRegion; 107 defaultRegion = (Rectangle2D )in.getBounds2D().clone(); 108 defaultRegion.add(in2.getBounds2D()); 109 110 Rectangle2D primitiveRegion 112 = SVGUtilities.convertFilterPrimitiveRegion(filterElement, 113 filteredElement, 114 filteredNode, 115 defaultRegion, 116 filterRegion, 117 ctx); 118 119 List srcs = new ArrayList (2); 120 srcs.add(in2); 121 srcs.add(in); 122 Filter filter = new CompositeRable8Bit(srcs, rule, true); 123 124 handleColorInterpolationFilters(filter, filterElement); 126 127 filter = new PadRable8Bit(filter, primitiveRegion, PadMode.ZERO_PAD); 128 129 updateFilterMap(filterElement, filter, filterMap); 131 132 return filter; 133 } 134 135 141 protected static CompositeRule convertOperator(Element filterElement) { 142 String s = filterElement.getAttributeNS(null, SVG_OPERATOR_ATTRIBUTE); 143 if (s.length() == 0) { 144 return CompositeRule.OVER; } 146 if (SVG_ATOP_VALUE.equals(s)) { 147 return CompositeRule.ATOP; 148 } 149 if (SVG_IN_VALUE.equals(s)) { 150 return CompositeRule.IN; 151 } 152 if (SVG_OVER_VALUE.equals(s)) { 153 return CompositeRule.OVER; 154 } 155 if (SVG_OUT_VALUE.equals(s)) { 156 return CompositeRule.OUT; 157 } 158 if (SVG_XOR_VALUE.equals(s)) { 159 return CompositeRule.XOR; 160 } 161 if (SVG_ARITHMETIC_VALUE.equals(s)) { 162 float k1 = convertNumber(filterElement, SVG_K1_ATTRIBUTE, 0); 163 float k2 = convertNumber(filterElement, SVG_K2_ATTRIBUTE, 0); 164 float k3 = convertNumber(filterElement, SVG_K3_ATTRIBUTE, 0); 165 float k4 = convertNumber(filterElement, SVG_K4_ATTRIBUTE, 0); 166 return CompositeRule.ARITHMETIC(k1, k2, k3, k4); 167 } 168 throw new BridgeException(filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED, 169 new Object [] {SVG_OPERATOR_ATTRIBUTE, s}); 170 } 171 } 172 | Popular Tags |