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

pack-priv final Class FileSystemFontProvider

extends FontProvider
Class Inheritance
Imports
java.io.BufferedReader, .BufferedWriter, .File, .FileInputStream, .FileReader, .FileWriter, .IOException, .InputStream, java.net.URI, java.nio.charset.StandardCharsets, java.nio.file.Files, java.security.AccessControlException, java.util.ArrayList, .HashSet, .List, .Set, java.util.zip.CRC32, org.apache.commons.logging.Log, .LogFactory, org.apache.fontbox.FontBoxFont, org.apache.fontbox.ttf.FontHeaders, .OS2WindowsMetricsTable, .OTFParser, .OpenTypeFont, .TTFParser, .TrueTypeCollection, .TrueTypeFont, org.apache.fontbox.type1.Type1Font, org.apache.fontbox.util.autodetect.FontFileFinder, org.apache.pdfbox.io.IOUtils, .RandomAccessReadBufferedFile

A FontProvider which searches for fonts on the local filesystem.
Author
John Hewson

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final FontCache
private static final String
private final List<FileSystemFontProvider.FSFontInfo>
private static final Log
private static final boolean
SKIP_CHECKSUMS

This option changes publicly visible behaviour: ".pdfbox.cache" file will have hash="-" for all files.

Constructor Summary

AccessConstructor and Description
pack-priv
FileSystemFontProvider(FontCache cache)

Constructor.

Method Summary

Modifier and TypeMethod and Description
private void
addTrueTypeCollection(final File ttcFile)

Adds a TTC or OTC to the file cache.

private void
addTrueTypeFont(File ttfFile)

Adds an OTF or TTF font to the file cache.

private void
addTrueTypeFontImpl(FontHeaders fontHeaders, File file, String hash)

Adds an OTF or TTF font to the file cache.

private void
addType1Font(File pfbFile)

Adds a Type 1 font to the file cache.

private static String
private FileSystemFontProvider.FSFontInfo
createFSIgnored(File file, FontFormat format, String postScriptName)

private File
public List<? extends FontInfo>
getFontInfo()

Implements abstract org.apache.pdfbox.pdmodel.font.FontProvider.getFontInfo.

Returns a list of information about fonts on the system.

private static boolean
private List<FileSystemFontProvider.FSFontInfo>
loadDiskCache(List<File> files)

Loads the font metadata cache from disk.

private void
saveDiskCache()

Saves the font metadata cache to disk.

private void
public String
toDebugString()

Implements abstract org.apache.pdfbox.pdmodel.font.FontProvider.toDebugString.

Returns a string containing debugging information.

private void

Field Detail

cacheback to summary
private final FontCache cache
CHECKSUM_PLACEHOLDERback to summary
private static final String CHECKSUM_PLACEHOLDER
fontInfoListback to summary
private final List<FileSystemFontProvider.FSFontInfo> fontInfoList
LOGback to summary
private static final Log LOG
SKIP_CHECKSUMSback to summary
private static final boolean SKIP_CHECKSUMS

This option changes publicly visible behaviour: ".pdfbox.cache" file will have hash="-" for all files. After implementing FontHeaders, parsing font headers is faster than checksumming anyway.

Constructor Detail

FileSystemFontProviderback to summary
pack-priv FileSystemFontProvider(FontCache cache)

Constructor.

Method Detail

addTrueTypeCollectionback to summary
private void addTrueTypeCollection(final File ttcFile)

Adds a TTC or OTC to the file cache. To reduce memory, the parsed font is not cached.

addTrueTypeFontback to summary
private void addTrueTypeFont(File ttfFile)

Adds an OTF or TTF font to the file cache. To reduce memory, the parsed font is not cached.

addTrueTypeFontImplback to summary
private void addTrueTypeFontImpl(FontHeaders fontHeaders, File file, String hash)

Adds an OTF or TTF font to the file cache. To reduce memory, the parsed font is not cached.

addType1Fontback to summary
private void addType1Font(File pfbFile)

Adds a Type 1 font to the file cache. To reduce memory, the parsed font is not cached.

computeHashback to summary
private static String computeHash(InputStream is) throws IOException
createFSIgnoredback to summary
private FileSystemFontProvider.FSFontInfo createFSIgnored(File file, FontFormat format, String postScriptName)
getDiskCacheFileback to summary
private File getDiskCacheFile()
getFontInfoback to summary
public List<? extends FontInfo> getFontInfo()

