Class FontMapperImpl

java.lang.Object
org.apache.pdfbox.pdmodel.font.FontMapperImpl
All Implemented Interfaces:
FontMapper

final class FontMapperImpl extends Object implements FontMapper
Font mapper, locates non-embedded fonts via a pluggable FontProvider.
  • Field Details

    • LOG

      private static final org.apache.commons.logging.Log LOG
    • fontCache

      private static final FontCache fontCache
    • fontProvider

      private FontProvider fontProvider
    • fontInfoByName

      private Map<String,FontInfo> fontInfoByName
    • lastResortFont

      private final TrueTypeFont lastResortFont
    • substitutes

      private final Map<String,List<String>> substitutes
      Map of PostScript name substitutes, in priority order.
  • Constructor Details

    • FontMapperImpl

      FontMapperImpl()
  • Method Details

    • setProvider

      public void setProvider(FontProvider fontProvider)
      Sets the font service provider.
    • getProvider

      public FontProvider getProvider()
      Returns the font service provider. Defaults to using FileSystemFontProvider.
    • getFontCache

      public FontCache getFontCache()
      Returns the font cache associated with this FontMapper. This method is needed by FontProvider subclasses.
    • createFontInfoByName

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

      private Set<String> getPostScriptNames(String postScriptName)
      Gets alternative names, as seen in some PDFs, e.g. PDFBOX-142.
    • copySubstitutes

      private List<String> copySubstitutes(String postScriptName)
      Copies a list of font substitutes, adding the original font at the start of the list.
    • addSubstitute

      public void addSubstitute(String match, String replace)
      Adds a top-priority substitute for the given font.
      Parameters:
      match - PostScript name of the font to match
      replace - PostScript name of the font to use as a replacement
    • getSubstitutes

      private List<String> getSubstitutes(String postScriptName)
      Returns the substitutes for a given font.
    • getFallbackFontName

      private String getFallbackFontName(PDFontDescriptor fontDescriptor)
      Attempts to find a good fallback based on the font descriptor.
    • getTrueTypeFont

      public FontMapping<TrueTypeFont> getTrueTypeFont(String baseFont, PDFontDescriptor fontDescriptor)
      Finds a TrueType font with the given PostScript name, or a suitable substitute, or null.
      Specified by:
      getTrueTypeFont in interface FontMapper
      Parameters:
      fontDescriptor - FontDescriptor
    • getFontBoxFont

      public FontMapping<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:
      getFontBoxFont in interface FontMapper
      Parameters:
      fontDescriptor - the FontDescriptor of the font to find
    • findFontBoxFont

      private FontBoxFont findFontBoxFont(String postScriptName)
      Finds a font with the given PostScript name, or a suitable substitute, or null.
      Parameters:
      postScriptName - PostScript font name
    • findFont

      private FontBoxFont findFont(FontFormat format, String postScriptName)
      Finds a font with the given PostScript name, or a suitable substitute, or null.
      Parameters:
      postScriptName - PostScript font name
    • getFont

      private FontInfo getFont(FontFormat format, String postScriptName)
      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:
      getCIDFont in interface FontMapper
      Parameters:
      fontDescriptor - FontDescriptor
      cidSystemInfo - 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

      private boolean probablyBarcodeFont(PDFontDescriptor fontDescriptor)
    • isCharSetMatch

      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.
    • printMatches

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