Class AbstractFontSelectorStrategy
- java.lang.Object
-
- com.itextpdf.layout.font.selectorstrategy.AbstractFontSelectorStrategy
-
- All Implemented Interfaces:
IFontSelectorStrategy
- Direct Known Subclasses:
BestMatchFontSelectorStrategy
,FirstMatchFontSelectorStrategy
public abstract class AbstractFontSelectorStrategy extends java.lang.Object implements IFontSelectorStrategy
The class defines complex implementation ofIFontSelectorStrategy
which based on the following algorithm: 1. Find first significant symbol (not whitespace or special). 2. Find font which matches symbol according to passedFontSelector
. 3. Try to append as many symbols as possible using the current font. 4. If symbol is not matched to the current font, go to step 1.Algorithm takes care of the case when there is no matched font for symbol or when diacritic from another font is used (previous symbol will be processed by diacritic's font).
-
-
Field Summary
Fields Modifier and Type Field Description private FontSet
additionalFonts
private FontProvider
fontProvider
private FontSelector
fontSelector
-
Constructor Summary
Constructors Constructor Description AbstractFontSelectorStrategy(FontProvider fontProvider, FontSelector fontSelector, FontSet additionalFonts)
Creates a new instance ofAbstractFontSelectorStrategy
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private static int
extractCodePoint(java.lang.String text, int idx)
java.util.List<Tuple2<GlyphLine,PdfFont>>
getGlyphLines(java.lang.String text)
Converts text into glyphs with the best matching font.private static PdfFont
getPdfFont(FontInfo fontInfo, FontProvider fontProvider, FontSet additionalFonts)
Utility method to create PdfFont.protected abstract boolean
isCurrentFontCheckRequired()
If it is necessary to provide a check that the best font for passed symbol equals to the current font.private static boolean
isSignificantUnicodeScript(java.lang.Character.UnicodeScript unicodeScript)
protected PdfFont
matchFont(int codePoint, FontSelector fontSelector, FontProvider fontProvider, FontSet additionalFonts)
Finds the best font which matches passed symbol.private static int
nextSignificantIndex(int startIndex, java.lang.String text)
-
-
-
Field Detail
-
fontProvider
private final FontProvider fontProvider
-
additionalFonts
private final FontSet additionalFonts
-
fontSelector
private final FontSelector fontSelector
-
-
Constructor Detail
-
AbstractFontSelectorStrategy
public AbstractFontSelectorStrategy(FontProvider fontProvider, FontSelector fontSelector, FontSet additionalFonts)
Creates a new instance ofAbstractFontSelectorStrategy
.- Parameters:
fontProvider
- the font providerfontSelector
- the font selectoradditionalFonts
- the set of fonts to be used additionally to the fonts added to font provider.
-
-
Method Detail
-
isCurrentFontCheckRequired
protected abstract boolean isCurrentFontCheckRequired()
If it is necessary to provide a check that the best font for passed symbol equals to the current font. Result of checking is used to split text into parts in case if inequality.- Returns:
true
if check is needed, otherwisefalse
-
getGlyphLines
public java.util.List<Tuple2<GlyphLine,PdfFont>> getGlyphLines(java.lang.String text)
Converts text into glyphs with the best matching font.- Specified by:
getGlyphLines
in interfaceIFontSelectorStrategy
- Parameters:
text
- the text to split- Returns:
- the glyphs with the matching font attached
-
matchFont
protected PdfFont matchFont(int codePoint, FontSelector fontSelector, FontProvider fontProvider, FontSet additionalFonts)
Finds the best font which matches passed symbol.- Parameters:
codePoint
- the symbol to matchfontSelector
- the font selectorfontProvider
- the font provideradditionalFonts
- the addition fonts- Returns:
- font which matches the symbol
-
nextSignificantIndex
private static int nextSignificantIndex(int startIndex, java.lang.String text)
-
isSignificantUnicodeScript
private static boolean isSignificantUnicodeScript(java.lang.Character.UnicodeScript unicodeScript)
-
extractCodePoint
private static int extractCodePoint(java.lang.String text, int idx)
-
getPdfFont
private static PdfFont getPdfFont(FontInfo fontInfo, FontProvider fontProvider, FontSet additionalFonts)
Utility method to create PdfFont.- Parameters:
fontInfo
- instance of FontInfo- Returns:
- cached or just created PdfFont on success, otherwise null
- See Also:
FontProvider.getPdfFont(FontInfo, FontSet)
-
-