1 18 package org.apache.batik.bridge; 19 20 import java.awt.geom.Rectangle2D ; 21 import java.util.Map ; 22 23 import org.apache.batik.ext.awt.image.Light; 24 import org.apache.batik.ext.awt.image.renderable.Filter; 25 import org.apache.batik.ext.awt.image.renderable.SpecularLightingRable8Bit; 26 import org.apache.batik.gvt.GraphicsNode; 27 import org.w3c.dom.Element ; 28 29 35 public class SVGFeSpecularLightingElementBridge 36 extends AbstractSVGLightingElementBridge { 37 38 39 42 public SVGFeSpecularLightingElementBridge() {} 43 44 47 public String getLocalName() { 48 return SVG_FE_SPECULAR_LIGHTING_TAG; 49 } 50 51 69 public Filter createFilter(BridgeContext ctx, 70 Element filterElement, 71 Element filteredElement, 72 GraphicsNode filteredNode, 73 Filter inputFilter, 74 Rectangle2D filterRegion, 75 Map filterMap) { 76 77 78 float surfaceScale 80 = convertNumber(filterElement, SVG_SURFACE_SCALE_ATTRIBUTE, 1); 81 82 float specularConstant 84 = convertNumber(filterElement, SVG_SPECULAR_CONSTANT_ATTRIBUTE, 1); 85 86 float specularExponent = convertSpecularExponent(filterElement); 88 89 Light light = extractLight(filterElement, ctx); 91 92 double [] kernelUnitLength = convertKernelUnitLength(filterElement); 94 95 Filter in = getIn(filterElement, 97 filteredElement, 98 filteredNode, 99 inputFilter, 100 filterMap, 101 ctx); 102 if (in == null) { 103 return null; } 105 106 Rectangle2D defaultRegion = in.getBounds2D(); 110 Rectangle2D primitiveRegion 111 = SVGUtilities.convertFilterPrimitiveRegion(filterElement, 112 filteredElement, 113 filteredNode, 114 defaultRegion, 115 filterRegion, 116 ctx); 117 118 Filter filter = new SpecularLightingRable8Bit(in, 119 primitiveRegion, 120 light, 121 specularConstant, 122 specularExponent, 123 surfaceScale, 124 kernelUnitLength); 125 126 127 handleColorInterpolationFilters(filter, filterElement); 129 130 updateFilterMap(filterElement, filter, filterMap); 132 133 return filter; 134 } 135 136 142 protected static float convertSpecularExponent(Element filterElement) { 143 String s = filterElement.getAttributeNS 144 (null, SVG_SPECULAR_EXPONENT_ATTRIBUTE); 145 if (s.length() == 0) { 146 return 1; } else { 148 try { 149 float v = SVGUtilities.convertSVGNumber(s); 150 if (v < 1 || v > 128) { 151 throw new BridgeException 152 (filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED, 153 new Object [] {SVG_SPECULAR_CONSTANT_ATTRIBUTE, s}); 154 } 155 return v; 156 } catch (NumberFormatException ex) { 157 throw new BridgeException 158 (filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED, 159 new Object [] {SVG_SPECULAR_CONSTANT_ATTRIBUTE, s, ex}); 160 } 161 } 162 } 163 } 164 | Popular Tags |