source: josm/trunk/src/com/kitfox/svg/ClipPath.java@ 6388

Last change on this file since 6388 was 6002, checked in by Don-vip, 11 years ago

fix #8742 - update svgsalamander to release 0.1.18+patch (fix bug SVGSALAMANDER-26) -> allow to open more SVG files

File size: 4.8 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 January 26, 2004, 1:56 AM
35 */
36package com.kitfox.svg;
37
38import com.kitfox.svg.xml.StyleAttribute;
39import java.awt.Shape;
40import java.awt.geom.Area;
41import java.util.Iterator;
42
43/**
44 * @author Mark McKay
45 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
46 */
47public class ClipPath extends SVGElement
48{
49
50 public static final String TAG_NAME = "clippath";
51 public static final int CP_USER_SPACE_ON_USE = 0;
52 public static final int CP_OBJECT_BOUNDING_BOX = 1;
53 int clipPathUnits = CP_USER_SPACE_ON_USE;
54
55 /**
56 * Creates a new instance of Stop
57 */
58 public ClipPath()
59 {
60 }
61
62 public String getTagName()
63 {
64 return TAG_NAME;
65 }
66
67 /**
68 * Called after the start element but before the end element to indicate
69 * each child tag that has been processed
70 */
71 public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
72 {
73 super.loaderAddChild(helper, child);
74 }
75
76 protected void build() throws SVGException
77 {
78 super.build();
79
80 StyleAttribute sty = new StyleAttribute();
81
82 clipPathUnits = (getPres(sty.setName("clipPathUnits"))
83 && sty.getStringValue().equals("objectBoundingBox"))
84 ? CP_OBJECT_BOUNDING_BOX
85 : CP_USER_SPACE_ON_USE;
86 }
87
88 public int getClipPathUnits()
89 {
90 return clipPathUnits;
91 }
92
93 public Shape getClipPathShape()
94 {
95 if (children.isEmpty())
96 {
97 return null;
98 }
99 if (children.size() == 1)
100 {
101 return ((ShapeElement) children.get(0)).getShape();
102 }
103
104 Area clipArea = null;
105 for (Iterator it = children.iterator(); it.hasNext();)
106 {
107 ShapeElement se = (ShapeElement) it.next();
108
109 if (clipArea == null)
110 {
111 Shape shape = se.getShape();
112 if (shape != null)
113 {
114 clipArea = new Area(se.getShape());
115 }
116 continue;
117 }
118
119 Shape shape = se.getShape();
120 if (shape != null)
121 {
122 clipArea.intersect(new Area(shape));
123 }
124 }
125
126 return clipArea;
127 }
128
129 /**
130 * Updates all attributes in this diagram associated with a time event. Ie,
131 * all attributes with track information.
132 *
133 * @return - true if this node has changed state as a result of the time
134 * update
135 */
136 public boolean updateTime(double curTime) throws SVGException
137 {
138 //Get current values for parameters
139 StyleAttribute sty = new StyleAttribute();
140 boolean shapeChange = false;
141
142
143 if (getPres(sty.setName("clipPathUnits")))
144 {
145 String newUnitsStrn = sty.getStringValue();
146 int newUnits = newUnitsStrn.equals("objectBoundingBox")
147 ? CP_OBJECT_BOUNDING_BOX
148 : CP_USER_SPACE_ON_USE;
149
150 if (newUnits != clipPathUnits)
151 {
152 clipPathUnits = newUnits;
153 shapeChange = true;
154 }
155 }
156
157 if (shapeChange)
158 {
159 build();
160 }
161
162 return shapeChange;
163 }
164}
Note: See TracBrowser for help on using the repository browser.