Class FontSelector.PdfFontComparator

java.lang.Object
com.itextpdf.layout.font.FontSelector.PdfFontComparator
All Implemented Interfaces:
Comparator<FontInfo>
Enclosing class:
FontSelector

private static class FontSelector.PdfFontComparator extends Object implements Comparator<FontInfo>
  • Field Details

  • Constructor Details

  • Method Details

    • compare

      public int compare(FontInfo o1, FontInfo o2)
      Specified by:
      compare in interface Comparator<FontInfo>
    • parseFontStyle

      private static FontCharacteristics parseFontStyle(String fontFamily, FontCharacteristics fc)
    • characteristicsSimilarity

      private static int characteristicsSimilarity(String fontFamily, FontCharacteristics fc, FontInfo fontInfo, boolean isLastFontFamilyToBeProcessed)
      This method is used to compare two fonts (the required one which is described by fontInfo and the one to be examined which is described by fc and fontFamily) and measure their similarity. The more the fonts are similar the higher the score is.

      Firstly we check if the font-family described by fontInfo equals to the required one. If it's not true the examination fails, it continues otherwise. If the required font-family is monospace, serif or sans serif we check whether the font under examination is monospace, serif or sans serif resp. Its font-family is not taking into considerations.

      If font-family is respected, we consider the next font-style characteristics to select the required font of the respected font-family: a) bold b) italic

    • family2Similarity

      private static int family2Similarity(String fontFamily, FontCharacteristics fc, FontInfo fontInfo)
      This method is a fallback to compare family2 field if the main method wasn't able to prioritize the fonts.