Class FontProgramFactory

java.lang.Object
com.itextpdf.io.font.FontProgramFactory

public final class FontProgramFactory extends Object
Provides methods for creating various types of fonts.
  • Method Details

    • createFont

      public static FontProgram createFont() throws IOException
      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

      public static FontProgram createFont (String fontProgram) 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 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

      public static FontProgram createFont (String fontProgram, 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 file
      cached - 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 file
      cmap - CMap to convert Unicode value to CID if CJK font is used
      cached - 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

      public static FontProgram createFont (byte[] fontProgram) 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 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

      public static FontProgram createFont (byte[] fontProgram, boolean cached) throws IOException
      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 program
      cached - 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
    • createType1Font

      public static FontProgram createType1Font (byte[] afm, byte[] pfb) 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 file
      pfb - 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 file
      pfb - the contents of the PFB file
      cached - specifies whether to cache the created FontProgram or not
      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) 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 file
      binaryPath - 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 file
      binaryPath - path to the contents of the PFB file
      cached - specifies whether to cache the created FontProgram or not
      Returns:
      created FontProgram instance
      Throws:
      IOException - exception is thrown in case an I/O error occurs when reading the file
    • createFont

      public static FontProgram createFont (String ttc, int ttcIndex, boolean cached) throws 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 read
      cached - 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

      public static FontProgram createFont (byte[] ttc, int ttcIndex, boolean cached) throws 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 read
      cached - 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 otherwise
      style - the style of the font to look for. Possible values are listed in FontStyles. See FontStyles.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

      public static FontProgram createRegisteredFont (String fontName, int style) 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 otherwise
      style - the style of the font to look for. Possible values are listed in FontStyles. See FontStyles.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

      public static FontProgram createRegisteredFont (String fontName) 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 otherwise
      Returns:
      created FontProgram
      Throws:
      IOException - exception is thrown in case an I/O error occurs when reading the file2
    • registerFontFamily

      public static void registerFontFamily (String familyName, String fullName, String path)
      Register a font by giving explicitly the font family and name.
      Parameters:
      familyName - the font family
      fullName - the font name
      path - the font path
    • registerFont

      public static void registerFont (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 (String path, String alias)
      Register a font file and use an alias for the font contained in it.
      Parameters:
      path - the path to a font file
      alias - the alias you want to use for the font
    • registerFontDirectory

      public static int registerFontDirectory (String dir)
      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

      public static Set<String> getRegisteredFonts()
      Gets a set of registered font names.
      Returns:
      a set of registered fonts
    • getRegisteredFontFamilies

      public static Set<String> getRegisteredFontFamilies()
      Gets a set of registered font names.
      Returns:
      a set of registered font families
    • isRegisteredFont

      public static boolean isRegisteredFont (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
    • clearRegisteredFonts

      public static void clearRegisteredFonts()
    • clearRegisteredFontFamilies

      public static void clearRegisteredFontFamilies()
      Clears registered font cache