Package com.itextpdf.io.font
Class FontProgramFactory
- java.lang.Object
-
- com.itextpdf.io.font.FontProgramFactory
-
public final class FontProgramFactory extends java.lang.ObjectProvides methods for creating various types of fonts.
-
-
Field Summary
Fields Modifier and Type Field Description private static booleanDEFAULT_CACHEDThis is the default value of the cached variable.private static FontRegisterProviderfontRegisterProvider
-
Constructor Summary
Constructors Modifier Constructor Description privateFontProgramFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclearRegisteredFontFamilies()Clears registered font cachestatic voidclearRegisteredFonts()static FontProgramcreateFont()Creates 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(java.lang.String fontProgram)Creates a new font program.static FontProgramcreateFont(java.lang.String fontProgram, boolean cached)Creates a new font program.static FontProgramcreateFont(java.lang.String ttc, int ttcIndex, boolean cached)Creates a new TrueType font program from ttc (TrueType Collection) file.static FontProgramcreateFont(java.lang.String fontProgram, java.lang.String cmap, boolean cached)Creates a new font program.private static FontProgramcreateFont(java.lang.String name, java.lang.String cmap, byte[] fontProgram, boolean cached)private static FontCacheKeycreateFontCacheKey(java.lang.String name, byte[] fontProgram)static FontProgramcreateRegisteredFont(java.lang.String fontName)Creates a FontProgram from the font file that has been previously registered.static FontProgramcreateRegisteredFont(java.lang.String fontName, int style)Creates a FontProgram from the font file that has been previously registered.static FontProgramcreateRegisteredFont(java.lang.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(java.lang.String metricsPath, java.lang.String binaryPath)Creates a new Type 1 font by the corresponding AFM/PFM and PFB filesstatic FontProgramcreateType1Font(java.lang.String metricsPath, java.lang.String binaryPath, boolean cached)Creates a new Type 1 font by the corresponding AFM/PFM and PFB filesprivate static FontProgramcreateType1Font(java.lang.String metricsPath, java.lang.String binaryPath, byte[] afm, byte[] pfb, boolean cached)static java.util.Set<java.lang.String>getRegisteredFontFamilies()Gets a set of registered font names.static java.util.Set<java.lang.String>getRegisteredFonts()Gets a set of registered font names.static booleanisRegisteredFont(java.lang.String fontName)Checks if a certain font is registered.(package private) static byte[]readFontBytesFromPath(java.lang.String path)static voidregisterFont(java.lang.String path)Registers a .ttf, .otf, .afm, .pfm, or a .ttc font file.static voidregisterFont(java.lang.String path, java.lang.String alias)Register a font file and use an alias for the font contained in it.static intregisterFontDirectory(java.lang.String dir)Register all the fonts in a directory.static intregisterFontDirectoryRecursively(java.lang.String dir)Register all the fonts in a directory recursively.static voidregisterFontFamily(java.lang.String familyName, java.lang.String fullName, java.lang.String path)Register a font by giving explicitly the font family and name.static intregisterSystemFontDirectories()Register fonts in some probable directories.
-
-
-
Field Detail
-
DEFAULT_CACHED
private static boolean DEFAULT_CACHED
This is the default value of the cached variable.
-
fontRegisterProvider
private static FontRegisterProvider fontRegisterProvider
-
-
Method Detail
-
createFont
public static FontProgram createFont() throws java.io.IOException
Creates a new standard Helvetica font program file.- Returns:
- a
FontProgramobject with Helvetica font description - Throws:
java.io.IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
public static FontProgram createFont(java.lang.String fontProgram) throws java.io.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 file- Returns:
- returns a new
FontProgram. This font program may come from the cache - Throws:
java.io.IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
public static FontProgram createFont(java.lang.String fontProgram, boolean cached) throws java.io.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 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:
java.io.IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
public static FontProgram createFont(java.lang.String fontProgram, java.lang.String cmap, boolean cached) throws java.io.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:
java.io.IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
public static FontProgram createFont(byte[] fontProgram) throws java.io.IOException
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:
java.io.IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
public static FontProgram createFont(byte[] fontProgram, boolean cached) throws java.io.IOException
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:
java.io.IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
private static FontProgram createFont(java.lang.String name, java.lang.String cmap, byte[] fontProgram, boolean cached) throws java.io.IOException
- Throws:
java.io.IOException
-
createType1Font
public static FontProgram createType1Font(byte[] afm, byte[] pfb) throws java.io.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 file- Returns:
- created
FontPrograminstance - Throws:
java.io.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 java.io.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:
java.io.IOException- exception is thrown in case an I/O error occurs when reading the file
-
createType1Font
public static FontProgram createType1Font(java.lang.String metricsPath, java.lang.String binaryPath) throws java.io.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 file- Returns:
- created
FontPrograminstance - Throws:
java.io.IOException- exception is thrown in case an I/O error occurs when reading the file
-
createType1Font
public static FontProgram createType1Font(java.lang.String metricsPath, java.lang.String binaryPath, boolean cached) throws java.io.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:
java.io.IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
public static FontProgram createFont(java.lang.String ttc, int ttcIndex, boolean cached) throws java.io.IOException
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:
java.io.IOException- exception is thrown in case an I/O error occurs when reading the file
-
createFont
public static FontProgram createFont(byte[] ttc, int ttcIndex, boolean cached) throws java.io.IOException
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:
java.io.IOException- exception is thrown in case an I/O error occurs when reading the file
-
createRegisteredFont
public static FontProgram createRegisteredFont(java.lang.String fontName, int style, boolean cached) throws java.io.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:
java.io.IOException- exception is thrown in case an I/O error occurs when reading the file
-
createRegisteredFont
public static FontProgram createRegisteredFont(java.lang.String fontName, int style) throws java.io.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.UNDEFINED- Returns:
- created
FontProgram - Throws:
java.io.IOException- exception is thrown in case an I/O error occurs when reading the file
-
createRegisteredFont
public static FontProgram createRegisteredFont(java.lang.String fontName) throws java.io.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 otherwise- Returns:
- created
FontProgram - Throws:
java.io.IOException- exception is thrown in case an I/O error occurs when reading the file2
-
registerFontFamily
public static void registerFontFamily(java.lang.String familyName, java.lang.String fullName, java.lang.String path)Register a font by giving explicitly the font family and name.- Parameters:
familyName- the font familyfullName- the font namepath- the font path
-
registerFont
public static void registerFont(java.lang.String path)
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
public static void registerFont(java.lang.String path, java.lang.String alias)Register a font file and use an alias for the font contained in it.- Parameters:
path- the path to a font filealias- the alias you want to use for the font
-
registerFontDirectory
public static int registerFontDirectory(java.lang.String dir)
Register all the fonts in a directory.- Parameters:
dir- the directory- Returns:
- the number of fonts registered
-
registerFontDirectoryRecursively
public static int registerFontDirectoryRecursively(java.lang.String dir)
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
public static java.util.Set<java.lang.String> getRegisteredFonts()
Gets a set of registered font names.- Returns:
- a set of registered fonts
-
getRegisteredFontFamilies
public static java.util.Set<java.lang.String> getRegisteredFontFamilies()
Gets a set of registered font names.- Returns:
- a set of registered font families
-
isRegisteredFont
public static boolean isRegisteredFont(java.lang.String fontName)
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(java.lang.String metricsPath, java.lang.String binaryPath, byte[] afm, byte[] pfb, boolean cached) throws java.io.IOException
- Throws:
java.io.IOException
-
createFontCacheKey
private static FontCacheKey createFontCacheKey(java.lang.String name, byte[] fontProgram)
-
clearRegisteredFonts
public static void clearRegisteredFonts()
-
clearRegisteredFontFamilies
public static void clearRegisteredFontFamilies()
Clears registered font cache
-
readFontBytesFromPath
static byte[] readFontBytesFromPath(java.lang.String path) throws java.io.IOException- Throws:
java.io.IOException
-
-