Class Type1Font

java.lang.Object
com.itextpdf.io.font.FontProgram
com.itextpdf.io.font.Type1Font

public class Type1Font extends FontProgram
Font program parsed from Adobe Type 1 AFM/PFM metrics and optional PFB outline data.
  • Constructor Details

    • Type1Font

      protected Type1Font()
      Creates an empty Type 1 font program.
    • Type1Font

      protected Type1Font (String metricsPath, String binaryPath, byte[] afm, byte[] pfb) throws IOException
      Creates a Type 1 font program from AFM/PFM metrics and optional PFB data without remapping codes.
      Parameters:
      metricsPath - metrics file path, built-in font name, or null when afm is supplied
      binaryPath - PFB path, or null when pfb is supplied
      afm - AFM/PFM bytes, or null when metricsPath is supplied
      pfb - PFB bytes, or null when binaryPath is supplied
      Throws:
      IOException - if supplied font data cannot be read or parsed
    • Type1Font

      protected Type1Font (String metricsPath, String binaryPath, byte[] afm, byte[] pfb, FontEncoding fontEncoding) throws IOException
      Creates a Type1Font by parsing the AFM/PFM metrics and, optionally, the PFB binary data, then applying an explicit encoding to the resulting glyph maps.

      The font source may be supplied either as file-system paths or as raw byte arrays; one pair (metricsPath/binaryPath or afm/pfb) must be non-null. After parsing, if fontEncoding is non-null, initializeGlyphs(FontEncoding) is called to remap character codes according to that encoding.

      Parameters:
      metricsPath - path to the AFM or PFM metrics file, or a built-in standard font name, or null if afm bytes are provided instead
      binaryPath - path to the PFB binary file, or null if pfb bytes are provided or if the font is a built-in standard font
      afm - byte contents of the AFM or PFM metrics file, or null if metricsPath is provided instead
      pfb - byte contents of the PFB binary file, or null if binaryPath is provided or if the font is a built-in standard font
      fontEncoding - the encoding used to remap character codes to Unicode values after the font has been parsed; may be null to skip glyph remapping
      Throws:
      IOException - if an I/O error occurs while reading the metrics or binary file, or if the AFM/PFM data is malformed
    • Type1Font

      protected Type1Font (String baseFont)
      Creates a lightweight Type 1 font program for a named base font without parsing metrics.
      Parameters:
      baseFont - PostScript base-font name
  • Method Details

    • createStandardFont

      protected static Type1Font createStandardFont (String name) throws IOException
      Creates a font program for one of the PDF standard Type 1 fonts.
      Parameters:
      name - standard font name
      Returns:
      initialized standard-font program
      Throws:
      IOException - if font cannot be read or parsed
    • initializeGlyphs

      @Deprecated public void initializeGlyphs (FontEncoding fontEncoding)
      Deprecated.
      to make private
      Fills missing character codes in codeToGlyph map.
      Parameters:
      fontEncoding - to be used to map unicode values to character codes.
    • isBuiltInFont

      public boolean isBuiltInFont()
      Checks whether this program represents a built-in standard font.
      Returns:
      true when no external font program is required
    • getPdfFontFlags

      public int getPdfFontFlags()
      Description copied from class: FontProgram
      Computes the PDF font descriptor flags for this program.
      Specified by:
      getPdfFontFlags in class FontProgram
      Returns:
      bit set defined by the PDF font descriptor specification
    • getCharacterSet

      public String getCharacterSet()
      Gets the AFM CharacterSet declaration.
      Returns:
      character set description, or null when absent
    • hasKernPairs

      public boolean hasKernPairs()
      Checks if the font has any kerning pairs.
      Overrides:
      hasKernPairs in class FontProgram
      Returns:
      true if the font has any kerning pairs.
    • getKerning

      public int getKerning (Glyph first, Glyph second)
      Description copied from class: FontProgram
      Gets the kerning between two glyphs.
      Specified by:
      getKerning in class FontProgram
      Parameters:
      first - the first glyph
      second - the second glyph
      Returns:
      the kerning to be applied
    • setKerning

      public boolean setKerning (int first, int second, int kern)
      Sets the kerning between two Unicode chars.
      Parameters:
      first - the first unicode char.
      second - the second unicode char.
      kern - the kerning to apply in normalized 1000 units.
      Returns:
      true if the kerning was applied, false otherwise.
    • getGlyph

      public Glyph getGlyph (String name)
      Find glyph by glyph name.
      Parameters:
      name - Glyph name
      Returns:
      Glyph instance if found, otherwise null.
    • getFontStreamBytes

      public byte[] getFontStreamBytes()
    • getFontStreamLengths

      public int[] getFontStreamLengths()
    • isBuiltWith

      public boolean isBuiltWith (String fontProgram)
      Description copied from class: FontProgram
      Checks whether the FontProgram was built with corresponding fontName. Default value is false unless overridden.
      Overrides:
      isBuiltWith in class FontProgram
      Parameters:
      fontProgram - a font name or path to a font program
      Returns:
      true, if the FontProgram was built with the fontProgram. Otherwise false.
    • process

      protected void process() throws IOException
      Parses AFM/PFM metrics, character metrics, and kerning pairs into this font program.
      Throws:
      IOException - if mandatory sections are missing or the metrics source cannot be read