Implements abstract org.apache.pdfbox.pdmodel.font.FontProvider.getFontInfo.

Doc from org.apache.pdfbox.pdmodel.font.FontProvider.getFontInfo.

Returns a list of information about fonts on the system.

Returns:List<? extends FontInfo>

a list of FntInfo instances for all fonts on the system

Annotations
@Override
isBadPathback to summary
private static boolean isBadPath(String path)
loadDiskCacheback to summary
private List<FileSystemFontProvider.FSFontInfo> loadDiskCache(List<File> files)

Loads the font metadata cache from disk.

saveDiskCacheback to summary
private void saveDiskCache()

Saves the font metadata cache to disk.

scanFontsback to summary
private void scanFonts(List<File> files)
toDebugStringback to summary
public String toDebugString()

Implements abstract org.apache.pdfbox.pdmodel.font.FontProvider.toDebugString.

Doc from org.apache.pdfbox.pdmodel.font.FontProvider.toDebugString.

Returns a string containing debugging information. This will be written to the log if no suitable fonts are found and no fallback fonts are available. May be null.

Returns:String

string with debug information or null

Annotations
@Override
writeFontInfoback to summary
private void writeFontInfo(BufferedWriter writer, FileSystemFontProvider.FSFontInfo fontInfo) throws IOException
org.apache.pdfbox.pdmodel.font back to summary

private Class FileSystemFontProvider.FSFontInfo

extends FontInfo
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final CIDSystemInfo
private final File
private final FontFormat
private final String
private final long
private final int
private final PDPanoseClassification
private final FileSystemFontProvider
private final String
private final int
private final int
private final int
private final int

Constructor Summary

AccessConstructor and Description
private
FSFontInfo(File file, FontFormat format, String postScriptName, CIDSystemInfo cidSystemInfo, int usWeightClass, int sFamilyClass, int ulCodePageRange1, int ulCodePageRange2, int macStyle, byte[] panose, FileSystemFontProvider parent, String hash, long lastModified)

Method Summary

Modifier and TypeMethod and Description
public CIDSystemInfo
getCIDSystemInfo()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getCIDSystemInfo.

Returns the CIDSystemInfo associated with the font, if present.

public int
getCodePageRange1()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getCodePageRange1.

Returns the ulCodePageRange1 field of the "OS/2" table, or 0.

public int
getCodePageRange2()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getCodePageRange2.

Returns the ulCodePageRange2 field of the "OS/2" table, or 0.

public int
getFamilyClass()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getFamilyClass.

Returns the sFamilyClass field of the "OS/2" table, or -1.

public synchronized FontBoxFont
getFont()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getFont.

Returns a new FontBox font instance for the font.

public FontFormat
getFormat()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getFormat.

Returns the font's format.

public int
getMacStyle()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getMacStyle.

Returns the macStyle field of the "head" table, or -1.

private OpenTypeFont
getOTFFont(String postScriptName, File file)

public PDPanoseClassification
getPanose()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getPanose.

Returns the Panose classification of the font, if any.

public String
getPostScriptName()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getPostScriptName.

Returns the PostScript name of the font.

private TrueTypeFont
getTrueTypeFont(String postScriptName, File file)

private Type1Font
getType1Font(String postScriptName, File file)

public int
getWeightClass()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getWeightClass.

Returns the usWeightClass field of the "OS/2" table, or -1.

private TrueTypeFont
readTrueTypeFont(String postScriptName, File file)

public String
toString()

Overrides org.apache.pdfbox.pdmodel.font.FontInfo.toString.

Returns a string representation of the object.

Inherited from org.apache.pdfbox.pdmodel.font.FontInfo:
getCodePageRangegetWeightClassAsPanose

Field Detail

cidSystemInfoback to summary
private final CIDSystemInfo cidSystemInfo
fileback to summary
private final File file
formatback to summary
private final FontFormat format
hashback to summary
private final String hash
lastModifiedback to summary
private final long lastModified
macStyleback to summary
private final int macStyle
panoseback to summary
private final PDPanoseClassification panose
parentback to summary
private final FileSystemFontProvider parent
postScriptNameback to summary
private final String postScriptName
sFamilyClassback to summary
private final int sFamilyClass
ulCodePageRange1back to summary
private final int ulCodePageRange1
ulCodePageRange2back to summary
private final int ulCodePageRange2
usWeightClassback to summary
private final int usWeightClass

