1 17 18 19 20 package org.apache.fop.fonts; 21 22 import java.io.IOException ; 23 import java.util.Map ; 24 import javax.xml.transform.Source ; 25 26 29 public abstract class CustomFont extends Typeface 30 implements FontDescriptor, MutableFont { 31 32 private String fontName = null; 33 private String embedFileName = null; 34 protected String embedResourceName = null; 35 private FontResolver resolver = null; 36 37 private int capHeight = 0; 38 private int xHeight = 0; 39 private int ascender = 0; 40 private int descender = 0; 41 private int[] fontBBox = {0, 0, 0, 0}; 42 private int flags = 4; 43 private int stemV = 0; 44 private int italicAngle = 0; 45 private int missingWidth = 0; 46 private FontType fontType = FontType.TYPE1; 47 private int firstChar = 0; 48 private int lastChar = 255; 49 50 private Map kerning; 51 52 private boolean useKerning = true; 53 54 55 58 public String getFontName() { 59 return fontName; 60 } 61 62 67 public String getEmbedFileName() { 68 return embedFileName; 69 } 70 71 76 public Source getEmbedFileSource() throws IOException { 77 Source result = null; 78 if (resolver != null && embedFileName != null) { 79 result = resolver.resolve(embedFileName); 80 if(result == null) throw new IOException ("Unable to resolve Source '" + embedFileName + "' for embedded font"); 81 } 82 return result; 83 } 84 85 91 public String getEmbedResourceName() { 92 return embedResourceName; 93 } 94 95 98 public int getAscender() { 99 return ascender; 100 } 101 102 105 public int getDescender() { 106 return descender; 107 } 108 109 112 public int getCapHeight() { 113 return capHeight; 114 } 115 116 119 public int getAscender(int size) { 120 return size * ascender; 121 } 122 123 126 public int getDescender(int size) { 127 return size * descender; 128 } 129 130 133 public int getCapHeight(int size) { 134 return size * capHeight; 135 } 136 137 140 public int getXHeight(int size) { 141 return size * xHeight; 142 } 143 144 147 public int[] getFontBBox() { 148 return fontBBox; 149 } 150 151 154 public int getFlags() { 155 return flags; 156 } 157 158 161 public int getStemV() { 162 return stemV; 163 } 164 165 168 public int getItalicAngle() { 169 return italicAngle; 170 } 171 172 176 public int getMissingWidth() { 177 return missingWidth; 178 } 179 180 183 public FontType getFontType() { 184 return fontType; 185 } 186 187 191 public int getFirstChar() { 192 return 0; 193 195 } 196 197 201 public int getLastChar() { 202 return lastChar; 203 } 204 205 209 public boolean isKerningEnabled() { 210 return useKerning; 211 } 212 213 216 public final boolean hasKerningInfo() { 217 return (isKerningEnabled() && (kerning != null) && !kerning.isEmpty()); 218 } 219 220 223 public final Map getKerningInfo() { 224 if (hasKerningInfo()) { 225 return kerning; 226 } else { 227 return java.util.Collections.EMPTY_MAP; 228 } 229 } 230 231 232 233 234 237 public void setFontName(String name) { 238 this.fontName = name; 239 } 240 241 244 public void setEmbedFileName(String path) { 245 this.embedFileName = path; 246 } 247 248 251 public void setEmbedResourceName(String name) { 252 this.embedResourceName = name; 253 } 254 255 258 public void setCapHeight(int capHeight) { 259 this.capHeight = capHeight; 260 } 261 262 266 public void setXHeight(int xHeight) { 267 this.xHeight = xHeight; 268 } 269 270 273 public void setAscender(int ascender) { 274 this.ascender = ascender; 275 } 276 277 280 public void setDescender(int descender) { 281 this.descender = descender; 282 } 283 284 287 public void setFontBBox(int[] bbox) { 288 this.fontBBox = bbox; 289 } 290 291 294 public void setFlags(int flags) { 295 this.flags = flags; 296 } 297 298 301 public void setStemV(int stemV) { 302 this.stemV = stemV; 303 } 304 305 308 public void setItalicAngle(int italicAngle) { 309 this.italicAngle = italicAngle; 310 } 311 312 315 public void setMissingWidth(int width) { 316 this.missingWidth = width; 317 } 318 319 322 public void setFontType(FontType fontType) { 323 this.fontType = fontType; 324 } 325 326 329 public void setFirstChar(int index) { 330 this.firstChar = index; 331 } 332 333 336 public void setLastChar(int index) { 337 this.lastChar = index; 338 } 339 340 343 public void setKerningEnabled(boolean enabled) { 344 this.useKerning = enabled; 345 } 346 347 351 public void setResolver(FontResolver resolver) { 352 this.resolver = resolver; 353 } 354 355 358 public void putKerningEntry(Integer key, Map value) { 359 if (kerning == null) { 360 kerning = new java.util.HashMap (); 361 } 362 this.kerning.put(key, value); 363 } 364 365 } 366 | Popular Tags |