source: josm/trunk/src/com/kitfox/svg/Filter.java@ 15912

Last change on this file since 15912 was 11525, checked in by Don-vip, 8 years ago

see #14319 - update to latest version of svgSalamander (2017-01-07, patched)

  • Property svn:eol-style set to native
File size: 7.1 KB
Line 
1/*
2 * SVG Salamander
3 * Copyright (c) 2004, Mark McKay
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
9 *
10 * - Redistributions of source code must retain the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials
16 * provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 * OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
32 * projects can be found at http://www.kitfox.com
33 *
34 * Created on March 18, 2004, 6:52 AM
35 */
36package com.kitfox.svg;
37
38import java.awt.geom.Point2D;
39import java.net.URI;
40import java.net.URL;
41import java.util.ArrayList;
42
43import com.kitfox.svg.xml.StyleAttribute;
44
45/**
46 * @author Mark McKay
47 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
48 */
49public class Filter extends SVGElement
50{
51
52 public static final String TAG_NAME = "filter";
53 public static final int FU_OBJECT_BOUNDING_BOX = 0;
54 public static final int FU_USER_SPACE_ON_USE = 1;
55 protected int filterUnits = FU_OBJECT_BOUNDING_BOX;
56 public static final int PU_OBJECT_BOUNDING_BOX = 0;
57 public static final int PU_USER_SPACE_ON_USE = 1;
58 protected int primitiveUnits = PU_OBJECT_BOUNDING_BOX;
59 float x = 0f;
60 float y = 0f;
61 float width = 1f;
62 float height = 1f;
63 Point2D filterRes = new Point2D.Double();
64 URL href = null;
65 final ArrayList<SVGElement> filterEffects = new ArrayList<>();
66
67 /**
68 * Creates a new instance of FillElement
69 */
70 public Filter()
71 {
72 }
73
74 @Override
75 public String getTagName()
76 {
77 return TAG_NAME;
78 }
79
80 @Override
81 protected void build() throws SVGException
82 {
83 super.build();
84
85 StyleAttribute sty = new StyleAttribute();
86 String strn;
87
88 if (getPres(sty.setName("filterUnits")))
89 {
90 strn = sty.getStringValue().toLowerCase();
91 if (strn.equals("userspaceonuse"))
92 {
93 filterUnits = FU_USER_SPACE_ON_USE;
94 } else
95 {
96 filterUnits = FU_OBJECT_BOUNDING_BOX;
97 }
98 }
99
100 if (getPres(sty.setName("primitiveUnits")))
101 {
102 strn = sty.getStringValue().toLowerCase();
103 if (strn.equals("userspaceonuse"))
104 {
105 primitiveUnits = PU_USER_SPACE_ON_USE;
106 } else
107 {
108 primitiveUnits = PU_OBJECT_BOUNDING_BOX;
109 }
110 }
111
112 if (getPres(sty.setName("x")))
113 {
114 x = sty.getFloatValueWithUnits();
115 }
116
117 if (getPres(sty.setName("y")))
118 {
119 y = sty.getFloatValueWithUnits();
120 }
121
122 if (getPres(sty.setName("width")))
123 {
124 width = sty.getFloatValueWithUnits();
125 }
126
127 if (getPres(sty.setName("height")))
128 {
129 height = sty.getFloatValueWithUnits();
130 }
131
132 try
133 {
134 if (getPres(sty.setName("xlink:href")))
135 {
136 URI src = sty.getURIValue(getXMLBase());
137 href = src.toURL();
138 }
139 } catch (Exception e)
140 {
141 throw new SVGException(e);
142 }
143
144 }
145
146 public float getX()
147 {
148 return x;
149 }
150
151 public float getY()
152 {
153 return y;
154 }
155
156 public float getWidth()
157 {
158 return width;
159 }
160
161 public float getHeight()
162 {
163 return height;
164 }
165
166 @Override
167 public boolean updateTime(double curTime) throws SVGException
168 {
169// if (trackManager.getNumTracks() == 0) return false;
170
171 //Get current values for parameters
172 StyleAttribute sty = new StyleAttribute();
173 boolean stateChange = false;
174
175 if (getPres(sty.setName("x")))
176 {
177 float newVal = sty.getFloatValueWithUnits();
178 if (newVal != x)
179 {
180 x = newVal;
181 stateChange = true;
182 }
183 }
184
185 if (getPres(sty.setName("y")))
186 {
187 float newVal = sty.getFloatValueWithUnits();
188 if (newVal != y)
189 {
190 y = newVal;
191 stateChange = true;
192 }
193 }
194
195 if (getPres(sty.setName("width")))
196 {
197 float newVal = sty.getFloatValueWithUnits();
198 if (newVal != width)
199 {
200 width = newVal;
201 stateChange = true;
202 }
203 }
204
205 if (getPres(sty.setName("height")))
206 {
207 float newVal = sty.getFloatValueWithUnits();
208 if (newVal != height)
209 {
210 height = newVal;
211 stateChange = true;
212 }
213 }
214
215 try
216 {
217 if (getPres(sty.setName("xlink:href")))
218 {
219 URI src = sty.getURIValue(getXMLBase());
220 URL newVal = src.toURL();
221
222 if (!newVal.equals(href))
223 {
224 href = newVal;
225 stateChange = true;
226 }
227 }
228 } catch (Exception e)
229 {
230 throw new SVGException(e);
231 }
232
233 if (getPres(sty.setName("filterUnits")))
234 {
235 int newVal;
236 String strn = sty.getStringValue().toLowerCase();
237 if (strn.equals("userspaceonuse"))
238 {
239 newVal = FU_USER_SPACE_ON_USE;
240 } else
241 {
242 newVal = FU_OBJECT_BOUNDING_BOX;
243 }
244 if (newVal != filterUnits)
245 {
246 filterUnits = newVal;
247 stateChange = true;
248 }
249 }
250
251 if (getPres(sty.setName("primitiveUnits")))
252 {
253 int newVal;
254 String strn = sty.getStringValue().toLowerCase();
255 if (strn.equals("userspaceonuse"))
256 {
257 newVal = PU_USER_SPACE_ON_USE;
258 } else
259 {
260 newVal = PU_OBJECT_BOUNDING_BOX;
261 }
262 if (newVal != filterUnits)
263 {
264 primitiveUnits = newVal;
265 stateChange = true;
266 }
267 }
268
269
270
271 return stateChange;
272 }
273}
Note: See TracBrowser for help on using the repository browser.