1 31 package org.pdfbox.afmtypes; 32 33 import java.io.IOException ; 34 35 import java.util.ArrayList ; 36 import java.util.HashMap ; 37 import java.util.Iterator ; 38 import java.util.List ; 39 import java.util.Map ; 40 41 import org.pdfbox.util.BoundingBox; 42 43 50 public class FontMetric 51 { 52 55 private float afmVersion; 56 private int metricSets = 0; 57 private String fontName; 58 private String fullName; 59 private String familyName; 60 private String weight; 61 private BoundingBox fontBBox; 62 private String fontVersion; 63 private String notice; 64 private String encodingScheme; 65 private int mappingScheme; 66 private int escChar; 67 private String characterSet; 68 private int characters; 69 private boolean isBaseFont; 70 private float[] vVector; 71 private boolean isFixedV; 72 private float capHeight; 73 private float xHeight; 74 private float ascender; 75 private float descender; 76 private List comments = new ArrayList (); 77 78 private float underlinePosition; 79 private float underlineThickness; 80 private float italicAngle; 81 private float[] charWidth; 82 private boolean isFixedPitch; 83 private float standardHorizontalWidth; 84 private float standardVerticalWidth; 85 86 private List charMetrics = new ArrayList (); 87 private Map charMetricsMap = new HashMap (); 88 private List trackKern = new ArrayList (); 89 private List composites = new ArrayList (); 90 private List kernPairs = new ArrayList (); 91 private List kernPairs0 = new ArrayList (); 92 private List kernPairs1 = new ArrayList (); 93 94 97 public FontMetric() 98 { 99 } 100 101 110 public float getCharacterWidth( String name ) throws IOException 111 { 112 float result = 0; 113 CharMetric metric = (CharMetric)charMetricsMap.get( name ); 114 if( metric == null ) 115 { 116 result=0; 117 } 120 else 121 { 122 result = metric.getWx(); 123 } 124 return result; 125 } 126 127 134 public float getAverageCharacterWidth() throws IOException 135 { 136 float average = 0; 137 float totalWidths = 0; 138 float characterCount = 0; 139 Iterator iter = charMetricsMap.values().iterator(); 140 while( iter.hasNext() ) 141 { 142 CharMetric metric = (CharMetric)iter.next(); 143 if( metric.getWx() > 0 ) 144 { 145 totalWidths += metric.getWx(); 146 characterCount += 1; 147 } 148 } 149 if( totalWidths > 0 ) 150 { 151 average = totalWidths / characterCount; 152 } 153 154 return average; 155 } 156 157 162 public void addComment( String comment ) 163 { 164 comments.add( comment ); 165 } 166 167 172 public List getComments() 173 { 174 return comments; 175 } 176 177 182 public float getAFMVersion() 183 { 184 return afmVersion; 185 } 186 187 192 public int getMetricSets() 193 { 194 return metricSets; 195 } 196 197 202 public void setAFMVersion( float afmVersionValue ) 203 { 204 afmVersion = afmVersionValue; 205 } 206 207 212 public void setMetricSets( int metricSetsValue ) 213 { 214 if( metricSetsValue < 0 || metricSetsValue > 2 ) 215 { 216 throw new RuntimeException ( "The metricSets attribute must be in the " + 217 "set {0,1,2} and not '" + metricSetsValue + "'" ); 218 } 219 metricSets = metricSetsValue; 220 } 221 222 227 public String getFontName() 228 { 229 return fontName; 230 } 231 232 237 public void setFontName(String name) 238 { 239 fontName = name; 240 } 241 242 247 public String getFullName() 248 { 249 return fullName; 250 } 251 252 257 public void setFullName(String fullNameValue) 258 { 259 fullName = fullNameValue; 260 } 261 262 267 public String getFamilyName() 268 { 269 return familyName; 270 } 271 272 277 public void setFamilyName(String familyNameValue) 278 { 279 familyName = familyNameValue; 280 } 281 282 287 public String getWeight() 288 { 289 return weight; 290 } 291 292 297 public void setWeight(String weightValue) 298 { 299 weight = weightValue; 300 } 301 302 307 public BoundingBox getFontBBox() 308 { 309 return fontBBox; 310 } 311 312 317 public void setFontBBox(BoundingBox bBox) 318 { 319 this.fontBBox = bBox; 320 } 321 322 327 public String getNotice() 328 { 329 return notice; 330 } 331 332 337 public void setNotice(String noticeValue) 338 { 339 notice = noticeValue; 340 } 341 342 347 public String getEncodingScheme() 348 { 349 return encodingScheme; 350 } 351 352 357 public void setEncodingScheme(String encodingSchemeValue) 358 { 359 encodingScheme = encodingSchemeValue; 360 } 361 362 367 public int getMappingScheme() 368 { 369 return mappingScheme; 370 } 371 372 377 public void setMappingScheme(int mappingSchemeValue) 378 { 379 mappingScheme = mappingSchemeValue; 380 } 381 382 387 public int getEscChar() 388 { 389 return escChar; 390 } 391 392 397 public void setEscChar(int escCharValue) 398 { 399 escChar = escCharValue; 400 } 401 402 407 public String getCharacterSet() 408 { 409 return characterSet; 410 } 411 412 417 public void setCharacterSet(String characterSetValue) 418 { 419 characterSet = characterSetValue; 420 } 421 422 427 public int getCharacters() 428 { 429 return characters; 430 } 431 432 437 public void setCharacters(int charactersValue) 438 { 439 characters = charactersValue; 440 } 441 442 447 public boolean isBaseFont() 448 { 449 return isBaseFont; 450 } 451 452 457 public void setIsBaseFont(boolean isBaseFontValue) 458 { 459 isBaseFont = isBaseFontValue; 460 } 461 462 467 public float[] getVVector() 468 { 469 return this.vVector; 470 } 471 472 477 public void setVVector(float[] vVectorValue) 478 { 479 vVector = vVectorValue; 480 } 481 482 487 public boolean isFixedV() 488 { 489 return isFixedV; 490 } 491 492 497 public void setIsFixedV(boolean isFixedVValue) 498 { 499 isFixedV = isFixedVValue; 500 } 501 502 507 public float getCapHeight() 508 { 509 return capHeight; 510 } 511 512 517 public void setCapHeight(float capHeightValue) 518 { 519 capHeight = capHeightValue; 520 } 521 522 527 public float getXHeight() 528 { 529 return xHeight; 530 } 531 532 537 public void setXHeight( float xHeightValue ) 538 { 539 xHeight = xHeightValue; 540 } 541 542 547 public float getAscender() 548 { 549 return ascender; 550 } 551 552 557 public void setAscender( float ascenderValue ) 558 { 559 ascender = ascenderValue; 560 } 561 562 567 public float getDescender() 568 { 569 return descender; 570 } 571 572 577 public void setDescender( float descenderValue ) 578 { 579 descender = descenderValue; 580 } 581 582 587 public String getFontVersion() 588 { 589 return fontVersion; 590 } 591 592 597 public void setFontVersion(String fontVersionValue) 598 { 599 fontVersion = fontVersionValue; 600 } 601 602 607 public float getUnderlinePosition() 608 { 609 return underlinePosition; 610 } 611 612 617 public void setUnderlinePosition(float underlinePositionValue) 618 { 619 underlinePosition = underlinePositionValue; 620 } 621 622 627 public float getUnderlineThickness() 628 { 629 return underlineThickness; 630 } 631 632 637 public void setUnderlineThickness(float underlineThicknessValue) 638 { 639 underlineThickness = underlineThicknessValue; 640 } 641 642 647 public float getItalicAngle() 648 { 649 return italicAngle; 650 } 651 652 657 public void setItalicAngle(float italicAngleValue) 658 { 659 italicAngle = italicAngleValue; 660 } 661 662 667 public float[] getCharWidth() 668 { 669 return this.charWidth; 670 } 671 672 677 public void setCharWidth(float[] charWidthValue) 678 { 679 charWidth = charWidthValue; 680 } 681 682 687 public boolean isFixedPitch() 688 { 689 return isFixedPitch; 690 } 691 692 697 public void setFixedPitch(boolean isFixedPitchValue) 698 { 699 isFixedPitch = isFixedPitchValue; 700 } 701 702 705 public List getCharMetrics() 706 { 707 return charMetrics; 708 } 709 710 713 public void setCharMetrics(List charMetricsValue) 714 { 715 charMetrics = charMetricsValue; 716 } 717 718 723 public void addCharMetric( CharMetric metric ) 724 { 725 charMetrics.add( metric ); 726 charMetricsMap.put( metric.getName(), metric ); 727 } 728 729 732 public List getTrackKern() 733 { 734 return trackKern; 735 } 736 737 740 public void setTrackKern(List trackKernValue) 741 { 742 trackKern = trackKernValue; 743 } 744 745 750 public void addTrackKern( TrackKern kern ) 751 { 752 trackKern.add( kern ); 753 } 754 755 758 public List getComposites() 759 { 760 return composites; 761 } 762 763 766 public void setComposites(List compositesList) 767 { 768 composites = compositesList; 769 } 770 771 776 public void addComposite( Composite composite ) 777 { 778 composites.add( composite ); 779 } 780 781 784 public java.util.List getKernPairs() 785 { 786 return kernPairs; 787 } 788 789 794 public void addKernPair( KernPair kernPair ) 795 { 796 kernPairs.add( kernPair ); 797 } 798 799 802 public void setKernPairs(java.util.List kernPairsList) 803 { 804 kernPairs = kernPairsList; 805 } 806 807 810 public java.util.List getKernPairs0() 811 { 812 return kernPairs0; 813 } 814 815 820 public void addKernPair0( KernPair kernPair ) 821 { 822 kernPairs0.add( kernPair ); 823 } 824 825 828 public void setKernPairs0(java.util.List kernPairs0List) 829 { 830 kernPairs0 = kernPairs0List; 831 } 832 833 836 public java.util.List getKernPairs1() 837 { 838 return kernPairs1; 839 } 840 841 846 public void addKernPair1( KernPair kernPair ) 847 { 848 kernPairs1.add( kernPair ); 849 } 850 851 854 public void setKernPairs1(java.util.List kernPairs1List) 855 { 856 kernPairs1 = kernPairs1List; 857 } 858 859 862 public float getStandardHorizontalWidth() 863 { 864 return standardHorizontalWidth; 865 } 866 867 870 public void setStandardHorizontalWidth(float standardHorizontalWidthValue) 871 { 872 standardHorizontalWidth = standardHorizontalWidthValue; 873 } 874 875 878 public float getStandardVerticalWidth() 879 { 880 return standardVerticalWidth; 881 } 882 883 886 public void setStandardVerticalWidth(float standardVerticalWidthValue) 887 { 888 standardVerticalWidth = standardVerticalWidthValue; 889 } 890 891 } | Popular Tags |