KickJava   Java API By Example, From Geeks To Geeks.

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


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.Rectangle2D JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.apache.batik.ext.awt.image.CompositeRule;
26 import org.apache.batik.ext.awt.image.PadMode;
27 import org.apache.batik.ext.awt.image.renderable.CompositeRable8Bit;
28 import org.apache.batik.ext.awt.image.renderable.Filter;
29 import org.apache.batik.ext.awt.image.renderable.PadRable8Bit;
30 import org.apache.batik.gvt.GraphicsNode;
31 import org.w3c.dom.Element JavaDoc;
32
33 /**
34  * Bridge class for the <feBlend> element.
35  *
36  * @author <a HREF="mailto:tkormann@apache.org">Thierry Kormann</a>
37  * @version $Id: SVGFeBlendElementBridge.java,v 1.15 2004/08/18 07:12:33 vhardy Exp $
38  */

39 public class SVGFeBlendElementBridge
40     extends AbstractSVGFilterPrimitiveElementBridge {
41
42
43     /**
44      * Constructs a new bridge for the &lt;feBlend> element.
45      */

46     public SVGFeBlendElementBridge() {}
47
48     /**
49      * Returns 'feBlend'.
50      */

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

73     public Filter createFilter(BridgeContext ctx,
74                                Element JavaDoc filterElement,
75                                Element JavaDoc filteredElement,
76                                GraphicsNode filteredNode,
77                                Filter inputFilter,
78                                Rectangle2D JavaDoc filterRegion,
79                                Map JavaDoc filterMap) {
80
81
82         // 'mode' attribute - default is 'normal'
83
CompositeRule rule = convertMode(filterElement);
84
85         // 'in' attribute
86
Filter in = getIn(filterElement,
87                           filteredElement,
88                           filteredNode,
89                           inputFilter,
90                           filterMap,
91                           ctx);
92         if (in == null) {
93             return null; // disable the filter
94
}
95
96         // 'in2' attribute - required
97
Filter in2 = getIn2(filterElement,
98                             filteredElement,
99                             filteredNode,
100                             inputFilter,
101                             filterMap,
102                             ctx);
103         if (in2 == null) {
104             return null; // disable the filter
105
}
106
107         Rectangle2D JavaDoc defaultRegion;
108         defaultRegion = (Rectangle2D JavaDoc)in.getBounds2D().clone();
109         defaultRegion.add(in2.getBounds2D());
110
111         // get filter primitive chain region
112
Rectangle2D JavaDoc primitiveRegion
113             = SVGUtilities.convertFilterPrimitiveRegion(filterElement,
114                                                         filteredElement,
115                                                         filteredNode,
116                                                         defaultRegion,
117                                                         filterRegion,
118                                                         ctx);
119
120         // build the blend filter
121
List JavaDoc srcs = new ArrayList JavaDoc(2);
122         srcs.add(in2);
123         srcs.add(in);
124
125         Filter filter = new CompositeRable8Bit(srcs, rule, true);
126         // handle the 'color-interpolation-filters' property
127
handleColorInterpolationFilters(filter, filterElement);
128
129         filter = new PadRable8Bit(filter, primitiveRegion, PadMode.ZERO_PAD);
130
131         // update the filter Map
132
updateFilterMap(filterElement, filter, filterMap);
133
134
135         return filter;
136     }
137
138     /**
139      * Converts the 'mode' of the specified feBlend filter primitive.
140      *
141      * @param filterElement the filter feBlend element
142      */

143     protected static CompositeRule convertMode(Element JavaDoc filterElement) {
144         String JavaDoc rule = filterElement.getAttributeNS(null, SVG_MODE_ATTRIBUTE);
145         if (rule.length() == 0) {
146             return CompositeRule.OVER;
147         }
148         if (SVG_NORMAL_VALUE.equals(rule)) {
149             return CompositeRule.OVER;
150         }
151         if (SVG_MULTIPLY_VALUE.equals(rule)) {
152             return CompositeRule.MULTIPLY;
153         }
154         if (SVG_SCREEN_VALUE.equals(rule)) {
155             return CompositeRule.SCREEN;
156         }
157         if (SVG_DARKEN_VALUE.equals(rule)) {
158             return CompositeRule.DARKEN;
159         }
160         if (SVG_LIGHTEN_VALUE.equals(rule)) {
161             return CompositeRule.LIGHTEN;
162         }
163         throw new BridgeException(filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED,
164                                   new Object JavaDoc[] {SVG_MODE_ATTRIBUTE, rule});
165     }
166 }
167
Popular Tags