Class FontProgramFactory
java.lang.Object
com.itextpdf.io.font.FontProgramFactory
Provides methods for creating various types of fonts.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static booleanThis is the default value of the cached variable.private static FontRegisterProvider -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears registered font cachestatic voidstatic FontProgramCreates a new standard Helvetica font program file.static FontProgramcreateFont(byte[] fontProgram) Creates a new font program.static FontProgramcreateFont(byte[] fontProgram, boolean cached) Creates a new font program.static FontProgramcreateFont(byte[] ttc, int ttcIndex, boolean cached) Creates a new TrueType font program from ttc (TrueType Collection) file bytes.static FontProgramcreateFont(String fontProgram) Creates a new font program.static FontProgramcreateFont(String fontProgram, boolean cached) Creates a new font program.static FontProgramcreateFont(String ttc, int ttcIndex, boolean cached) Creates a new TrueType font program from ttc (TrueType Collection) file.static FontProgramcreateFont(String fontProgram, String cmap, boolean cached) Creates a new font program.private static FontProgramcreateFont(String name, String cmap, byte[] fontProgram, boolean cached) private static FontCacheKeycreateFontCacheKey(String name, byte[] fontProgram) static FontProgramcreateRegisteredFont(String fontName) Creates a FontProgram from the font file that has been previously registered.static FontProgramcreateRegisteredFont(String fontName, int style) Creates a FontProgram from the font file that has been previously registered.static FontProgramcreateRegisteredFont(String fontName, int style, boolean cached) Creates a FontProgram from the font file that has been previously registered.static FontProgramcreateType1Font(byte[] afm, byte[] pfb) Creates a new Type 1 font by the byte contents of the corresponding AFM/PFM and PFB filesstatic FontProgramcreateType1Font(byte[] afm, byte[] pfb, boolean cached) Creates a new Type 1 font by the byte contents of the corresponding AFM/PFM and PFB filesstatic FontProgramcreateType1Font(String metricsPath, String binaryPath) Creates a new Type 1 font by the corresponding AFM/PFM and PFB filesstatic FontProgramcreateType1Font(String metricsPath, String binaryPath, boolean cached) Creates a new Type 1 font by the corresponding AFM/PFM and PFB filesprivate static FontProgramcreateType1Font(String metricsPath, String binaryPath, byte[] afm, byte[] pfb, boolean cached) Gets a set of registered font names.Gets a set of registered font names.static booleanisRegisteredFont(String fontName) Checks if a certain font is registered.(package private) static byte[]readFontBytesFromPath(String path) static voidregisterFont(String path) Registers a .ttf, .otf, .afm, .pfm, or a .ttc font file.static voidregisterFont(String path, String alias) Register a font file and use an alias for the font contained in it.static intRegister all the fonts in a directory.static intRegister all the fonts in a directory recursively.static voidregisterFontFamily(String familyName, String fullName, String path) Register a font by giving explicitly the font family and name.static intRegister fonts in some probable directories.
-
Field Details
-
DEFAULT_CACHED
private static boolean DEFAULT_CACHEDThis is the default value of the cached variable. -
fontRegisterProvider
-
-
Constructor Details
-
FontProgramFactory
private FontProgramFactory()
-
-
Method Details
-
createFont
Creates a new standard Helvetica font program file.- Returns:
- a
FontProgramobject with Helvetica font description - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
Creates a new font program. This font program can be one of the 14 built in fonts, a Type1 font referred to by an AFM or PFM file, a TrueType font or a CJK font from the Adobe Asian Font Pack. Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1". This would get the second font (indexes start at 0), in this case "MS PGothic".The fonts are cached and if they already exist they are extracted from the cache, not parsed again.
- Parameters:
fontProgram- the name of the font or its location on file- Returns:
- returns a new
FontProgram. This font program may come from the cache - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
Creates a new font program. This font program can be one of the 14 built in fonts, a Type1 font referred to by an AFM or PFM file, a TrueType font or a CJK font from the Adobe Asian Font Pack. Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1". This would get the second font (indexes start at 0), in this case "MS PGothic".The fonts are cached and if they already exist they are extracted from the cache, not parsed again.
- Parameters:
fontProgram- the name of the font or its location on filecached- whether to to cache this font program after it has been loaded- Returns:
- returns a new
FontProgram. This font program may come from the cache - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
public static FontProgram createFont(String fontProgram, String cmap, boolean cached) throws IOException Creates a new font program. This font program can be one of the 14 built in fonts, a Type1 font referred to by an AFM or PFM file, a TrueType font or a CJK font from the Adobe Asian Font Pack. Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1". This would get the second font (indexes start at 0), in this case "MS PGothic".The fonts are cached and if they already exist they are extracted from the cache, not parsed again.
- Parameters:
fontProgram- the name of the font or its location on filecmap- CMap to convert Unicode value to CID if CJK font is usedcached- whether to cache this font program after it has been loaded- Returns:
- returns a new
FontProgram. This font program may come from the cache - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
Creates a new font program. The fonts are cached and if they already exist they are extracted from the cache, not parsed again.- Parameters:
fontProgram- the byte contents of the font program- Returns:
- returns a new
FontProgram. This font program may come from the cache - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
Creates a new font program. The fonts are cached and if they already exist they are extracted from the cache, not parsed again.- Parameters:
fontProgram- the byte contents of the font programcached- whether to to cache this font program- Returns:
- returns a new
FontProgram. This font program may come from the cache - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
private static FontProgram createFont(String name, String cmap, byte[] fontProgram, boolean cached) throws IOException - Throws:
IOException
-
createType1Font
Creates a new Type 1 font by the byte contents of the corresponding AFM/PFM and PFB files- Parameters:
afm- the contents of the AFM or PFM metrics filepfb- the contents of the PFB file- Returns:
- created
FontPrograminstance - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file
-
createType1Font
public static FontProgram createType1Font(byte[] afm, byte[] pfb, boolean cached) throws IOException Creates a new Type 1 font by the byte contents of the corresponding AFM/PFM and PFB files- Parameters:
afm- the contents of the AFM or PFM metrics filepfb- the contents of the PFB filecached- specifies whether to cache the createdFontProgramor not- Returns:
- created
FontPrograminstance - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file
-
createType1Font
Creates a new Type 1 font by the corresponding AFM/PFM and PFB files- Parameters:
metricsPath- path to the AFM or PFM metrics filebinaryPath- path to the contents of the PFB file- Returns:
- created
FontPrograminstance - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file
-
createType1Font
public static FontProgram createType1Font(String metricsPath, String binaryPath, boolean cached) throws IOException Creates a new Type 1 font by the corresponding AFM/PFM and PFB files- Parameters:
metricsPath- path to the AFM or PFM metrics filebinaryPath- path to the contents of the PFB filecached- specifies whether to cache the createdFontProgramor not- Returns:
- created
FontPrograminstance - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
Creates a new TrueType font program from ttc (TrueType Collection) file.- Parameters:
ttc- location of TrueType Collection file (*.ttc)ttcIndex- the index of the font file from the collection to be readcached- true if the font comes from the cache or is added to the cache if new, false if the font is always created new- Returns:
- returns a new
FontPrograminstance. This font may come from the cache but only if cached is true, otherwise it will always be created new - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
Creates a new TrueType font program from ttc (TrueType Collection) file bytes.- Parameters:
ttc- the content of a TrueType Collection file (*.ttc)ttcIndex- the index of the font file from the collection to be readcached- true if the font comes from the cache or is added to the cache if new, false if the font is always created new- Returns:
- returns a new
FontPrograminstance. This font may come from the cache but only if cached is true, otherwise it will always be created new - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file
-
createRegisteredFont
public static FontProgram createRegisteredFont(String fontName, int style, boolean cached) throws IOException Creates a FontProgram from the font file that has been previously registered.- Parameters:
fontName- either a font alias, if the font file has been registered with an alias, or just a font name otherwisestyle- the style of the font to look for. Possible values are listed inFontStyles. SeeFontStyles.BOLD,FontStyles.ITALIC,FontStyles.NORMAL,FontStyles.BOLDITALIC,FontStyles.UNDEFINEDcached- whether to try to get the font program from cache- Returns:
- created
FontProgram - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file
-
createRegisteredFont
Creates a FontProgram from the font file that has been previously registered.- Parameters:
fontName- either a font alias, if the font file has been registered with an alias, or just a font name otherwisestyle- the style of the font to look for. Possible values are listed inFontStyles. SeeFontStyles.BOLD,FontStyles.ITALIC,FontStyles.NORMAL,FontStyles.BOLDITALIC,FontStyles.UNDEFINED- Returns:
- created
FontProgram - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file
-
createRegisteredFont
Creates a FontProgram from the font file that has been previously registered.- Parameters:
fontName- either a font alias, if the font file has been registered with an alias, or just a font name otherwise- Returns:
- created
FontProgram - Throws:
IOException- exception is thrown in case an I/O error occurs when reading the file2
-
registerFontFamily
-
registerFont
Registers a .ttf, .otf, .afm, .pfm, or a .ttc font file. In case if TrueType Collection (.ttc), an additional parameter may be specified defining the index of the font to be registered, e.g. "path/to/font/collection.ttc,0". The index is zero-based.- Parameters:
path- the path to a font file
-
registerFont
-
registerFontDirectory
Register all the fonts in a directory.- Parameters:
dir- the directory- Returns:
- the number of fonts registered
-
registerFontDirectoryRecursively
Register all the fonts in a directory recursively.- Parameters:
dir- the directory- Returns:
- the number of fonts registered
-
registerSystemFontDirectories
public static int registerSystemFontDirectories()Register fonts in some probable directories. It usually works in Windows, Linux and Solaris.- Returns:
- the number of fonts registered
-
getRegisteredFonts
-
getRegisteredFontFamilies
-
isRegisteredFont
Checks if a certain font is registered.- Parameters:
fontName- the name of the font that has to be checked.- Returns:
- true if the font is found
-
createType1Font
private static FontProgram createType1Font(String metricsPath, String binaryPath, byte[] afm, byte[] pfb, boolean cached) throws IOException - Throws:
IOException
-
createFontCacheKey
-
clearRegisteredFonts
public static void clearRegisteredFonts() -
clearRegisteredFontFamilies
public static void clearRegisteredFontFamilies()Clears registered font cache -
readFontBytesFromPath
- Throws:
IOException
-