Constructor Detail

FSFontInfoback to summary
private FSFontInfo(File file, FontFormat format, String postScriptName, CIDSystemInfo cidSystemInfo, int usWeightClass, int sFamilyClass, int ulCodePageRange1, int ulCodePageRange2, int macStyle, byte[] panose, FileSystemFontProvider parent, String hash, long lastModified)

Method Detail

getCIDSystemInfoback to summary
public CIDSystemInfo getCIDSystemInfo()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getCIDSystemInfo.

Doc from org.apache.pdfbox.pdmodel.font.FontInfo.getCIDSystemInfo.

Returns the CIDSystemInfo associated with the font, if present.

Returns:CIDSystemInfo

the CIDSystemInof of the font if any

Annotations
@Override
getCodePageRange1back to summary
public int getCodePageRange1()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getCodePageRange1.

Doc from org.apache.pdfbox.pdmodel.font.FontInfo.getCodePageRange1.

Returns the ulCodePageRange1 field of the "OS/2" table, or 0.

Returns:int

the CodePageRange1 of the font if present

Annotations
@Override
getCodePageRange2back to summary
public int getCodePageRange2()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getCodePageRange2.

Doc from org.apache.pdfbox.pdmodel.font.FontInfo.getCodePageRange2.

Returns the ulCodePageRange2 field of the "OS/2" table, or 0.

Returns:int

the CodePageRange2 of the font if present

Annotations
@Override
getFamilyClassback to summary
public int getFamilyClass()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getFamilyClass.

Doc from org.apache.pdfbox.pdmodel.font.FontInfo.getFamilyClass.

Returns the sFamilyClass field of the "OS/2" table, or -1.

Returns:int

the FamilyClass of the font

Annotations
@Override
getFontback to summary
public synchronized FontBoxFont getFont()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getFont.

Doc from org.apache.pdfbox.pdmodel.font.FontInfo.getFont.

Returns a new FontBox font instance for the font. Implementors of this method must not cache the return value of this method unless doing so via the current FontCache.

The method returns null if there is there was an error opening the font.

Returns:FontBoxFont

a new FontBox instance of the font

Annotations
@Override
getFormatback to summary
public FontFormat getFormat()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getFormat.

Doc from org.apache.pdfbox.pdmodel.font.FontInfo.getFormat.

Returns the font's format.

Returns:FontFormat

the format of the font

Annotations
@Override
getMacStyleback to summary
public int getMacStyle()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getMacStyle.

Doc from org.apache.pdfbox.pdmodel.font.FontInfo.getMacStyle.

Returns the macStyle field of the "head" table, or -1.

Returns:int

the MacStyle of the font

Annotations
@Override
getOTFFontback to summary
private OpenTypeFont getOTFFont(String postScriptName, File file)
getPanoseback to summary
public PDPanoseClassification getPanose()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getPanose.

Doc from org.apache.pdfbox.pdmodel.font.FontInfo.getPanose.

Returns the Panose classification of the font, if any.

Returns:PDPanoseClassification

the PanoseClassification of the font

Annotations
@Override
getPostScriptNameback to summary
public String getPostScriptName()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getPostScriptName.

Doc from org.apache.pdfbox.pdmodel.font.FontInfo.getPostScriptName.

Returns the PostScript name of the font.

Returns:String

the PostScript name of the font

Annotations
@Override
getTrueTypeFontback to summary
private TrueTypeFont getTrueTypeFont(String postScriptName, File file)
getType1Fontback to summary
private Type1Font getType1Font(String postScriptName, File file)
getWeightClassback to summary
public int getWeightClass()

Implements abstract org.apache.pdfbox.pdmodel.font.FontInfo.getWeightClass.

Doc from org.apache.pdfbox.pdmodel.font.FontInfo.getWeightClass.

Returns the usWeightClass field of the "OS/2" table, or -1.

Returns:int

the WeightClass of the font

Annotations
@Override
readTrueTypeFontback to summary
private TrueTypeFont readTrueTypeFont(String postScriptName, File file) throws IOException
toStringback to summary
public String toString()

Overrides org.apache.pdfbox.pdmodel.font.FontInfo.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override