Top Description Inners Fields Constructors Methods
org.apache.pdfbox.pdmodel.font

pack-priv final Class FontMapperImpl

extends Object
implements FontMapper
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.pdmodel.font.FontMapper
Imports
java.io.IOException, .InputStream, java.util.ArrayList, .Arrays, .Collections, .HashMap, .HashSet, .LinkedHashMap, .List, .Locale, .Map, .PriorityQueue, .Set, org.apache.commons.logging.Log, .LogFactory, org.apache.fontbox.FontBoxFont, org.apache.fontbox.ttf.OpenTypeFont, .TTFParser, .TrueTypeFont, org.apache.fontbox.type1.Type1Font, org.apache.pdfbox.io.RandomAccessReadBuffer, org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName

Font mapper, locates non-embedded fonts via a pluggable FontProvider.
Author
John Hewson

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
FontMapperImpl.FontMatch

A potential match for a font substitution.

Field Summary

Modifier and TypeField and Description
private static final FontCache
private Map<String, FontInfo>
private FontProvider
private final TrueTypeFont
private static final Log
private final Map<String, List<String>>
substitutes

Map of PostScript name substitutes, in priority order.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
addSubstitute(String
PostScript name of the font to match
match
,
String
PostScript name of the font to use as a replacement
replace
)

Adds a top-priority substitute for the given font.

private void
addSubstitutes(String match, List<String> replacements)

private Map<String, FontInfo>
createFontInfoByName(List<? extends FontInfo> fontInfoList)

private FontBoxFont
findFont(FontFormat format, String
PostScript font name
postScriptName
)

Finds a font with the given PostScript name, or a suitable substitute, or null.

private FontBoxFont
findFontBoxFont(String
PostScript font name
postScriptName
)

Finds a font with the given PostScript name, or a suitable substitute, or null.

public CIDFontMapping
getCIDFont(String
PostScript name of the mapped font
baseFont
,
PDFontDescriptor
FontDescriptor
fontDescriptor
,
PDCIDSystemInfo
the CID system info, e.g. "Adobe-Japan1", if any.
cidSystemInfo
)

Implements org.apache.pdfbox.pdmodel.font.FontMapper.getCIDFont.

Finds a CFF CID-Keyed font with the given PostScript name, or a suitable substitute, or null.

private String
getFallbackFontName(PDFontDescriptor fontDescriptor)

Attempts to find a good fallback based on the font descriptor.

private FontInfo
getFont(FontFormat format, String postScriptName)

Finds the named font with the given format.

public FontMapping<FontBoxFont>
getFontBoxFont(String
PostScript name of the mapped font
baseFont
,
PDFontDescriptor
the FontDescriptor of the font to find
fontDescriptor
)

Implements org.apache.pdfbox.pdmodel.font.FontMapper.getFontBoxFont.

Finds a font with the given PostScript name, or a suitable substitute, or null.

public FontCache
getFontCache()

Returns the font cache associated with this FontMapper.

private PriorityQueue<FontMapperImpl.FontMatch>
getFontMatches(PDFontDescriptor
FontDescriptor, always present.
fontDescriptor
,
PDCIDSystemInfo
Font's CIDSystemInfo, may be null.
cidSystemInfo
)

Returns a list of matching fonts, scored by suitability.

private Set<String>
getPostScriptNames(String postScriptName)

Gets alternative names, as seen in some PDFs, e.g. PDFBOX-142.

public synchronized FontProvider
getProvider()

Returns the font service provider.

private List<String>
getSubstitutes(String postScriptName)

Returns the substitutes for a given font.

public FontMapping<TrueTypeFont>
getTrueTypeFont(String
PostScript name of the mapped font
baseFont
,
PDFontDescriptor
FontDescriptor
fontDescriptor
)

Implements org.apache.pdfbox.pdmodel.font.FontMapper.getTrueTypeFont.

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
private boolean
public synchronized void
setProvider(FontProvider fontProvider)

Sets the font service provider.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fontCacheback to summary
private static final FontCache fontCache
fontInfoByNameback to summary
private Map<String, FontInfo> fontInfoByName
fontProviderback to summary
private FontProvider fontProvider
lastResortFontback to summary
private final TrueTypeFont lastResortFont
LOGback to summary
private static final Log LOG
substitutesback to summary
private final Map<String, List<String>> substitutes

Map of PostScript name substitutes, in priority order.

Constructor Detail

FontMapperImplback to summary
pack-priv FontMapperImpl()

Method Detail

addSubstituteback to summary
public void addSubstitute(String match, String replace)

Adds a top-priority substitute for the given font.

Parameters
match:String

PostScript name of the font to match

replace:String

PostScript name of the font to use as a replacement

addSubstitutesback to summary
private void addSubstitutes(String match, List<String> replacements)
createFontInfoByNameback to summary
private Map<String, FontInfo> createFontInfoByName(List<? extends FontInfo> fontInfoList)
findFontback to summary
private FontBoxFont findFont(FontFormat format, String postScriptName)

Finds a font with the given PostScript name, or a suitable substitute, or null.

Parameters
postScriptName:String

PostScript font name

