Class FontSelector.PdfFontComparator

  • All Implemented Interfaces:
    java.util.Comparator<FontInfo>
    Enclosing class:
    FontSelector

    private static class FontSelector.PdfFontComparator
    extends java.lang.Object
    implements java.util.Comparator<FontInfo>
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static int characteristicsSimilarity​(java.lang.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.
      int compare​(FontInfo o1, FontInfo o2)  
      private static int family2Similarity​(java.lang.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.
      private static FontCharacteristics parseFontStyle​(java.lang.String fontFamily, FontCharacteristics fc)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Field Detail

      • fontFamilies

        java.util.List<java.lang.String> fontFamilies
    • Constructor Detail

      • PdfFontComparator

        PdfFontComparator​(java.util.List<java.lang.String> fontFamilies,
                          FontCharacteristics fc)
    • Method Detail

      • compare

        public int compare​(FontInfo o1,
                           FontInfo o2)
        Specified by:
        compare in interface java.util.Comparator<FontInfo>
      • characteristicsSimilarity

        private static int characteristicsSimilarity​(java.lang.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​(java.lang.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.