source: josm/trunk/src/com/kitfox/svg/Symbol.java@ 17333

Last change on this file since 17333 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: 4.4 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.Graphics2D;
40import java.awt.Rectangle;
41import java.awt.Shape;
42import java.awt.geom.AffineTransform;
43import java.awt.geom.Rectangle2D;
44
45/**
46 * @author Mark McKay
47 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
48 */
49public class Symbol extends Group
50{
51
52 public static final String TAG_NAME = "symbol";
53 AffineTransform viewXform;
54 Rectangle2D viewBox;
55
56 /**
57 * Creates a new instance of Stop
58 */
59 public Symbol()
60 {
61 }
62
63 @Override
64 public String getTagName()
65 {
66 return TAG_NAME;
67 }
68
69 @Override
70 protected void build() throws SVGException
71 {
72 super.build();
73
74 StyleAttribute sty = new StyleAttribute();
75
76// sty = getPres("unicode");
77// if (sty != null) unicode = sty.getStringValue();
78
79
80 if (getPres(sty.setName("viewBox")))
81 {
82 float[] dim = sty.getFloatList();
83 viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]);
84 }
85
86 if (viewBox == null)
87 {
88// viewBox = super.getBoundingBox();
89 viewBox = new Rectangle(0, 0, 1, 1);
90 }
91
92 //Transform pattern onto unit square
93 viewXform = new AffineTransform();
94 viewXform.scale(1.0 / viewBox.getWidth(), 1.0 / viewBox.getHeight());
95 viewXform.translate(-viewBox.getX(), -viewBox.getY());
96 }
97
98 @Override
99 protected boolean outsideClip(Graphics2D g) throws SVGException
100 {
101 Shape clip = g.getClip();
102// g.getClipBounds(clipBounds);
103 Rectangle2D rect = super.getBoundingBox();
104 if (clip == null || clip.intersects(rect))
105 {
106 return false;
107 }
108
109 return true;
110
111 }
112
113 @Override
114 public void render(Graphics2D g) throws SVGException
115 {
116 AffineTransform oldXform = g.getTransform();
117 g.transform(viewXform);
118
119 super.render(g);
120
121 g.setTransform(oldXform);
122 }
123
124 @Override
125 public Shape getShape()
126 {
127 Shape shape = super.getShape();
128 return viewXform.createTransformedShape(shape);
129 }
130
131 @Override
132 public Rectangle2D getBoundingBox() throws SVGException
133 {
134 Rectangle2D rect = super.getBoundingBox();
135 return viewXform.createTransformedShape(rect).getBounds2D();
136 }
137
138 /**
139 * Updates all attributes in this diagram associated with a time event. Ie,
140 * all attributes with track information.
141 *
142 * @return - true if this node has changed state as a result of the time
143 * update
144 */
145 @Override
146 public boolean updateTime(double curTime) throws SVGException
147 {
148// if (trackManager.getNumTracks() == 0) return false;
149 boolean changeState = super.updateTime(curTime);
150
151 //View box properties do not change
152
153 return changeState;
154 }
155}
Note: See TracBrowser for help on using the repository browser.