findFontBoxFontback to summary
private FontBoxFont findFontBoxFont(String postScriptName)

Finds a font with the given PostScript name, or a suitable substitute, or null.

Parameters
postScriptName:String

PostScript font name

getCIDFontback to summary
public CIDFontMapping getCIDFont(String baseFont, PDFontDescriptor fontDescriptor, PDCIDSystemInfo cidSystemInfo)

Implements org.apache.pdfbox.pdmodel.font.FontMapper.getCIDFont.

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).

Parameters
baseFont:String

Doc from org.apache.pdfbox.pdmodel.font.FontMapper.getCIDFont.

PostScript name of the mapped font

fontDescriptor:PDFontDescriptor

FontDescriptor

cidSystemInfo:PDCIDSystemInfo

the CID system info, e.g. "Adobe-Japan1", if any.

Returns:CIDFontMapping

Doc from org.apache.pdfbox.pdmodel.font.FontMapper.getCIDFont.

the mapped CIDFont font or null

Annotations
@Override
getFallbackFontNameback to summary
private String getFallbackFontName(PDFontDescriptor fontDescriptor)

Attempts to find a good fallback based on the font descriptor.

getFontback to summary
private FontInfo getFont(FontFormat format, String postScriptName)

Finds the named font with the given format.

getFontBoxFontback to summary
public FontMapping<FontBoxFont> getFontBoxFont(String baseFont, PDFontDescriptor fontDescriptor)

Implements org.apache.pdfbox.pdmodel.font.FontMapper.getFontBoxFont.

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.

Parameters
baseFont:String

Doc from org.apache.pdfbox.pdmodel.font.FontMapper.getFontBoxFont.

PostScript name of the mapped font

fontDescriptor:PDFontDescriptor

the FontDescriptor of the font to find

Returns:FontMapping<FontBoxFont>

Doc from org.apache.pdfbox.pdmodel.font.FontMapper.getFontBoxFont.

the mapped FontBox font or null

Annotations
@Override
getFontCacheback to summary
public FontCache getFontCache()

Returns the font cache associated with this FontMapper. This method is needed by FontProvider subclasses.

getFontMatchesback to summary
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:PDFontDescriptor

FontDescriptor, always present.

cidSystemInfo:PDCIDSystemInfo

Font's CIDSystemInfo, may be null.

getPostScriptNamesback to summary
private Set<String> getPostScriptNames(String postScriptName)

Gets alternative names, as seen in some PDFs, e.g. PDFBOX-142.

getProviderback to summary
public synchronized FontProvider getProvider()

Returns the font service provider. Defaults to using FileSystemFontProvider.

getSubstitutesback to summary
private List<String> getSubstitutes(String postScriptName)

Returns the substitutes for a given font.

getTrueTypeFontback to summary
public FontMapping<TrueTypeFont> getTrueTypeFont(String baseFont, PDFontDescriptor fontDescriptor)

Implements org.apache.pdfbox.pdmodel.font.FontMapper.getTrueTypeFont.

Finds a TrueType font with the given PostScript name, or a suitable substitute, or null.

Parameters
baseFont:String

Doc from org.apache.pdfbox.pdmodel.font.FontMapper.getTrueTypeFont.

PostScript name of the mapped font

fontDescriptor:PDFontDescriptor

FontDescriptor

Returns:FontMapping<TrueTypeFont>

Doc from org.apache.pdfbox.pdmodel.font.FontMapper.getTrueTypeFont.

the mapped TrueType font or null

Annotations
@Override
isCharSetMatchback to summary
private boolean isCharSetMatch(PDCIDSystemInfo cidSystemInfo, FontInfo info)

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.

printMatchesback to summary
private FontMapperImpl.FontMatch printMatches(PriorityQueue<FontMapperImpl.FontMatch> queue)

For debugging. Prints all matches and returns the best match.

probablyBarcodeFontback to summary
private boolean probablyBarcodeFont(PDFontDescriptor fontDescriptor)
setProviderback to summary
public synchronized void setProvider(FontProvider fontProvider)

Sets the font service provider.

org.apache.pdfbox.pdmodel.font back to summary

private Class FontMapperImpl.DefaultFontProvider

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.pdfbox.pdmodel.font.FontMapperImpl.DefaultFontProvider

Field Summary

Modifier and TypeField and Description
private static final FontProvider

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
private static final FontProvider INSTANCE

Constructor Detail

DefaultFontProviderback to summary
private DefaultFontProvider()
org.apache.pdfbox.pdmodel.font back to summary

private Class FontMapperImpl.FontMatch

extends Object
implements Comparable<FontMapperImpl.FontMatch>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable

A potential match for a font substitution.

Field Summary

Modifier and TypeField and Description
pack-priv final FontInfo
pack-priv double

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(FontMapperImpl.FontMatch
the object to be compared.
match
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

infoback to summary
pack-priv final FontInfo info
scoreback to summary
pack-priv double score

Constructor Detail

FontMatchback to summary
pack-priv FontMatch(FontInfo info)

Method Detail

compareToback to summary
public int compareTo(FontMapperImpl.FontMatch match)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
match:FontMapperImpl.FontMatch

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override