java.lang.Object
org.sejda.sambox.pdmodel.font.FontMapperImpl
- All Implemented Interfaces:
FontMapper
Font mapper, locates non-embedded fonts via a pluggable FontProvider.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classA potential match for a font substitution. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CompletableFuture<Map<String,FontInfo>> private final org.apache.fontbox.ttf.TrueTypeFontprivate static final org.slf4j.LoggerMap of PostScript name substitutes, in priority order. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSubstitute(String match, String replace) Adds a top-priority substitute for the given font.private voidaddSubstitutes(String match, List<String> replacements) copySubstitutes(String postScriptName) Copies a list of font substitutes, adding the original font at the start of the list.private org.apache.fontbox.FontBoxFontfindFont(FontFormat format, String postScriptName) Finds a font with the given PostScript name, or a suitable substitute, or null.private org.apache.fontbox.FontBoxFontfindFontBoxFont(String postScriptName) Finds a font with the given PostScript name, or a suitable substitute, or null.getCIDFont(String baseFont, PDFontDescriptor fontDescriptor, PDCIDSystemInfo cidSystemInfo) Finds a CFF CID-Keyed font with the given PostScript name, or a suitable substitute, or null.private StringgetFallbackFontName(PDFontDescriptor fontDescriptor) Attempts to find a good fallback based on the font descriptor.private FontInfogetFont(FontFormat format, String postScriptName) Finds the named font with the given format.FontMapping<org.apache.fontbox.FontBoxFont>getFontBoxFont(String baseFont, PDFontDescriptor fontDescriptor) Finds a font with the given PostScript name, or a suitable substitute, or null.private PriorityQueue<FontMapperImpl.FontMatch>getFontMatches(PDFontDescriptor fontDescriptor, PDCIDSystemInfo cidSystemInfo) Returns a list of matching fonts, scored by suitability.org.apache.fontbox.ttf.TrueTypeFontgetPostScriptNames(String postScriptName) Gets alternative names, as seen in some PDFs, e.g.getSubstitutes(String postScriptName) Returns the substitutes for a given font.FontMapping<org.apache.fontbox.ttf.TrueTypeFont>getTrueTypeFont(String baseFont, PDFontDescriptor fontDescriptor) Finds a TrueType font with the given PostScript name, or a suitable substitute, or null.private booleanisCharSetMatch(PDCIDSystemInfo cidSystemInfo, FontInfo info) Returns true if the character set described by CIDSystemInfo is present in the given font.static FontProviderstatic org.apache.fontbox.ttf.TrueTypeFontprivate static booleanprobablyBarcodeFont(PDFontDescriptor fontDescriptor)
-
Field Details
-
fontInfoByName
-
lastResortFont
private final org.apache.fontbox.ttf.TrueTypeFont lastResortFont -
LOG
private static final org.slf4j.Logger LOG -
substitutes
Map of PostScript name substitutes, in priority order.
-
-
Constructor Details
-
FontMapperImpl
FontMapperImpl() -
FontMapperImpl
FontMapperImpl(FontProvider fontProvider)
-
-
Method Details
-
getLastResortFont
public org.apache.fontbox.ttf.TrueTypeFont getLastResortFont() -
loadLastResortFont
public static org.apache.fontbox.ttf.TrueTypeFont loadLastResortFont() -
loadFontProvider
-
getPostScriptNames
Gets alternative names, as seen in some PDFs, e.g. PDFBOX-142. -
copySubstitutes
Copies a list of font substitutes, adding the original font at the start of the list. -
addSubstitute
Adds a top-priority substitute for the given font.- Parameters:
match- PostScript name of the font to matchreplace- PostScript name of the font to use as a replacement
-
addSubstitutes
-
getSubstitutes
Returns the substitutes for a given font. -
getFallbackFontName
Attempts to find a good fallback based on the font descriptor. -
getTrueTypeFont
public FontMapping<org.apache.fontbox.ttf.TrueTypeFont> getTrueTypeFont(String baseFont, PDFontDescriptor fontDescriptor) Finds a TrueType font with the given PostScript name, or a suitable substitute, or null.- Specified by:
getTrueTypeFontin interfaceFontMapper- Parameters:
fontDescriptor- FontDescriptor
-
getFontBoxFont
public FontMapping<org.apache.fontbox.FontBoxFont> getFontBoxFont(String baseFont, PDFontDescriptor fontDescriptor) Finds a font with the given PostScript name, or a suitable substitute, or null. This allows any font to be substituted with a PFB, TTF or OTF.- Specified by:
getFontBoxFontin interfaceFontMapper- Parameters:
fontDescriptor- the FontDescriptor of the font to find
-
findFontBoxFont
Finds a font with the given PostScript name, or a suitable substitute, or null.- Parameters:
postScriptName- PostScript font name
-
findFont
Finds a font with the given PostScript name, or a suitable substitute, or null.- Parameters:
postScriptName- PostScript font name
-
getFont
Finds the named font with the given format. -
getCIDFont
public CIDFontMapping getCIDFont(String baseFont, PDFontDescriptor fontDescriptor, PDCIDSystemInfo cidSystemInfo) Finds a CFF CID-Keyed font with the given PostScript name, or a suitable substitute, or null. This method can also map CJK fonts via their CIDSystemInfo (ROS).- Specified by:
getCIDFontin interfaceFontMapper- Parameters:
fontDescriptor- FontDescriptorcidSystemInfo- the CID system info, e.g. "Adobe-Japan1", if any.
-
getFontMatches
private PriorityQueue<FontMapperImpl.FontMatch> getFontMatches(PDFontDescriptor fontDescriptor, PDCIDSystemInfo cidSystemInfo) Returns a list of matching fonts, scored by suitability. Positive scores indicate matches for certain attributes, while negative scores indicate mismatches. Zero scores are neutral.- Parameters:
fontDescriptor- FontDescriptor, always present.cidSystemInfo- Font's CIDSystemInfo, may be null.
-
probablyBarcodeFont
-
isCharSetMatch
Returns true if the character set described by CIDSystemInfo is present in the given font. Only applies to Adobe-GB1, Adobe-CNS1, Adobe-Japan1, Adobe-Korea1, as per the PDF spec.
-