Changeset 6002 in josm for trunk/src/com/kitfox/svg/MissingGlyph.java
- Timestamp:
- 2013-06-11T01:01:28+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/MissingGlyph.java
r4256 r6002 1 1 /* 2 * Font.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 20, 2004, 10:00 PM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 import com.kitfox.svg.xml.*; 31 32 import java.awt.*; 33 import java.awt.geom.*; 34 import java.util.*; 35 36 import com.kitfox.svg.pathcmd.*; 37 //import org.apache.batik.ext.awt.geom.ExtendedGeneralPath; 38 import com.kitfox.svg.pathcmd.BuildHistory; 39 import com.kitfox.svg.pathcmd.PathCommand; 40 import com.kitfox.svg.xml.StyleAttribute; 41 import java.awt.Graphics2D; 42 import java.awt.Shape; 43 import java.awt.geom.AffineTransform; 44 import java.awt.geom.GeneralPath; 45 import java.awt.geom.Rectangle2D; 46 import java.util.Iterator; 38 47 39 48 /** … … 47 56 public class MissingGlyph extends ShapeElement 48 57 { 58 public static final String TAG_NAME = "missingglyph"; 59 49 60 //We may define a path 50 // ExtendedGeneralPath path = null;51 61 Shape path = null; 52 53 62 //Alternately, we may have child graphical elements 54 55 63 int horizAdvX = -1; //Inherits font's value if not set 56 64 int vertOriginX = -1; //Inherits font's value if not set … … 58 66 int vertAdvY = -1; //Inherits font's value if not set 59 67 60 /** Creates a new instance of Font */ 68 /** 69 * Creates a new instance of Font 70 */ 61 71 public MissingGlyph() 62 72 { 63 73 } 64 /* 65 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 66 { 67 //Load style string 68 super.loaderStartElement(helper, attrs, parent); 74 75 public String getTagName() 76 { 77 return TAG_NAME; 78 } 79 80 /** 81 * Called after the start element but before the end element to indicate 82 * each child tag that has been processed 83 */ 84 public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException 85 { 86 super.loaderAddChild(helper, child); 87 } 88 89 protected void build() throws SVGException 90 { 91 super.build(); 92 93 StyleAttribute sty = new StyleAttribute(); 94 95 String commandList = ""; 96 if (getPres(sty.setName("d"))) 97 { 98 commandList = sty.getStringValue(); 99 } 100 69 101 70 102 //If glyph path was specified, calculate it 71 String commandList = attrs.getValue("d");72 103 if (commandList != null) 73 104 { 74 StyleAttribute atyleAttrib = getStyle("fill-rule"); 75 String fillRule = (atyleAttrib == null) ? "nonzero" : atyleAttrib.getStringValue(); 105 String fillRule = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero"; 76 106 77 107 PathCommand[] commands = parsePathList(commandList); 78 108 79 // ExtendedGeneralPath buildPath = new ExtendedGeneralPath(80 109 GeneralPath buildPath = new GeneralPath( 81 110 fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO, … … 98 127 99 128 //Read glyph spacing info 100 String horizAdvX = attrs.getValue("horiz-adv-x"); 101 String vertOriginX = attrs.getValue("vert-origin-x"); 102 String vertOriginY = attrs.getValue("vert-origin-y"); 103 String vertAdvY = attrs.getValue("vert-adv-y"); 104 105 if (horizAdvX != null) this.horizAdvX = XMLParseUtil.parseInt(horizAdvX); 106 if (vertOriginX != null) this.vertOriginX = XMLParseUtil.parseInt(vertOriginX); 107 if (vertOriginY != null) this.vertOriginY = XMLParseUtil.parseInt(vertOriginY); 108 if (vertAdvY != null) this.vertAdvY = XMLParseUtil.parseInt(vertAdvY); 109 110 } 111 */ 112 /** 113 * Called after the start element but before the end element to indicate 114 * each child tag that has been processed 115 */ 116 public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException 117 { 118 super.loaderAddChild(helper, child); 119 } 120 121 122 protected void build() throws SVGException 123 { 124 super.build(); 125 126 StyleAttribute sty = new StyleAttribute(); 127 128 String commandList = ""; 129 if (getPres(sty.setName("d"))) commandList = sty.getStringValue(); 130 131 132 //If glyph path was specified, calculate it 133 if (commandList != null) 134 { 135 // StyleAttribute atyleAttrib = getStyle("fill-rule"); 136 String fillRule = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero"; 137 138 PathCommand[] commands = parsePathList(commandList); 139 140 // ExtendedGeneralPath buildPath = new ExtendedGeneralPath( 141 GeneralPath buildPath = new GeneralPath( 142 fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO, 143 commands.length); 144 145 BuildHistory hist = new BuildHistory(); 146 147 for (int i = 0; i < commands.length; i++) 148 { 149 PathCommand cmd = commands[i]; 150 cmd.appendPath(buildPath, hist); 151 } 152 153 //Reflect glyph path to put it in user coordinate system 154 AffineTransform at = new AffineTransform(); 155 at.scale(1, -1); 156 path = at.createTransformedShape(buildPath); 157 } 158 159 160 //Read glyph spacing info 161 if (getPres(sty.setName("horiz-adv-x"))) horizAdvX = sty.getIntValue(); 162 163 if (getPres(sty.setName("vert-origin-x"))) vertOriginX = sty.getIntValue(); 164 165 if (getPres(sty.setName("vert-origin-y"))) vertOriginY = sty.getIntValue(); 166 167 if (getPres(sty.setName("vert-adv-y"))) vertAdvY = sty.getIntValue(); 129 if (getPres(sty.setName("horiz-adv-x"))) 130 { 131 horizAdvX = sty.getIntValue(); 132 } 133 134 if (getPres(sty.setName("vert-origin-x"))) 135 { 136 vertOriginX = sty.getIntValue(); 137 } 138 139 if (getPres(sty.setName("vert-origin-y"))) 140 { 141 vertOriginY = sty.getIntValue(); 142 } 143 144 if (getPres(sty.setName("vert-adv-y"))) 145 { 146 vertAdvY = sty.getIntValue(); 147 } 168 148 } 169 149 … … 177 157 //Do not push or pop stack 178 158 179 if (path != null) renderShape(g, path); 180 159 if (path != null) 160 { 161 renderShape(g, path); 162 } 163 181 164 Iterator it = children.iterator(); 182 165 while (it.hasNext()) 183 166 { 184 SVGElement ele = (SVGElement) it.next();167 SVGElement ele = (SVGElement) it.next(); 185 168 if (ele instanceof RenderableElement) 186 169 { 187 ((RenderableElement) ele).render(g);170 ((RenderableElement) ele).render(g); 188 171 } 189 172 } … … 195 178 { 196 179 if (horizAdvX == -1) 197 horizAdvX = ((Font)parent).getHorizAdvX(); 180 { 181 horizAdvX = ((Font) parent).getHorizAdvX(); 182 } 198 183 return horizAdvX; 199 184 } … … 202 187 { 203 188 if (vertOriginX == -1) 189 { 204 190 vertOriginX = getHorizAdvX() / 2; 191 } 205 192 return vertOriginX; 206 193 } … … 209 196 { 210 197 if (vertOriginY == -1) 211 vertOriginY = ((Font)parent).getFontFace().getAscent(); 198 { 199 vertOriginY = ((Font) parent).getFontFace().getAscent(); 200 } 212 201 return vertOriginY; 213 202 } … … 216 205 { 217 206 if (vertAdvY == -1) 218 vertAdvY = ((Font)parent).getFontFace().getUnitsPerEm(); 207 { 208 vertAdvY = ((Font) parent).getFontFace().getUnitsPerEm(); 209 } 219 210 return vertAdvY; 220 211 … … 223 214 public Shape getShape() 224 215 { 225 if (path != null) return shapeToParent(path); 216 if (path != null) 217 { 218 return shapeToParent(path); 219 } 226 220 return null; 227 221 } … … 229 223 public Rectangle2D getBoundingBox() throws SVGException 230 224 { 231 if (path != null) return boundsToParent(includeStrokeInBounds(path.getBounds2D())); 225 if (path != null) 226 { 227 return boundsToParent(includeStrokeInBounds(path.getBounds2D())); 228 } 232 229 return null; 233 230 } 234 231 235 232 /** 236 * Updates all attributes in this diagram associated with a time event. 237 * Ie, all attributes with track information. 233 * Updates all attributes in this diagram associated with a time event. Ie, 234 * all attributes with track information. 235 * 238 236 * @return - true if this node has changed state as a result of the time 239 237 * update
Note:
See TracChangeset
for help on using the changeset viewer.