Changeset 6002 in josm for trunk/src/com/kitfox/svg/FontFace.java
- Timestamp:
- 2013-06-11T01:01:28+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/FontFace.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.awt.geom.*;35 import java.awt.*;36 37 39 38 40 /** … … 46 48 public class FontFace extends SVGElement 47 49 { 50 51 public static final String TAG_NAME = "fontface"; 48 52 String fontFamily; 49 50 /** Em size of coordinate system font is defined in */ 53 /** 54 * Em size of coordinate system font is defined in 55 */ 51 56 int unitsPerEm = 1000; 52 53 57 int ascent = -1; 54 58 int descent = -1; 55 59 int accentHeight = -1; 56 57 60 int underlinePosition = -1; 58 61 int underlineThickness = -1; … … 62 65 int overlineThickness = -1; 63 66 64 /** Creates a new instance of Font */ 67 /** 68 * Creates a new instance of Font 69 */ 65 70 public FontFace() 66 71 { 67 72 } 68 /* 69 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 70 { 71 //Load style string 72 super.loaderStartElement(helper, attrs, parent); 73 74 fontFamily = attrs.getValue("font-family"); 75 76 String unitsPerEm = attrs.getValue("units-per-em"); 77 String ascent = attrs.getValue("ascent"); 78 String descent = attrs.getValue("descent"); 79 String accentHeight = attrs.getValue("accent-height"); 80 81 String underlinePosition = attrs.getValue("underline-position"); 82 String underlineThickness = attrs.getValue("underline-thickness"); 83 String strikethroughPosition = attrs.getValue("strikethrough-position"); 84 String strikethroughThickness = attrs.getValue("strikethrough-thickness"); 85 String overlinePosition = attrs.getValue("overline-position"); 86 String overlineThickness = attrs.getValue("overline-thickness"); 87 88 89 if (unitsPerEm != null) this.unitsPerEm = XMLParseUtil.parseInt(unitsPerEm); 90 if (ascent != null) this.ascent = XMLParseUtil.parseInt(ascent); 91 if (descent != null) this.descent = XMLParseUtil.parseInt(descent); 92 if (accentHeight != null) this.accentHeight = XMLParseUtil.parseInt(accentHeight); 93 94 if (underlinePosition != null) this.underlinePosition = XMLParseUtil.parseInt(underlinePosition); 95 if (underlineThickness != null) this.underlineThickness = XMLParseUtil.parseInt(underlineThickness); 96 if (strikethroughPosition != null) this.strikethroughPosition = XMLParseUtil.parseInt(strikethroughPosition); 97 if (strikethroughThickness != null) this.strikethroughThickness = XMLParseUtil.parseInt(strikethroughThickness); 98 if (overlinePosition != null) this.overlinePosition = XMLParseUtil.parseInt(overlinePosition); 99 if (overlineThickness != null) this.overlineThickness = XMLParseUtil.parseInt(overlineThickness); 100 101 // unitFontXform.setToScale(1.0 / (double)unitsPerEm, 1.0 / (double)unitsPerEm); 102 } 103 */ 104 /* 105 public void loaderEndElement(SVGLoaderHelper helper) 106 { 107 super.loaderEndElement(helper); 108 109 build(); 110 111 // unitFontXform.setToScale(1.0 / (double)unitsPerEm, 1.0 / (double)unitsPerEm); 112 } 113 */ 114 73 74 public String getTagName() 75 { 76 return TAG_NAME; 77 } 78 115 79 protected void build() throws SVGException 116 80 { 117 81 super.build(); 118 82 119 83 StyleAttribute sty = new StyleAttribute(); 120 121 if (getPres(sty.setName("font-family"))) fontFamily = sty.getStringValue(); 122 123 if (getPres(sty.setName("units-per-em"))) unitsPerEm = sty.getIntValue(); 124 if (getPres(sty.setName("ascent"))) ascent = sty.getIntValue(); 125 if (getPres(sty.setName("descent"))) descent = sty.getIntValue(); 126 if (getPres(sty.setName("accent-height"))) accentHeight = sty.getIntValue(); 127 128 if (getPres(sty.setName("underline-position"))) underlinePosition = sty.getIntValue(); 129 if (getPres(sty.setName("underline-thickness"))) underlineThickness = sty.getIntValue(); 130 if (getPres(sty.setName("strikethrough-position"))) strikethroughPosition = sty.getIntValue(); 131 if (getPres(sty.setName("strikethrough-thickenss"))) strikethroughThickness = sty.getIntValue(); 132 if (getPres(sty.setName("overline-position"))) overlinePosition = sty.getIntValue(); 133 if (getPres(sty.setName("overline-thickness"))) overlineThickness = sty.getIntValue(); 134 } 135 136 137 public String getFontFamily() { return fontFamily; } 138 139 public int getUnitsPerEm() { return unitsPerEm; } 84 85 if (getPres(sty.setName("font-family"))) 86 { 87 fontFamily = sty.getStringValue(); 88 } 89 90 if (getPres(sty.setName("units-per-em"))) 91 { 92 unitsPerEm = sty.getIntValue(); 93 } 94 if (getPres(sty.setName("ascent"))) 95 { 96 ascent = sty.getIntValue(); 97 } 98 if (getPres(sty.setName("descent"))) 99 { 100 descent = sty.getIntValue(); 101 } 102 if (getPres(sty.setName("accent-height"))) 103 { 104 accentHeight = sty.getIntValue(); 105 } 106 107 if (getPres(sty.setName("underline-position"))) 108 { 109 underlinePosition = sty.getIntValue(); 110 } 111 if (getPres(sty.setName("underline-thickness"))) 112 { 113 underlineThickness = sty.getIntValue(); 114 } 115 if (getPres(sty.setName("strikethrough-position"))) 116 { 117 strikethroughPosition = sty.getIntValue(); 118 } 119 if (getPres(sty.setName("strikethrough-thickenss"))) 120 { 121 strikethroughThickness = sty.getIntValue(); 122 } 123 if (getPres(sty.setName("overline-position"))) 124 { 125 overlinePosition = sty.getIntValue(); 126 } 127 if (getPres(sty.setName("overline-thickness"))) 128 { 129 overlineThickness = sty.getIntValue(); 130 } 131 } 132 133 public String getFontFamily() 134 { 135 return fontFamily; 136 } 137 138 public int getUnitsPerEm() 139 { 140 return unitsPerEm; 141 } 140 142 141 143 public int getAscent() 142 144 { 143 145 if (ascent == -1) 144 ascent = unitsPerEm - ((Font)parent).getVertOriginY(); 146 { 147 ascent = unitsPerEm - ((Font) parent).getVertOriginY(); 148 } 145 149 return ascent; 146 150 } … … 149 153 { 150 154 if (descent == -1) 151 descent = ((Font)parent).getVertOriginY(); 155 { 156 descent = ((Font) parent).getVertOriginY(); 157 } 152 158 return descent; 153 159 } … … 156 162 { 157 163 if (accentHeight == -1) 164 { 158 165 accentHeight = getAscent(); 166 } 159 167 return accentHeight; 160 168 } … … 163 171 { 164 172 if (underlinePosition == -1) 173 { 165 174 underlinePosition = unitsPerEm * 5 / 6; 175 } 166 176 return underlinePosition; 167 177 } … … 170 180 { 171 181 if (underlineThickness == -1) 182 { 172 183 underlineThickness = unitsPerEm / 20; 184 } 173 185 return underlineThickness; 174 186 } … … 177 189 { 178 190 if (strikethroughPosition == -1) 191 { 179 192 strikethroughPosition = unitsPerEm * 3 / 6; 193 } 180 194 return strikethroughPosition; 181 195 } … … 184 198 { 185 199 if (strikethroughThickness == -1) 200 { 186 201 strikethroughThickness = unitsPerEm / 20; 202 } 187 203 return strikethroughThickness; 188 204 } … … 191 207 { 192 208 if (overlinePosition == -1) 209 { 193 210 overlinePosition = unitsPerEm * 5 / 6; 211 } 194 212 return overlinePosition; 195 213 } … … 198 216 { 199 217 if (overlineThickness == -1) 218 { 200 219 overlineThickness = unitsPerEm / 20; 220 } 201 221 return overlineThickness; 202 222 } 203 223 204 224 /** 205 * Updates all attributes in this diagram associated with a time event. 206 * Ie, all attributes with track information. 225 * Updates all attributes in this diagram associated with a time event. Ie, 226 * all attributes with track information. 227 * 207 228 * @return - true if this node has changed state as a result of the time 208 229 * update
Note:
See TracChangeset
for help on using the changeset viewer.