KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > bridge > SVGFeOffsetElementBridge


1 /*
2
3    Copyright 2001-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.bridge;
19
20 import java.awt.geom.AffineTransform JavaDoc;
21 import java.awt.geom.Rectangle2D JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.apache.batik.ext.awt.image.PadMode;
25 import org.apache.batik.ext.awt.image.renderable.AffineRable8Bit;
26 import org.apache.batik.ext.awt.image.renderable.Filter;
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 JavaDoc;
31
32 /**
33  * Bridge class for the <feOffset> element.
34  *
35  * @author <a HREF="mailto:tkormann@apache.org">Thierry Kormann</a>
36  * @version $Id: SVGFeOffsetElementBridge.java,v 1.15 2004/08/18 07:12:34 vhardy Exp $
37  */

38 public class SVGFeOffsetElementBridge
39     extends AbstractSVGFilterPrimitiveElementBridge {
40
41     /**
42      * Constructs a new bridge for the &lt;feOffset> element.
43      */

44     public SVGFeOffsetElementBridge() {}
45
46     /**
47      * Returns 'feOffset'.
48      */

49     public String JavaDoc getLocalName() {
50         return SVG_FE_OFFSET_TAG;
51     }
52
53     /**
54      * Creates a <tt>Filter</tt> primitive according to the specified
55      * parameters.
56      *
57      * @param ctx the bridge context to use
58      * @param filterElement the element that defines a filter
59      * @param filteredElement the element that references the filter
60      * @param filteredNode the graphics node to filter
61      *
62      * @param inputFilter the <tt>Filter</tt> that represents the current
63      * filter input if the filter chain.
64      * @param filterRegion the filter area defined for the filter chain
65      * the new node will be part of.
66      * @param filterMap a map where the mediator can map a name to the
67      * <tt>Filter</tt> it creates. Other <tt>FilterBridge</tt>s
68      * can then access a filter node from the filterMap if they
69      * know its name.
70      */

71     public Filter createFilter(BridgeContext ctx,
72                                Element JavaDoc filterElement,
73                                Element JavaDoc filteredElement,
74                                GraphicsNode filteredNode,
75                                Filter inputFilter,
76                                Rectangle2D JavaDoc filterRegion,
77                                Map JavaDoc filterMap) {
78
79
80         // 'in' attribute
81
Filter in = getIn(filterElement,
82                           filteredElement,
83                           filteredNode,
84                           inputFilter,
85                           filterMap,
86                           ctx);
87         if (in == null) {
88             return null; // disable the filter
89
}
90
91         // Default region is the size of in (if in is SourceGraphic or
92
// SourceAlpha it will already include a pad/crop to the
93
// proper filter region size).
94
Rectangle2D JavaDoc defaultRegion = in.getBounds2D();
95         Rectangle2D JavaDoc primitiveRegion
96             = SVGUtilities.convertFilterPrimitiveRegion(filterElement,
97                                                         filteredElement,
98                                                         filteredNode,
99                                                         defaultRegion,
100                                                         filterRegion,
101                                                         ctx);
102
103         float dx = convertNumber(filterElement, SVG_DX_ATTRIBUTE, 0);
104         float dy = convertNumber(filterElement, SVG_DY_ATTRIBUTE, 0);
105         AffineTransform JavaDoc at = AffineTransform.getTranslateInstance(dx, dy);
106
107         // feOffset is a point operation. Therefore, to take the
108
// filter primitive region into account, only a pad operation
109
// on the input is required.
110
PadRable pad = new PadRable8Bit(in, primitiveRegion, PadMode.ZERO_PAD);
111         Filter filter = new AffineRable8Bit(pad, at);
112         filter = new PadRable8Bit(filter, primitiveRegion, PadMode.ZERO_PAD);
113
114         // handle the 'color-interpolation-filters' property
115
handleColorInterpolationFilters(filter, filterElement);
116
117         // update the filter Map
118
updateFilterMap(filterElement, filter, filterMap);
119
120         return filter;
121     }
122 }
123
Popular Tags