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

Last change on this file since 12713 was 11525, checked in by Don-vip, 7 years ago

see #14319 - update to latest version of svgSalamander (2017-01-07, patched)

  • Property svn:eol-style set to native
File size: 8.0 KB
Line 
1/*
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
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{
50
51 public static final String TAG_NAME = "fontface";
52 String fontFamily;
53 /**
54 * Em size of coordinate system font is defined in
55 */
56 private int unitsPerEm = 1000;
57 private int ascent = -1;
58 private int descent = -1;
59 private int accentHeight = -1;
60 private int underlinePosition = -1;
61 private int underlineThickness = -1;
62 private int strikethroughPosition = -1;
63 private int strikethroughThickness = -1;
64 private int overlinePosition = -1;
65 private int overlineThickness = -1;
66
67 /**
68 * Creates a new instance of Font
69 */
70 public FontFace()
71 {
72 }
73
74 @Override
75 public String getTagName()
76 {
77 return TAG_NAME;
78 }
79
80 @Override
81 protected void build() throws SVGException
82 {
83 super.build();
84
85 StyleAttribute sty = new StyleAttribute();
86
87 if (getPres(sty.setName("font-family")))
88 {
89 fontFamily = sty.getStringValue();
90 }
91
92 if (getPres(sty.setName("units-per-em")))
93 {
94 unitsPerEm = sty.getIntValue();
95 }
96 if (getPres(sty.setName("ascent")))
97 {
98 ascent = sty.getIntValue();
99 }
100 if (getPres(sty.setName("descent")))
101 {
102 descent = sty.getIntValue();
103 }
104 if (getPres(sty.setName("accent-height")))
105 {
106 accentHeight = sty.getIntValue();
107 }
108
109 if (getPres(sty.setName("underline-position")))
110 {
111 underlinePosition = sty.getIntValue();
112 }
113 if (getPres(sty.setName("underline-thickness")))
114 {
115 underlineThickness = sty.getIntValue();
116 }
117 if (getPres(sty.setName("strikethrough-position")))
118 {
119 strikethroughPosition = sty.getIntValue();
120 }
121 if (getPres(sty.setName("strikethrough-thickenss")))
122 {
123 strikethroughThickness = sty.getIntValue();
124 }
125 if (getPres(sty.setName("overline-position")))
126 {
127 overlinePosition = sty.getIntValue();
128 }
129 if (getPres(sty.setName("overline-thickness")))
130 {
131 overlineThickness = sty.getIntValue();
132 }
133 }
134
135 public String getFontFamily()
136 {
137 return fontFamily;
138 }
139
140 public int getUnitsPerEm()
141 {
142 return unitsPerEm;
143 }
144
145 public int getAscent()
146 {
147 if (ascent == -1)
148 {
149 ascent = unitsPerEm - ((Font) parent).getVertOriginY();
150 }
151 return ascent;
152 }
153
154 public int getDescent()
155 {
156 if (descent == -1)
157 {
158 descent = ((Font) parent).getVertOriginY();
159 }
160 return descent;
161 }
162
163 public int getAccentHeight()
164 {
165 if (accentHeight == -1)
166 {
167 accentHeight = getAscent();
168 }
169 return accentHeight;
170 }
171
172 public int getUnderlinePosition()
173 {
174 if (underlinePosition == -1)
175 {
176 underlinePosition = unitsPerEm * 5 / 6;
177 }
178 return underlinePosition;
179 }
180
181 public int getUnderlineThickness()
182 {
183 if (underlineThickness == -1)
184 {
185 underlineThickness = unitsPerEm / 20;
186 }
187 return underlineThickness;
188 }
189
190 public int getStrikethroughPosition()
191 {
192 if (strikethroughPosition == -1)
193 {
194 strikethroughPosition = unitsPerEm * 3 / 6;
195 }
196 return strikethroughPosition;
197 }
198
199 public int getStrikethroughThickness()
200 {
201 if (strikethroughThickness == -1)
202 {
203 strikethroughThickness = unitsPerEm / 20;
204 }
205 return strikethroughThickness;
206 }
207
208 public int getOverlinePosition()
209 {
210 if (overlinePosition == -1)
211 {
212 overlinePosition = unitsPerEm * 5 / 6;
213 }
214 return overlinePosition;
215 }
216
217 public int getOverlineThickness()
218 {
219 if (overlineThickness == -1)
220 {
221 overlineThickness = unitsPerEm / 20;
222 }
223 return overlineThickness;
224 }
225
226 /**
227 * Updates all attributes in this diagram associated with a time event. Ie,
228 * all attributes with track information.
229 *
230 * @return - true if this node has changed state as a result of the time
231 * update
232 */
233 @Override
234 public boolean updateTime(double curTime)
235 {
236 //Fonts can't change
237 return false;
238 }
239
240 /**
241 * @param unitsPerEm the unitsPerEm to set
242 */
243 public void setUnitsPerEm(int unitsPerEm)
244 {
245 this.unitsPerEm = unitsPerEm;
246 }
247
248 /**
249 * @param ascent the ascent to set
250 */
251 public void setAscent(int ascent)
252 {
253 this.ascent = ascent;
254 }
255
256 /**
257 * @param descent the descent to set
258 */
259 public void setDescent(int descent)
260 {
261 this.descent = descent;
262 }
263
264 /**
265 * @param accentHeight the accentHeight to set
266 */
267 public void setAccentHeight(int accentHeight)
268 {
269 this.accentHeight = accentHeight;
270 }
271
272 /**
273 * @param underlinePosition the underlinePosition to set
274 */
275 public void setUnderlinePosition(int underlinePosition)
276 {
277 this.underlinePosition = underlinePosition;
278 }
279
280 /**
281 * @param underlineThickness the underlineThickness to set
282 */
283 public void setUnderlineThickness(int underlineThickness)
284 {
285 this.underlineThickness = underlineThickness;
286 }
287
288 /**
289 * @param strikethroughPosition the strikethroughPosition to set
290 */
291 public void setStrikethroughPosition(int strikethroughPosition)
292 {
293 this.strikethroughPosition = strikethroughPosition;
294 }
295
296 /**
297 * @param strikethroughThickness the strikethroughThickness to set
298 */
299 public void setStrikethroughThickness(int strikethroughThickness)
300 {
301 this.strikethroughThickness = strikethroughThickness;
302 }
303
304 /**
305 * @param overlinePosition the overlinePosition to set
306 */
307 public void setOverlinePosition(int overlinePosition)
308 {
309 this.overlinePosition = overlinePosition;
310 }
311
312 /**
313 * @param overlineThickness the overlineThickness to set
314 */
315 public void setOverlineThickness(int overlineThickness)
316 {
317 this.overlineThickness = overlineThickness;
318 }
319}
Note: See TracBrowser for help on using the repository browser.