Changeset 6002 in josm for trunk/src/com/kitfox/svg/SVGRoot.java
- Timestamp:
- 2013-06-11T01:01:28+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/SVGRoot.java
r4256 r6002 1 1 /* 2 * SVGRoot.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 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 24 33 * 25 34 * Created on February 18, 2004, 5:33 PM … … 30 39 import com.kitfox.svg.xml.NumberWithUnits; 31 40 import com.kitfox.svg.xml.StyleAttribute; 32 import java.awt.geom.*; 33 import java.awt.*; 41 import com.kitfox.svg.xml.StyleSheet; 42 import java.awt.Graphics2D; 43 import java.awt.Rectangle; 44 import java.awt.Shape; 45 import java.awt.geom.AffineTransform; 46 import java.awt.geom.Rectangle2D; 34 47 35 48 /** … … 41 54 public class SVGRoot extends Group 42 55 { 56 public static final String TAG_NAME = "svg"; 57 43 58 NumberWithUnits x; 44 59 NumberWithUnits y; … … 46 61 NumberWithUnits height; 47 62 48 49 // final Rectangle2D.Float viewBox = new Rectangle2D.Float();50 63 Rectangle2D.Float viewBox = null; 51 64 … … 70 83 final Rectangle2D.Float clipRect = new Rectangle2D.Float(); 71 84 85 private StyleSheet styleSheet; 86 72 87 /** Creates a new instance of SVGRoot */ 73 88 public SVGRoot() 74 89 { 75 90 } 76 /* 77 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 78 { 79 //Load style string 80 super.loaderStartElement(helper, attrs, parent); 81 82 x = XMLParseUtil.parseNumberWithUnits(attrs.getValue("x")); 83 y = XMLParseUtil.parseNumberWithUnits(attrs.getValue("y")); 84 width = XMLParseUtil.parseNumberWithUnits(attrs.getValue("width")); 85 height = XMLParseUtil.parseNumberWithUnits(attrs.getValue("height")); 86 87 String viewBox = attrs.getValue("viewBox"); 88 float[] coords = XMLParseUtil.parseFloatList(viewBox); 89 90 if (coords == null) 91 { 92 //this.viewBox.setRect(0, 0, width.getValue(), height.getValue()); 93 this.viewBox = null; 94 } 95 else 96 { 97 this.viewBox = new Rectangle2D.Float(coords[0], coords[1], coords[2], coords[3]); 98 } 99 100 String par = attrs.getValue("preserveAspectRatio"); 101 if (par != null) 102 { 103 String[] parList = XMLParseUtil.parseStringList(par); 104 105 if (parList[0].equals("none")) { parAlignX = PA_X_NONE; parAlignY = PA_Y_NONE; } 106 else if (parList[0].equals("xMinYMin")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MIN; } 107 else if (parList[0].equals("xMidYMin")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MIN; } 108 else if (parList[0].equals("xMaxYMin")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MIN; } 109 else if (parList[0].equals("xMinYMid")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MID; } 110 else if (parList[0].equals("xMidYMid")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MID; } 111 else if (parList[0].equals("xMaxYMid")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MID; } 112 else if (parList[0].equals("xMinYMax")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MAX; } 113 else if (parList[0].equals("xMidYMax")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MAX; } 114 else if (parList[0].equals("xMaxYMax")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MAX; } 115 116 if (parList[1].equals("meet")) parSpecifier = PS_MEET; 117 else if (parList[1].equals("slice")) parSpecifier = PS_SLICE; 118 } 119 120 build(); 121 } 122 */ 91 92 public String getTagName() 93 { 94 return TAG_NAME; 95 } 123 96 124 97 public void build() throws SVGException … … 128 101 StyleAttribute sty = new StyleAttribute(); 129 102 130 if (getPres(sty.setName("x"))) x = sty.getNumberWithUnits(); 131 132 if (getPres(sty.setName("y"))) y = sty.getNumberWithUnits(); 133 134 if (getPres(sty.setName("width"))) width = sty.getNumberWithUnits(); 135 136 if (getPres(sty.setName("height"))) height = sty.getNumberWithUnits(); 103 if (getPres(sty.setName("x"))) 104 { 105 x = sty.getNumberWithUnits(); 106 } 107 108 if (getPres(sty.setName("y"))) 109 { 110 y = sty.getNumberWithUnits(); 111 } 112 113 if (getPres(sty.setName("width"))) 114 { 115 width = sty.getNumberWithUnits(); 116 } 117 118 if (getPres(sty.setName("height"))) 119 { 120 height = sty.getNumberWithUnits(); 121 } 137 122 138 123 if (getPres(sty.setName("viewBox"))) … … 157 142 else if (contains(preserve, "xMaxYMax")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MAX; } 158 143 159 if (contains(preserve, "meet")) parSpecifier = PS_MEET; 160 else if (contains(preserve, "slice")) parSpecifier = PS_SLICE; 161 162 /* 163 String[] parList = sty.getStringList(); 164 165 if (parList[0].equals("none")) { parAlignX = PA_X_NONE; parAlignY = PA_Y_NONE; } 166 else if (parList[0].equals("xMinYMin")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MIN; } 167 else if (parList[0].equals("xMidYMin")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MIN; } 168 else if (parList[0].equals("xMaxYMin")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MIN; } 169 else if (parList[0].equals("xMinYMid")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MID; } 170 else if (parList[0].equals("xMidYMid")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MID; } 171 else if (parList[0].equals("xMaxYMid")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MID; } 172 else if (parList[0].equals("xMinYMax")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MAX; } 173 else if (parList[0].equals("xMidYMax")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MAX; } 174 else if (parList[0].equals("xMaxYMax")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MAX; } 175 176 if (parList[1].equals("meet")) parSpecifier = PS_MEET; 177 else if (parList[1].equals("slice")) parSpecifier = PS_SLICE; 178 */ 144 if (contains(preserve, "meet")) 145 { 146 parSpecifier = PS_MEET; 147 } 148 else if (contains(preserve, "slice")) 149 { 150 parSpecifier = PS_SLICE; 151 } 179 152 } 180 153 … … 185 158 { 186 159 return (text.indexOf(find) != -1); 160 } 161 162 public SVGRoot getRoot() 163 { 164 return this; 187 165 } 188 166 … … 195 173 { 196 174 defaultBounds = getBoundingBox(); 197 } catch (SVGException ex) 175 } 176 catch (SVGException ex) 198 177 { 199 178 defaultBounds= new Rectangle2D.Float(); … … 213 192 ww = StyleAttribute.convertUnitsToPixels(width.getUnits(), width.getValue()); 214 193 } 215 // setAttribute("x", AnimationElement.AT_XML, "" + xx);216 // setAttribute("width", AnimationElement.AT_XML, "" + ww);217 194 } 218 195 else if (viewBox != null) … … 273 250 viewXform.translate(-viewBox.x, -viewBox.y); 274 251 } 275 276 277 //For now, treat all preserveAspectRatio as 'none'278 // viewXform.setToTranslation(viewBox.x, viewBox.y);279 // viewXform.scale(clipRect.width / viewBox.width, clipRect.height / viewBox.height);280 // viewXform.translate(-clipRect.x, -clipRect.y);281 252 } 282 253 … … 393 364 } 394 365 366 /** 367 * @return the styleSheet 368 */ 369 public StyleSheet getStyleSheet() 370 { 371 if (styleSheet == null) 372 { 373 for (int i = 0; i < getNumChildren(); ++i) 374 { 375 SVGElement ele = getChild(i); 376 if (ele instanceof Style) 377 { 378 return ((Style)ele).getStyleSheet(); 379 } 380 } 381 } 382 383 return styleSheet; 384 } 385 386 /** 387 * @param styleSheet the styleSheet to set 388 */ 389 public void setStyleSheet(StyleSheet styleSheet) 390 { 391 this.styleSheet = styleSheet; 392 } 393 395 394 }
Note:
See TracChangeset
for help on using the changeset viewer.