1 18 package org.apache.batik.bridge; 19 20 import java.awt.geom.Rectangle2D ; 21 import java.util.Map ; 22 import java.util.StringTokenizer ; 23 24 import org.apache.batik.ext.awt.image.PadMode; 25 import org.apache.batik.ext.awt.image.renderable.Filter; 26 import org.apache.batik.ext.awt.image.renderable.GaussianBlurRable8Bit; 27 import org.apache.batik.ext.awt.image.renderable.PadRable; 28 import org.apache.batik.ext.awt.image.renderable.PadRable8Bit; 29 import org.apache.batik.gvt.GraphicsNode; 30 import org.w3c.dom.Element ; 31 32 38 public class SVGFeGaussianBlurElementBridge 39 extends AbstractSVGFilterPrimitiveElementBridge { 40 41 42 45 public SVGFeGaussianBlurElementBridge() {} 46 47 50 public String getLocalName() { 51 return SVG_FE_GAUSSIAN_BLUR_TAG; 52 } 53 54 72 public Filter createFilter(BridgeContext ctx, 73 Element filterElement, 74 Element filteredElement, 75 GraphicsNode filteredNode, 76 Filter inputFilter, 77 Rectangle2D filterRegion, 78 Map filterMap) { 79 80 float [] stdDeviationXY = convertStdDeviation(filterElement); 82 if (stdDeviationXY[0] < 0 || stdDeviationXY[1] < 0) { 83 throw new BridgeException(filterElement, 84 ERR_ATTRIBUTE_VALUE_MALFORMED, 85 new Object [] {SVG_STD_DEVIATION_ATTRIBUTE, 86 "" + stdDeviationXY[0] + 87 stdDeviationXY[1]}); 88 } 89 90 Filter in = getIn(filterElement, 92 filteredElement, 93 filteredNode, 94 inputFilter, 95 filterMap, 96 ctx); 97 if (in == null) { 98 return null; } 100 101 Rectangle2D defaultRegion = in.getBounds2D(); 105 Rectangle2D primitiveRegion 106 = SVGUtilities.convertFilterPrimitiveRegion(filterElement, 107 filteredElement, 108 filteredNode, 109 defaultRegion, 110 filterRegion, 111 ctx); 112 113 PadRable pad = new PadRable8Bit(in, primitiveRegion, PadMode.ZERO_PAD); 116 117 Filter blur = new GaussianBlurRable8Bit 119 (pad, stdDeviationXY[0], stdDeviationXY[1]); 120 121 handleColorInterpolationFilters(blur, filterElement); 123 124 PadRable filter 125 = new PadRable8Bit(blur, primitiveRegion, PadMode.ZERO_PAD); 126 127 updateFilterMap(filterElement, filter, filterMap); 129 130 return filter; 131 } 132 133 139 protected static float [] convertStdDeviation(Element filterElement) { 140 String s 141 = filterElement.getAttributeNS(null, SVG_STD_DEVIATION_ATTRIBUTE); 142 if (s.length() == 0) { 143 return new float[] {0, 0}; 144 } 145 float [] stdDevs = new float[2]; 146 StringTokenizer tokens = new StringTokenizer (s, " ,"); 147 try { 148 stdDevs[0] = SVGUtilities.convertSVGNumber(tokens.nextToken()); 149 if (tokens.hasMoreTokens()) { 150 stdDevs[1] = SVGUtilities.convertSVGNumber(tokens.nextToken()); 151 } else { 152 stdDevs[1] = stdDevs[0]; 153 } 154 } catch (NumberFormatException ex) { 155 throw new BridgeException 156 (filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED, 157 new Object [] {SVG_STD_DEVIATION_ATTRIBUTE, s, ex}); 158 } 159 if (tokens.hasMoreTokens()) { 160 throw new BridgeException 161 (filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED, 162 new Object [] {SVG_STD_DEVIATION_ATTRIBUTE, s}); 163 } 164 return stdDevs; 165 } 166 } 167 | Popular Tags |