Package com.itextpdf.layout.font
Class FontSelector.PdfFontComparator
- java.lang.Object
-
- com.itextpdf.layout.font.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>
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.List<java.lang.String>
fontFamilies
(package private) java.util.List<FontCharacteristics>
fontStyles
-
Constructor Summary
Constructors Constructor Description PdfFontComparator(java.util.List<java.lang.String> fontFamilies, FontCharacteristics fc)
-
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)
-
-
-
Field Detail
-
fontFamilies
java.util.List<java.lang.String> fontFamilies
-
fontStyles
java.util.List<FontCharacteristics> fontStyles
-
-
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 interfacejava.util.Comparator<FontInfo>
-
parseFontStyle
private static FontCharacteristics parseFontStyle(java.lang.String fontFamily, FontCharacteristics fc)
-
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.
-
-