001/* 002 * SVG Salamander 003 * Copyright (c) 2004, Mark McKay 004 * All rights reserved. 005 * 006 * Redistribution and use in source and binary forms, with or 007 * without modification, are permitted provided that the following 008 * conditions are met: 009 * 010 * - Redistributions of source code must retain the above 011 * copyright notice, this list of conditions and the following 012 * disclaimer. 013 * - Redistributions in binary form must reproduce the above 014 * copyright notice, this list of conditions and the following 015 * disclaimer in the documentation and/or other materials 016 * provided with the distribution. 017 * 018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 019 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 020 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 021 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 022 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 023 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 025 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 026 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 027 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 029 * OF THE POSSIBILITY OF SUCH DAMAGE. 030 * 031 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other 032 * projects can be found at http://www.kitfox.com 033 * 034 * Created on February 20, 2004, 10:00 PM 035 */ 036package com.kitfox.svg; 037 038import com.kitfox.svg.xml.StyleAttribute; 039 040/** 041 * Implements an embedded font. 042 * 043 * SVG specification: http://www.w3.org/TR/SVG/fonts.html 044 * 045 * @author Mark McKay 046 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 047 */ 048public class FontFace extends SVGElement 049{ 050 051 public static final String TAG_NAME = "fontface"; 052 String fontFamily; 053 /** 054 * Em size of coordinate system font is defined in 055 */ 056 private int unitsPerEm = 1000; 057 private int ascent = -1; 058 private int descent = -1; 059 private int accentHeight = -1; 060 private int underlinePosition = -1; 061 private int underlineThickness = -1; 062 private int strikethroughPosition = -1; 063 private int strikethroughThickness = -1; 064 private int overlinePosition = -1; 065 private int overlineThickness = -1; 066 067 /** 068 * Creates a new instance of Font 069 */ 070 public FontFace() 071 { 072 } 073 074 public String getTagName() 075 { 076 return TAG_NAME; 077 } 078 079 protected void build() throws SVGException 080 { 081 super.build(); 082 083 StyleAttribute sty = new StyleAttribute(); 084 085 if (getPres(sty.setName("font-family"))) 086 { 087 fontFamily = sty.getStringValue(); 088 } 089 090 if (getPres(sty.setName("units-per-em"))) 091 { 092 unitsPerEm = sty.getIntValue(); 093 } 094 if (getPres(sty.setName("ascent"))) 095 { 096 ascent = sty.getIntValue(); 097 } 098 if (getPres(sty.setName("descent"))) 099 { 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 } 142 143 public int getAscent() 144 { 145 if (ascent == -1) 146 { 147 ascent = unitsPerEm - ((Font) parent).getVertOriginY(); 148 } 149 return ascent; 150 } 151 152 public int getDescent() 153 { 154 if (descent == -1) 155 { 156 descent = ((Font) parent).getVertOriginY(); 157 } 158 return descent; 159 } 160 161 public int getAccentHeight() 162 { 163 if (accentHeight == -1) 164 { 165 accentHeight = getAscent(); 166 } 167 return accentHeight; 168 } 169 170 public int getUnderlinePosition() 171 { 172 if (underlinePosition == -1) 173 { 174 underlinePosition = unitsPerEm * 5 / 6; 175 } 176 return underlinePosition; 177 } 178 179 public int getUnderlineThickness() 180 { 181 if (underlineThickness == -1) 182 { 183 underlineThickness = unitsPerEm / 20; 184 } 185 return underlineThickness; 186 } 187 188 public int getStrikethroughPosition() 189 { 190 if (strikethroughPosition == -1) 191 { 192 strikethroughPosition = unitsPerEm * 3 / 6; 193 } 194 return strikethroughPosition; 195 } 196 197 public int getStrikethroughThickness() 198 { 199 if (strikethroughThickness == -1) 200 { 201 strikethroughThickness = unitsPerEm / 20; 202 } 203 return strikethroughThickness; 204 } 205 206 public int getOverlinePosition() 207 { 208 if (overlinePosition == -1) 209 { 210 overlinePosition = unitsPerEm * 5 / 6; 211 } 212 return overlinePosition; 213 } 214 215 public int getOverlineThickness() 216 { 217 if (overlineThickness == -1) 218 { 219 overlineThickness = unitsPerEm / 20; 220 } 221 return overlineThickness; 222 } 223 224 /** 225 * Updates all attributes in this diagram associated with a time event. Ie, 226 * all attributes with track information. 227 * 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 237 /** 238 * @param unitsPerEm the unitsPerEm to set 239 */ 240 public void setUnitsPerEm(int unitsPerEm) 241 { 242 this.unitsPerEm = unitsPerEm; 243 } 244 245 /** 246 * @param ascent the ascent to set 247 */ 248 public void setAscent(int ascent) 249 { 250 this.ascent = ascent; 251 } 252 253 /** 254 * @param descent the descent to set 255 */ 256 public void setDescent(int descent) 257 { 258 this.descent = descent; 259 } 260 261 /** 262 * @param accentHeight the accentHeight to set 263 */ 264 public void setAccentHeight(int accentHeight) 265 { 266 this.accentHeight = accentHeight; 267 } 268 269 /** 270 * @param underlinePosition the underlinePosition to set 271 */ 272 public void setUnderlinePosition(int underlinePosition) 273 { 274 this.underlinePosition = underlinePosition; 275 } 276 277 /** 278 * @param underlineThickness the underlineThickness to set 279 */ 280 public void setUnderlineThickness(int underlineThickness) 281 { 282 this.underlineThickness = underlineThickness; 283 } 284 285 /** 286 * @param strikethroughPosition the strikethroughPosition to set 287 */ 288 public void setStrikethroughPosition(int strikethroughPosition) 289 { 290 this.strikethroughPosition = strikethroughPosition; 291 } 292 293 /** 294 * @param strikethroughThickness the strikethroughThickness to set 295 */ 296 public void setStrikethroughThickness(int strikethroughThickness) 297 { 298 this.strikethroughThickness = strikethroughThickness; 299 } 300 301 /** 302 * @param overlinePosition the overlinePosition to set 303 */ 304 public void setOverlinePosition(int overlinePosition) 305 { 306 this.overlinePosition = overlinePosition; 307 } 308 309 /** 310 * @param overlineThickness the overlineThickness to set 311 */ 312 public void setOverlineThickness(int overlineThickness) 313 { 314 this.overlineThickness = overlineThickness; 315 } 316}