001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.bridge;
020:
021: import java.awt.geom.Rectangle2D;
022: import java.util.Map;
023:
024: import org.apache.batik.ext.awt.image.Light;
025: import org.apache.batik.ext.awt.image.renderable.DiffuseLightingRable8Bit;
026: import org.apache.batik.ext.awt.image.renderable.Filter;
027: import org.apache.batik.gvt.GraphicsNode;
028: import org.w3c.dom.Element;
029:
030: /**
031: * Bridge class for the <feDiffuseLighting> element.
032: *
033: * @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
034: * @version $Id: SVGFeDiffuseLightingElementBridge.java 475477 2006-11-15 22:44:28Z cam $
035: */
036: public class SVGFeDiffuseLightingElementBridge extends
037: AbstractSVGLightingElementBridge {
038:
039: /**
040: * Constructs a new bridge for the <feDiffuseLighting> element.
041: */
042: public SVGFeDiffuseLightingElementBridge() {
043: }
044:
045: /**
046: * Returns 'feDiffuseLighting'.
047: */
048: public String getLocalName() {
049: return SVG_FE_DIFFUSE_LIGHTING_TAG;
050: }
051:
052: /**
053: * Creates a <tt>Filter</tt> primitive according to the specified
054: * parameters.
055: *
056: * @param ctx the bridge context to use
057: * @param filterElement the element that defines a filter
058: * @param filteredElement the element that references the filter
059: * @param filteredNode the graphics node to filter
060: *
061: * @param inputFilter the <tt>Filter</tt> that represents the current
062: * filter input if the filter chain.
063: * @param filterRegion the filter area defined for the filter chain
064: * the new node will be part of.
065: * @param filterMap a map where the mediator can map a name to the
066: * <tt>Filter</tt> it creates. Other <tt>FilterBridge</tt>s
067: * can then access a filter node from the filterMap if they
068: * know its name.
069: */
070: public Filter createFilter(BridgeContext ctx,
071: Element filterElement, Element filteredElement,
072: GraphicsNode filteredNode, Filter inputFilter,
073: Rectangle2D filterRegion, Map filterMap) {
074:
075: // 'surfaceScale' attribute - default is 1
076: float surfaceScale = convertNumber(filterElement,
077: SVG_SURFACE_SCALE_ATTRIBUTE, 1, ctx);
078:
079: // 'diffuseConstant' attribute - default is 1
080: float diffuseConstant = convertNumber(filterElement,
081: SVG_DIFFUSE_CONSTANT_ATTRIBUTE, 1, ctx);
082:
083: // 'kernelUnitLength' attribute
084: // <!> FIXME: Why is it ignored ???
085:
086: // extract the light definition from the filterElement's children list
087: Light light = extractLight(filterElement, ctx);
088:
089: // 'kernelUnitLength' attribute
090: double[] kernelUnitLength = convertKernelUnitLength(
091: filterElement, ctx);
092:
093: // 'in' attribute
094: Filter in = getIn(filterElement, filteredElement, filteredNode,
095: inputFilter, filterMap, ctx);
096: if (in == null) {
097: return null; // disable the filter
098: }
099:
100: // Default region is the size of in (if in is SourceGraphic or
101: // SourceAlpha it will already include a pad/crop to the
102: // proper filter region size).
103: Rectangle2D defaultRegion = in.getBounds2D();
104: Rectangle2D primitiveRegion = SVGUtilities
105: .convertFilterPrimitiveRegion(filterElement,
106: filteredElement, filteredNode, defaultRegion,
107: filterRegion, ctx);
108: Filter filter = new DiffuseLightingRable8Bit(in,
109: primitiveRegion, light, diffuseConstant, surfaceScale,
110: kernelUnitLength);
111:
112: // handle the 'color-interpolation-filters' property
113: handleColorInterpolationFilters(filter, filterElement);
114:
115: // update the filter Map
116: updateFilterMap(filterElement, filter, filterMap);
117:
118: return filter;
119: }
120: }
|