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

Last change on this file since 4453 was 4256, checked in by bastiK, 13 years ago

see #6560 - basic svg support, includes kitfox svgsalamander, r 98, patched

File size: 4.5 KB
Line 
1/*
2 * Stop.java
3 *
4 *
5 * The Salamander Project - 2D and 3D graphics libraries in Java
6 * Copyright (C) 2004 Mark McKay
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
23 * projects can be found at http://www.kitfox.com
24 *
25 * Created on January 26, 2004, 1:56 AM
26 */
27
28package com.kitfox.svg;
29
30import java.awt.*;
31import java.awt.geom.*;
32
33import com.kitfox.svg.xml.*;
34
35/**
36 * @author Mark McKay
37 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
38 */
39public class Symbol extends Group
40{
41 AffineTransform viewXform;
42 Rectangle2D viewBox;
43
44 /** Creates a new instance of Stop */
45 public Symbol() {
46 }
47/*
48 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
49 {
50 //Load style string
51 super.loaderStartElement(helper, attrs, parent);
52
53 String viewBoxStrn = attrs.getValue("viewBox");
54 if (viewBoxStrn != null)
55 {
56 float[] dim = XMLParseUtil.parseFloatList(viewBoxStrn);
57 viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]);
58 }
59 }
60*/
61 /*
62 public void loaderEndElement(SVGLoaderHelper helper)
63 {
64 if (viewBox == null)
65 {
66 viewBox = super.getBoundingBox();
67 }
68
69 //Transform pattern onto unit square
70 viewXform = new AffineTransform();
71 viewXform.scale(1.0 / viewBox.getWidth(), 1.0 / viewBox.getHeight());
72 viewXform.translate(-viewBox.getX(), -viewBox.getY());
73 }
74*/
75
76 protected void build() throws SVGException
77 {
78 super.build();
79
80 StyleAttribute sty = new StyleAttribute();
81
82// sty = getPres("unicode");
83// if (sty != null) unicode = sty.getStringValue();
84
85
86 if (getPres(sty.setName("viewBox")))
87 {
88 float[] dim = sty.getFloatList();
89 viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]);
90 }
91
92 if (viewBox == null)
93 {
94// viewBox = super.getBoundingBox();
95 viewBox = new Rectangle(0, 0, 1, 1);
96 }
97
98 //Transform pattern onto unit square
99 viewXform = new AffineTransform();
100 viewXform.scale(1.0 / viewBox.getWidth(), 1.0 / viewBox.getHeight());
101 viewXform.translate(-viewBox.getX(), -viewBox.getY());
102 }
103
104 protected boolean outsideClip(Graphics2D g) throws SVGException
105 {
106 g.getClipBounds(clipBounds);
107 Rectangle2D rect = super.getBoundingBox();
108 if (rect.intersects(clipBounds))
109 {
110 return false;
111 }
112
113 return true;
114
115 }
116
117 public void render(Graphics2D g) throws SVGException
118 {
119 AffineTransform oldXform = g.getTransform();
120 g.transform(viewXform);
121
122 super.render(g);
123
124 g.setTransform(oldXform);
125 }
126
127 public Shape getShape()
128 {
129 Shape shape = super.getShape();
130 return viewXform.createTransformedShape(shape);
131 }
132
133 public Rectangle2D getBoundingBox() throws SVGException
134 {
135 Rectangle2D rect = super.getBoundingBox();
136 return viewXform.createTransformedShape(rect).getBounds2D();
137 }
138
139 /**
140 * Updates all attributes in this diagram associated with a time event.
141 * Ie, all attributes with track information.
142 * @return - true if this node has changed state as a result of the time
143 * update
144 */
145 public boolean updateTime(double curTime) throws SVGException
146 {
147// if (trackManager.getNumTracks() == 0) return false;
148 boolean changeState = super.updateTime(curTime);
149
150 //View box properties do not change
151
152 return changeState;
153 }
154
155}
Note: See TracBrowser for help on using the repository browser.