Changeset 6002 in josm for trunk/src/com/kitfox/svg/Font.java
- Timestamp:
- 2013-06-11T01:01:28+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/Font.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 38 import com.kitfox.svg.xml.StyleAttribute; 31 import com.kitfox.svg.xml.*; 32 import org.xml.sax.*; 33 34 import java.util.*; 39 import java.util.HashMap; 35 40 36 41 /** … … 44 49 public class Font extends SVGElement 45 50 { 51 52 public static final String TAG_NAME = "font"; 46 53 int horizOriginX = 0; 47 54 int horizOriginY = 0; … … 50 57 int vertOriginY = -1; //Defaults to font's ascent 51 58 int vertAdvY = -1; //Defaults to one 'em'. See font-face 52 53 59 FontFace fontFace = null; 54 60 MissingGlyph missingGlyph = null; 55 61 final HashMap glyphs = new HashMap(); 56 62 57 /** Creates a new instance of Font */ 63 /** 64 * Creates a new instance of Font 65 */ 58 66 public Font() 59 67 { 60 68 } 61 /* 62 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 63 { 64 //Load style string 65 super.loaderStartElement(helper, attrs, parent); 66 67 String horizOriginX = attrs.getValue("horiz-origin-x"); 68 String horizOriginY = attrs.getValue("horiz-origin-y"); 69 String horizAdvX = attrs.getValue("horiz-adv-x"); 70 String vertOriginX = attrs.getValue("vert-origin-x"); 71 String vertOriginY = attrs.getValue("vert-origin-y"); 72 String vertAdvY = attrs.getValue("vert-adv-y"); 73 74 if (horizOriginX != null) this.horizOriginX = XMLParseUtil.parseInt(horizOriginX); 75 if (horizOriginY != null) this.horizOriginY = XMLParseUtil.parseInt(horizOriginY); 76 if (horizAdvX != null) this.horizAdvX = XMLParseUtil.parseInt(horizAdvX); 77 if (vertOriginX != null) this.vertOriginX = XMLParseUtil.parseInt(vertOriginX); 78 if (vertOriginY != null) this.vertOriginY = XMLParseUtil.parseInt(vertOriginY); 79 if (vertAdvY != null) this.vertAdvY = XMLParseUtil.parseInt(vertAdvY); 80 81 } 82 */ 69 70 public String getTagName() 71 { 72 return TAG_NAME; 73 } 74 83 75 /** 84 76 * Called after the start element but before the end element to indicate … … 87 79 public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException 88 80 { 89 81 super.loaderAddChild(helper, child); 90 82 91 83 if (child instanceof Glyph) 92 84 { 93 glyphs.put(((Glyph)child).getUnicode(), child); 94 } 95 else if (child instanceof MissingGlyph) 96 { 97 missingGlyph = (MissingGlyph)child; 98 } 99 else if (child instanceof FontFace) 100 { 101 fontFace = (FontFace)child; 85 glyphs.put(((Glyph) child).getUnicode(), child); 86 } else if (child instanceof MissingGlyph) 87 { 88 missingGlyph = (MissingGlyph) child; 89 } else if (child instanceof FontFace) 90 { 91 fontFace = (FontFace) child; 102 92 } 103 93 } … … 108 98 109 99 //build(); 110 100 111 101 helper.universe.registerFont(this); 112 102 } 113 103 114 104 protected void build() throws SVGException 115 105 { 116 106 super.build(); 117 107 118 108 StyleAttribute sty = new StyleAttribute(); 119 120 if (getPres(sty.setName("horiz-origin-x"))) horizOriginX = sty.getIntValue(); 121 122 if (getPres(sty.setName("horiz-origin-y"))) horizOriginY = sty.getIntValue(); 123 124 if (getPres(sty.setName("horiz-adv-x"))) horizAdvX = sty.getIntValue(); 125 126 if (getPres(sty.setName("vert-origin-x"))) vertOriginX = sty.getIntValue(); 127 128 if (getPres(sty.setName("vert-origin-y"))) vertOriginY = sty.getIntValue(); 129 130 if (getPres(sty.setName("vert-adv-y"))) vertAdvY = sty.getIntValue(); 131 } 132 133 public FontFace getFontFace() { return fontFace; } 109 110 if (getPres(sty.setName("horiz-origin-x"))) 111 { 112 horizOriginX = sty.getIntValue(); 113 } 114 115 if (getPres(sty.setName("horiz-origin-y"))) 116 { 117 horizOriginY = sty.getIntValue(); 118 } 119 120 if (getPres(sty.setName("horiz-adv-x"))) 121 { 122 horizAdvX = sty.getIntValue(); 123 } 124 125 if (getPres(sty.setName("vert-origin-x"))) 126 { 127 vertOriginX = sty.getIntValue(); 128 } 129 130 if (getPres(sty.setName("vert-origin-y"))) 131 { 132 vertOriginY = sty.getIntValue(); 133 } 134 135 if (getPres(sty.setName("vert-adv-y"))) 136 { 137 vertAdvY = sty.getIntValue(); 138 } 139 } 140 141 public FontFace getFontFace() 142 { 143 return fontFace; 144 } 134 145 135 146 public MissingGlyph getGlyph(String unicode) 136 147 { 137 Glyph retVal = (Glyph)glyphs.get(unicode); 138 if (retVal == null) return missingGlyph; 148 Glyph retVal = (Glyph) glyphs.get(unicode); 149 if (retVal == null) 150 { 151 return missingGlyph; 152 } 139 153 return retVal; 140 154 } 141 155 142 public int getHorizOriginX() { return horizOriginX; } 143 public int getHorizOriginY() { return horizOriginY; } 144 public int getHorizAdvX() { return horizAdvX; } 156 public int getHorizOriginX() 157 { 158 return horizOriginX; 159 } 160 161 public int getHorizOriginY() 162 { 163 return horizOriginY; 164 } 165 166 public int getHorizAdvX() 167 { 168 return horizAdvX; 169 } 145 170 146 171 public int getVertOriginX() 147 172 { 148 if (vertOriginX != -1) return vertOriginX; 173 if (vertOriginX != -1) 174 { 175 return vertOriginX; 176 } 149 177 vertOriginX = getHorizAdvX() / 2; 150 178 return vertOriginX; … … 153 181 public int getVertOriginY() 154 182 { 155 if (vertOriginY != -1) return vertOriginY; 183 if (vertOriginY != -1) 184 { 185 return vertOriginY; 186 } 156 187 vertOriginY = fontFace.getAscent(); 157 188 return vertOriginY; … … 160 191 public int getVertAdvY() 161 192 { 162 if (vertAdvY != -1) return vertAdvY; 193 if (vertAdvY != -1) 194 { 195 return vertAdvY; 196 } 163 197 vertAdvY = fontFace.getUnitsPerEm(); 164 198 return vertAdvY; 165 199 } 166 200 167 201 /** 168 * Updates all attributes in this diagram associated with a time event. 169 * Ie, all attributes with track information. 202 * Updates all attributes in this diagram associated with a time event. Ie, 203 * all attributes with track information. 204 * 170 205 * @return - true if this node has changed state as a result of the time 171 206 * update … … 176 211 return false; 177 212 /* 178 if (trackManager.getNumTracks() == 0) return false;179 180 //Get current values for parameters181 StyleAttribute sty = new StyleAttribute();182 boolean stateChange = false;183 184 if (getPres(sty.setName("horiz-origin-x")))185 {186 187 188 189 190 191 192 }193 194 if (getPres(sty.setName("horiz-origin-y")))195 {196 197 198 199 200 201 202 }203 204 if (getPres(sty.setName("horiz-adv-x")))205 {206 207 208 209 210 211 212 }213 214 if (getPres(sty.setName("vert-origin-x")))215 {216 217 218 219 220 221 222 }223 224 if (getPres(sty.setName("vert-origin-y")))225 {226 227 228 229 230 231 232 }233 234 if (getPres(sty.setName("vert-adv-y")))235 {236 237 238 239 240 241 242 }243 244 return shapeChange;245 */213 if (trackManager.getNumTracks() == 0) return false; 214 215 //Get current values for parameters 216 StyleAttribute sty = new StyleAttribute(); 217 boolean stateChange = false; 218 219 if (getPres(sty.setName("horiz-origin-x"))) 220 { 221 int newVal = sty.getIntValue(); 222 if (newVal != horizOriginX) 223 { 224 horizOriginX = newVal; 225 stateChange = true; 226 } 227 } 228 229 if (getPres(sty.setName("horiz-origin-y"))) 230 { 231 int newVal = sty.getIntValue(); 232 if (newVal != horizOriginY) 233 { 234 horizOriginY = newVal; 235 stateChange = true; 236 } 237 } 238 239 if (getPres(sty.setName("horiz-adv-x"))) 240 { 241 int newVal = sty.getIntValue(); 242 if (newVal != horizAdvX) 243 { 244 horizAdvX = newVal; 245 stateChange = true; 246 } 247 } 248 249 if (getPres(sty.setName("vert-origin-x"))) 250 { 251 int newVal = sty.getIntValue(); 252 if (newVal != vertOriginX) 253 { 254 vertOriginX = newVal; 255 stateChange = true; 256 } 257 } 258 259 if (getPres(sty.setName("vert-origin-y"))) 260 { 261 int newVal = sty.getIntValue(); 262 if (newVal != vertOriginY) 263 { 264 vertOriginY = newVal; 265 stateChange = true; 266 } 267 } 268 269 if (getPres(sty.setName("vert-adv-y"))) 270 { 271 int newVal = sty.getIntValue(); 272 if (newVal != vertAdvY) 273 { 274 vertAdvY = newVal; 275 stateChange = true; 276 } 277 } 278 279 return shapeChange; 280 */ 246 281 } 247 282 }
Note:
See TracChangeset
for help on using the changeset viewer.