source: josm/trunk/src/com/kitfox/svg/FontFace.java@ 6002

Last change on this file since 6002 was 6002, checked in by Don-vip, 13 years ago

fix #8742 - update svgsalamander to release 0.1.18+patch (fix bug SVGSALAMANDER-26) -> allow to open more SVG files

File size: 6.3 KB
RevLine 
[4256]1/*
[6002]2 * SVG Salamander
3 * Copyright (c) 2004, Mark McKay
4 * All rights reserved.
[4256]5 *
[6002]6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
[4256]9 *
[6002]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.
[4256]17 *
[6002]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
[4256]33 *
34 * Created on February 20, 2004, 10:00 PM
35 */
36package com.kitfox.svg;
37
38import com.kitfox.svg.xml.StyleAttribute;
39
40/**
41 * Implements an embedded font.
42 *
43 * SVG specification: http://www.w3.org/TR/SVG/fonts.html
44 *
45 * @author Mark McKay
46 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
47 */
48public class FontFace extends SVGElement
49{
[6002]50
51 public static final String TAG_NAME = "fontface";
[4256]52 String fontFamily;
[6002]53 /**
54 * Em size of coordinate system font is defined in
55 */
[4256]56 int unitsPerEm = 1000;
57 int ascent = -1;
58 int descent = -1;
59 int accentHeight = -1;
60 int underlinePosition = -1;
61 int underlineThickness = -1;
62 int strikethroughPosition = -1;
63 int strikethroughThickness = -1;
64 int overlinePosition = -1;
65 int overlineThickness = -1;
66
[6002]67 /**
68 * Creates a new instance of Font
69 */
[4256]70 public FontFace()
71 {
72 }
[6002]73
74 public String getTagName()
[4256]75 {
[6002]76 return TAG_NAME;
77 }
[4256]78
[6002]79 protected void build() throws SVGException
80 {
81 super.build();
[4256]82
[6002]83 StyleAttribute sty = new StyleAttribute();
[4256]84
[6002]85 if (getPres(sty.setName("font-family")))
86 {
87 fontFamily = sty.getStringValue();
88 }
[4256]89
[6002]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 }
[4256]106
[6002]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 }
[4256]132
[6002]133 public String getFontFamily()
134 {
135 return fontFamily;
[4256]136 }
137
[6002]138 public int getUnitsPerEm()
[4256]139 {
[6002]140 return unitsPerEm;
[4256]141 }
142
143 public int getAscent()
144 {
145 if (ascent == -1)
[6002]146 {
147 ascent = unitsPerEm - ((Font) parent).getVertOriginY();
148 }
[4256]149 return ascent;
150 }
151
152 public int getDescent()
153 {
154 if (descent == -1)
[6002]155 {
156 descent = ((Font) parent).getVertOriginY();
157 }
[4256]158 return descent;
159 }
160
161 public int getAccentHeight()
162 {
163 if (accentHeight == -1)
[6002]164 {
[4256]165 accentHeight = getAscent();
[6002]166 }
[4256]167 return accentHeight;
168 }
169
170 public int getUnderlinePosition()
171 {
172 if (underlinePosition == -1)
[6002]173 {
[4256]174 underlinePosition = unitsPerEm * 5 / 6;
[6002]175 }
[4256]176 return underlinePosition;
177 }
178
179 public int getUnderlineThickness()
180 {
181 if (underlineThickness == -1)
[6002]182 {
[4256]183 underlineThickness = unitsPerEm / 20;
[6002]184 }
[4256]185 return underlineThickness;
186 }
187
188 public int getStrikethroughPosition()
189 {
190 if (strikethroughPosition == -1)
[6002]191 {
[4256]192 strikethroughPosition = unitsPerEm * 3 / 6;
[6002]193 }
[4256]194 return strikethroughPosition;
195 }
196
197 public int getStrikethroughThickness()
198 {
199 if (strikethroughThickness == -1)
[6002]200 {
[4256]201 strikethroughThickness = unitsPerEm / 20;
[6002]202 }
[4256]203 return strikethroughThickness;
204 }
205
206 public int getOverlinePosition()
207 {
208 if (overlinePosition == -1)
[6002]209 {
[4256]210 overlinePosition = unitsPerEm * 5 / 6;
[6002]211 }
[4256]212 return overlinePosition;
213 }
214
215 public int getOverlineThickness()
216 {
217 if (overlineThickness == -1)
[6002]218 {
[4256]219 overlineThickness = unitsPerEm / 20;
[6002]220 }
[4256]221 return overlineThickness;
222 }
[6002]223
[4256]224 /**
[6002]225 * Updates all attributes in this diagram associated with a time event. Ie,
226 * all attributes with track information.
227 *
[4256]228 * @return - true if this node has changed state as a result of the time
229 * update
230 */
231 public boolean updateTime(double curTime)
232 {
233 //Fonts can't change
234 return false;
235 }
236}
Note: See TracBrowser for help on using the repository browser.