Package com.itextpdf.io.font
Class FontProgramFactory
java.lang.Object
com.itextpdf.io.font.FontProgramFactory
Provides methods for creating various types of fonts.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static boolean
This is the default value of the cached variable.private static FontRegisterProvider
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Clears registered font cachestatic void
static FontProgram
Creates a new standard Helvetica font program file.static FontProgram
createFont
(byte[] fontProgram) Creates a new font program.static FontProgram
createFont
(byte[] fontProgram, boolean cached) Creates a new font program.static FontProgram
createFont
(byte[] ttc, int ttcIndex, boolean cached) Creates a new TrueType font program from ttc (TrueType Collection) file bytes.static FontProgram
createFont
(String fontProgram) Creates a new font program.static FontProgram
createFont
(String fontProgram, boolean cached) Creates a new font program.static FontProgram
createFont
(String ttc, int ttcIndex, boolean cached) Creates a new TrueType font program from ttc (TrueType Collection) file.static FontProgram
createFont
(String fontProgram, String cmap, boolean cached) Creates a new font program.private static FontProgram
createFont
(String name, String cmap, byte[] fontProgram, boolean cached) private static FontCacheKey
createFontCacheKey
(String name, byte[] fontProgram) static FontProgram
createRegisteredFont
(String fontName) Creates a FontProgram from the font file that has been previously registered.static FontProgram
createRegisteredFont
(String fontName, int style) Creates a FontProgram from the font file that has been previously registered.static FontProgram
createRegisteredFont
(String fontName, int style, boolean cached) Creates a FontProgram from the font file that has been previously registered.static FontProgram
createType1Font
(byte[] afm, byte[] pfb) Creates a new Type 1 font by the byte contents of the corresponding AFM/PFM and PFB filesstatic FontProgram
createType1Font
(byte[] afm, byte[] pfb, boolean cached) Creates a new Type 1 font by the byte contents of the corresponding AFM/PFM and PFB filesstatic FontProgram
createType1Font
(String metricsPath, String binaryPath) Creates a new Type 1 font by the corresponding AFM/PFM and PFB filesstatic FontProgram
createType1Font
(String metricsPath, String binaryPath, boolean cached) Creates a new Type 1 font by the corresponding AFM/PFM and PFB filesprivate static FontProgram
createType1Font
(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 boolean
isRegisteredFont
(String fontName) Checks if a certain font is registered.(package private) static byte[]
readFontBytesFromPath
(String path) static void
registerFont
(String path) Registers a .ttf, .otf, .afm, .pfm, or a .ttc font file.static void
registerFont
(String path, String alias) Register a font file and use an alias for the font contained in it.static int
Register all the fonts in a directory.static void
registerFontFamily
(String familyName, String fullName, String path) Register a font by giving explicitly the font family and name.static int
Register 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
FontProgram
object 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. 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 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. This font program can be one of the 14 built in fonts, a Type 1 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 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
FontProgram
instance - 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 createdFontProgram
or not- Returns:
- created
FontProgram
instance - 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
FontProgram
instance - 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 createdFontProgram
or not- Returns:
- created
FontProgram
instance - 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
FontProgram
instance. 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
FontProgram
instance. 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.UNDEFINED
cached
- 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
Register a font by giving explicitly the font family and name.- Parameters:
familyName
- the font familyfullName
- the font namepath
- the font path
-
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
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
Register all the fonts in a directory.- 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
Gets a set of registered font names.- Returns:
- a set of registered fonts
-
getRegisteredFontFamilies
Gets a set of registered font names.- Returns:
- a set of registered font families
-
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
-