1 18 package org.apache.batik.bridge; 19 20 import java.awt.geom.Rectangle2D ; 21 import java.util.Iterator ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 import java.util.Map ; 25 26 import org.apache.batik.ext.awt.image.CompositeRule; 27 import org.apache.batik.ext.awt.image.PadMode; 28 import org.apache.batik.ext.awt.image.renderable.CompositeRable8Bit; 29 import org.apache.batik.ext.awt.image.renderable.Filter; 30 import org.apache.batik.ext.awt.image.renderable.PadRable8Bit; 31 import org.apache.batik.gvt.GraphicsNode; 32 import org.w3c.dom.Element ; 33 import org.w3c.dom.Node ; 34 35 41 public class SVGFeMergeElementBridge 42 extends AbstractSVGFilterPrimitiveElementBridge { 43 44 47 public SVGFeMergeElementBridge() {} 48 49 52 public String getLocalName() { 53 return SVG_FE_MERGE_TAG; 54 } 55 56 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 List srcs = extractFeMergeNode(filterElement, 82 filteredElement, 83 filteredNode, 84 inputFilter, 85 filterMap, 86 ctx); 87 88 if (srcs == null) { 89 return null; } 91 92 if (srcs.size() == 0) { 93 return null; } 95 96 Iterator iter = srcs.iterator(); 98 Rectangle2D defaultRegion = 99 (Rectangle2D )((Filter)iter.next()).getBounds2D().clone(); 100 101 while (iter.hasNext()) { 102 defaultRegion.add(((Filter)iter.next()).getBounds2D()); 103 } 104 105 Rectangle2D primitiveRegion 107 = SVGUtilities.convertFilterPrimitiveRegion(filterElement, 108 filteredElement, 109 filteredNode, 110 defaultRegion, 111 filterRegion, 112 ctx); 113 114 Filter filter = new CompositeRable8Bit(srcs, CompositeRule.OVER, true); 115 116 handleColorInterpolationFilters(filter, filterElement); 118 119 filter = new PadRable8Bit(filter, primitiveRegion, PadMode.ZERO_PAD); 120 121 updateFilterMap(filterElement, filter, filterMap); 123 124 return filter; 125 } 126 127 128 140 protected static List extractFeMergeNode(Element filterElement, 141 Element filteredElement, 142 GraphicsNode filteredNode, 143 Filter inputFilter, 144 Map filterMap, 145 BridgeContext ctx) { 146 147 List srcs = null; 148 for (Node n = filterElement.getFirstChild(); 149 n != null; 150 n = n.getNextSibling()) { 151 152 if (n.getNodeType() != Node.ELEMENT_NODE) { 153 continue; 154 } 155 156 Element e = (Element )n; 157 Bridge bridge = ctx.getBridge(e); 158 if (bridge == null || 159 !(bridge instanceof SVGFeMergeNodeElementBridge)) { 160 continue; 161 } 162 Filter filter = ((SVGFeMergeNodeElementBridge)bridge).createFilter 163 (ctx, 164 e, 165 filteredElement, 166 filteredNode, 167 inputFilter, 168 filterMap); 169 if (filter != null) { 170 if (srcs == null) { 171 srcs = new LinkedList (); 172 } 173 srcs.add(filter); 174 } 175 } 176 return srcs; 177 } 178 179 182 public static class SVGFeMergeNodeElementBridge extends AbstractSVGBridge { 183 184 187 public SVGFeMergeNodeElementBridge() {} 188 189 192 public String getLocalName() { 193 return SVG_FE_MERGE_NODE_TAG; 194 } 195 196 210 public Filter createFilter(BridgeContext ctx, 211 Element filterElement, 212 Element filteredElement, 213 GraphicsNode filteredNode, 214 Filter inputFilter, 215 Map filterMap) { 216 return getIn(filterElement, 217 filteredElement, 218 filteredNode, 219 inputFilter, 220 filterMap, 221 ctx); 222 } 223 } 224 } 225 | Popular Tags |