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

Last change on this file since 6535 was 6002, checked in by Don-vip, 13 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
RevLine 
[4256]1/*
[6002]2 * SVG Salamander
3 * Copyright (c) 2004, Mark McKay
4 * All rights reserved.
[4256]5 *
[6002]6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
[4256]9 *
[6002]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.
[4256]17 *
[6002]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
[4256]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 */
[6002]47public class ClipPath extends SVGElement
[4256]48{
49
[6002]50 public static final String TAG_NAME = "clippath";
[4256]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
[6002]55 /**
56 * Creates a new instance of Stop
57 */
58 public ClipPath()
59 {
[4256]60 }
[6002]61
62 public String getTagName()
[4256]63 {
[6002]64 return TAG_NAME;
65 }
[4256]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 {
[6002]73 super.loaderAddChild(helper, child);
[4256]74 }
75
76 protected void build() throws SVGException
77 {
78 super.build();
[6002]79
[4256]80 StyleAttribute sty = new StyleAttribute();
[6002]81
[4256]82 clipPathUnits = (getPres(sty.setName("clipPathUnits"))
[6002]83 && sty.getStringValue().equals("objectBoundingBox"))
84 ? CP_OBJECT_BOUNDING_BOX
[4256]85 : CP_USER_SPACE_ON_USE;
86 }
[6002]87
[4256]88 public int getClipPathUnits()
89 {
90 return clipPathUnits;
91 }
92
93 public Shape getClipPathShape()
94 {
[6002]95 if (children.isEmpty())
96 {
97 return null;
98 }
99 if (children.size() == 1)
100 {
101 return ((ShapeElement) children.get(0)).getShape();
102 }
[4256]103
104 Area clipArea = null;
105 for (Iterator it = children.iterator(); it.hasNext();)
106 {
[6002]107 ShapeElement se = (ShapeElement) it.next();
[4256]108
109 if (clipArea == null)
110 {
111 Shape shape = se.getShape();
[6002]112 if (shape != null)
113 {
114 clipArea = new Area(se.getShape());
115 }
[4256]116 continue;
117 }
118
119 Shape shape = se.getShape();
[6002]120 if (shape != null)
121 {
122 clipArea.intersect(new Area(shape));
123 }
[4256]124 }
125
126 return clipArea;
127 }
128
129 /**
[6002]130 * Updates all attributes in this diagram associated with a time event. Ie,
131 * all attributes with track information.
132 *
[4256]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
[6002]142
[4256]143 if (getPres(sty.setName("clipPathUnits")))
144 {
145 String newUnitsStrn = sty.getStringValue();
146 int newUnits = newUnitsStrn.equals("objectBoundingBox")
[6002]147 ? CP_OBJECT_BOUNDING_BOX
[4256]148 : CP_USER_SPACE_ON_USE;
[6002]149
[4256]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.