1 31 package org.pdfbox.pdmodel.font; 32 33 import java.io.IOException ; 34 35 import org.fontbox.afm.FontMetric; 36 37 import org.pdfbox.pdmodel.common.PDRectangle; 38 39 import org.fontbox.util.BoundingBox; 40 41 48 public class PDFontDescriptorAFM extends PDFontDescriptor 49 { 50 private FontMetric afm; 51 52 57 public PDFontDescriptorAFM( FontMetric afmFile ) 58 { 59 afm = afmFile; 60 } 61 62 67 public String getFontName() 68 { 69 return afm.getFontName(); 70 } 71 72 77 public void setFontName( String fontName ) 78 { 79 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 80 } 81 82 87 public String getFontFamily() 88 { 89 return afm.getFamilyName(); 90 } 91 92 97 public void setFontFamily( String fontFamily ) 98 { 99 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 100 } 101 102 109 public float getFontWeight() 110 { 111 String weight = afm.getWeight(); 112 float retval = 500; 113 if( weight != null && weight.equalsIgnoreCase( "bold" ) ) 114 { 115 retval = 900; 116 } 117 else if( weight != null && weight.equalsIgnoreCase( "light" ) ) 118 { 119 retval = 100; 120 } 121 return retval; 122 } 123 124 129 public void setFontWeight( float fontWeight ) 130 { 131 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 132 } 133 134 139 public String getFontStretch() 140 { 141 return null; 142 } 143 144 149 public void setFontStretch( String fontStretch ) 150 { 151 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 152 } 153 154 159 public int getFlags() 160 { 161 return afm.isFixedPitch() ? 1 : 0; 163 } 164 165 170 public void setFlags( int flags ) 171 { 172 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 173 } 174 175 180 public PDRectangle getFontBoundingBox() 181 { 182 BoundingBox box = afm.getFontBBox(); 183 PDRectangle retval = null; 184 if( box != null ) 185 { 186 retval = new PDRectangle( box ); 187 } 188 return retval; 189 } 190 191 196 public void setFontBoundingBox( PDRectangle rect ) 197 { 198 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 199 } 200 201 206 public float getItalicAngle() 207 { 208 return afm.getItalicAngle(); 209 } 210 211 216 public void setItalicAngle( float angle ) 217 { 218 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 219 } 220 221 226 public float getAscent() 227 { 228 return afm.getAscender(); 229 } 230 231 236 public void setAscent( float ascent ) 237 { 238 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 239 } 240 241 246 public float getDescent() 247 { 248 return afm.getDescender(); 249 } 250 251 256 public void setDescent( float descent ) 257 { 258 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 259 } 260 261 266 public float getLeading() 267 { 268 return 0f; 270 } 271 272 277 public void setLeading( float leading ) 278 { 279 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 280 } 281 282 287 public float getCapHeight() 288 { 289 return afm.getCapHeight(); 290 } 291 292 297 public void setCapHeight( float capHeight ) 298 { 299 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 300 } 301 302 307 public float getXHeight() 308 { 309 return afm.getXHeight(); 310 } 311 312 317 public void setXHeight( float xHeight ) 318 { 319 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 320 } 321 322 327 public float getStemV() 328 { 329 return 0; 331 } 332 333 338 public void setStemV( float stemV ) 339 { 340 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 341 } 342 343 348 public float getStemH() 349 { 350 return 0; 352 } 353 354 359 public void setStemH( float stemH ) 360 { 361 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 362 } 363 364 371 public float getAverageWidth() throws IOException 372 { 373 return afm.getAverageCharacterWidth(); 374 } 375 376 381 public void setAverageWidth( float averageWidth ) 382 { 383 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 384 } 385 386 391 public float getMaxWidth() 392 { 393 return 0; 395 } 396 397 402 public void setMaxWidth( float maxWidth ) 403 { 404 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 405 } 406 407 412 public float getMissingWidth() 413 { 414 return 0; 415 } 416 417 422 public void setMissingWidth( float missingWidth ) 423 { 424 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 425 } 426 427 432 public String getCharSet() 433 { 434 return afm.getCharacterSet(); 435 } 436 437 442 public void setCharacterSet( String charSet ) 443 { 444 throw new UnsupportedOperationException ( "The AFM Font descriptor is immutable" ); 445 } 446 } | Popular Tags |