final class FontMapperImpl extends java.lang.Object implements FontMapper
Modifier and Type | Class and Description |
---|---|
private static class |
FontMapperImpl.DefaultFontProvider |
private static class |
FontMapperImpl.FontMatch
A potential match for a font substitution.
|
Modifier and Type | Field and Description |
---|---|
private static FontCache |
fontCache |
private java.util.Map<java.lang.String,FontInfo> |
fontInfoByName |
private FontProvider |
fontProvider |
private TrueTypeFont |
lastResortFont |
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
substitutes
Map of PostScript name substitutes, in priority order.
|
Constructor and Description |
---|
FontMapperImpl() |
Modifier and Type | Method and Description |
---|---|
void |
addSubstitute(java.lang.String match,
java.lang.String replace)
Adds a top-priority substitute for the given font.
|
private java.util.List<java.lang.String> |
copySubstitutes(java.lang.String postScriptName)
Copies a list of font substitutes, adding the original font at the start of the list.
|
private java.util.Map<java.lang.String,FontInfo> |
createFontInfoByName(java.util.List<? extends FontInfo> fontInfoList) |
private FontBoxFont |
findFont(FontFormat format,
java.lang.String postScriptName)
Finds a font with the given PostScript name, or a suitable substitute, or null.
|
private FontBoxFont |
findFontBoxFont(java.lang.String postScriptName)
Finds a font with the given PostScript name, or a suitable substitute, or null.
|
CIDFontMapping |
getCIDFont(java.lang.String baseFont,
PDFontDescriptor fontDescriptor,
PDCIDSystemInfo cidSystemInfo)
Finds a CFF CID-Keyed font with the given PostScript name, or a suitable substitute, or null.
|
private java.lang.String |
getFallbackFontName(PDFontDescriptor fontDescriptor)
Attempts to find a good fallback based on the font descriptor.
|
private FontInfo |
getFont(FontFormat format,
java.lang.String postScriptName)
Finds the named font with the given format.
|
FontMapping<FontBoxFont> |
getFontBoxFont(java.lang.String baseFont,
PDFontDescriptor fontDescriptor)
Finds a font with the given PostScript name, or a suitable substitute, or null.
|
FontCache |
getFontCache()
Returns the font cache associated with this FontMapper.
|
private java.util.PriorityQueue<FontMapperImpl.FontMatch> |
getFontMatches(PDFontDescriptor fontDescriptor,
PDCIDSystemInfo cidSystemInfo)
Returns a list of matching fonts, scored by suitability.
|
private java.util.Set<java.lang.String> |
getPostScriptNames(java.lang.String postScriptName)
Gets alternative names, as seen in some PDFs, e.g.
|
FontProvider |
getProvider()
Returns the font service provider.
|
private java.util.List<java.lang.String> |
getSubstitutes(java.lang.String postScriptName)
Returns the substitutes for a given font.
|
FontMapping<TrueTypeFont> |
getTrueTypeFont(java.lang.String baseFont,
PDFontDescriptor fontDescriptor)
Finds a TrueType font with the given PostScript name, or a suitable substitute, or null.
|
private boolean |
isCharSetMatch(PDCIDSystemInfo cidSystemInfo,
FontInfo info)
Returns true if the character set described by CIDSystemInfo is present in the given font.
|
private FontMapperImpl.FontMatch |
printMatches(java.util.PriorityQueue<FontMapperImpl.FontMatch> queue)
For debugging.
|
private boolean |
probablyBarcodeFont(PDFontDescriptor fontDescriptor) |
void |
setProvider(FontProvider fontProvider)
Sets the font service provider.
|
private static final FontCache fontCache
private FontProvider fontProvider
private java.util.Map<java.lang.String,FontInfo> fontInfoByName
private final TrueTypeFont lastResortFont
private final java.util.Map<java.lang.String,java.util.List<java.lang.String>> substitutes
public void setProvider(FontProvider fontProvider)
public FontProvider getProvider()
public FontCache getFontCache()
private java.util.Map<java.lang.String,FontInfo> createFontInfoByName(java.util.List<? extends FontInfo> fontInfoList)
private java.util.Set<java.lang.String> getPostScriptNames(java.lang.String postScriptName)
private java.util.List<java.lang.String> copySubstitutes(java.lang.String postScriptName)
public void addSubstitute(java.lang.String match, java.lang.String replace)
match
- PostScript name of the font to matchreplace
- PostScript name of the font to use as a replacementprivate java.util.List<java.lang.String> getSubstitutes(java.lang.String postScriptName)
private java.lang.String getFallbackFontName(PDFontDescriptor fontDescriptor)
public FontMapping<TrueTypeFont> getTrueTypeFont(java.lang.String baseFont, PDFontDescriptor fontDescriptor)
getTrueTypeFont
in interface FontMapper
fontDescriptor
- FontDescriptorpublic FontMapping<FontBoxFont> getFontBoxFont(java.lang.String baseFont, PDFontDescriptor fontDescriptor)
getFontBoxFont
in interface FontMapper
fontDescriptor
- the FontDescriptor of the font to findprivate FontBoxFont findFontBoxFont(java.lang.String postScriptName)
postScriptName
- PostScript font nameprivate FontBoxFont findFont(FontFormat format, java.lang.String postScriptName)
postScriptName
- PostScript font nameprivate FontInfo getFont(FontFormat format, java.lang.String postScriptName)
public CIDFontMapping getCIDFont(java.lang.String baseFont, PDFontDescriptor fontDescriptor, PDCIDSystemInfo cidSystemInfo)
getCIDFont
in interface FontMapper
fontDescriptor
- FontDescriptorcidSystemInfo
- the CID system info, e.g. "Adobe-Japan1", if any.private java.util.PriorityQueue<FontMapperImpl.FontMatch> getFontMatches(PDFontDescriptor fontDescriptor, PDCIDSystemInfo cidSystemInfo)
fontDescriptor
- FontDescriptor, always present.cidSystemInfo
- Font's CIDSystemInfo, may be null.private boolean probablyBarcodeFont(PDFontDescriptor fontDescriptor)
private boolean isCharSetMatch(PDCIDSystemInfo cidSystemInfo, FontInfo info)
private FontMapperImpl.FontMatch printMatches(java.util.PriorityQueue<FontMapperImpl.FontMatch> queue)