Class Type1Font

java.lang.Object
com.lowagie.text.pdf.BaseFont
com.lowagie.text.pdf.Type1Font

class Type1Font extends BaseFont
Reads a Type1 font
  • Field Details

    • PFB_TYPES

      private static final int[] PFB_TYPES
      Types of records in a PFB file. ASCII is 1 and BINARY is 2. They have to appear in the PFB file in this sequence.
    • resourceAnchor

      private static FontsResourceAnchor resourceAnchor
    • pfb

      protected byte[] pfb
      The PFB file if the input was made with a byte array.
    • FontName

      private String FontName
      The Postscript font name.
    • FullName

      private String FullName
      The full name of the font.
    • FamilyName

      private String FamilyName
      The family name of the font.
    • Weight

      private String Weight
      The weight of the font: normal, bold, etc.
    • ItalicAngle

      private float ItalicAngle
      The italic angle of the font, usually 0.0 or negative.
    • IsFixedPitch

      private boolean IsFixedPitch
      true if all the characters have the same width.
    • CharacterSet

      private String CharacterSet
      The character set of the font.
    • llx

      private int llx
      The llx of the FontBox.
    • lly

      private int lly
      The lly of the FontBox.
    • urx

      private int urx
      The lurx of the FontBox.
    • ury

      private int ury
      The ury of the FontBox.
    • UnderlinePosition

      private int UnderlinePosition
      The underline position.
    • UnderlineThickness

      private int UnderlineThickness
      The underline thickness.
    • EncodingScheme

      private String EncodingScheme
      The font's encoding name. This encoding is 'StandardEncoding' or 'AdobeStandardEncoding' for a font that can be totally encoded according to the characters names. For all other names the font is treated as symbolic.
    • CapHeight

      private int CapHeight
      A variable.
    • XHeight

      private int XHeight
      A variable.
    • Ascender

      private int Ascender
      A variable.
    • Descender

      private int Descender
      A variable.
    • StdHW

      private int StdHW
      A variable.
    • StdVW

      private int StdVW
      A variable.
    • CharMetrics

      private Map<Object,Object[]> CharMetrics
      Represents the section CharMetrics in the AFM file. Each value of this array contains a Object[4] with an Integer, Integer, String and int[]. This is the code, width, name and char bbox. The key is the name of the char and also an Integer with the char number.
    • KernPairs

      private Map<String,Object[]> KernPairs
      Represents the section KernPairs in the AFM file. The key is the name of the first character and the value is a Object[] with 2 elements for each kern pair. Position 0 is the name of the second character and position 1 is the kerning distance. This is repeated for all the pairs.
    • fileName

      private String fileName
      The file in use.
    • builtinFont

      private boolean builtinFont
      true if this font is one of the 14 built in fonts.
  • Constructor Details

    • Type1Font

      Type1Font(String afmFile, String enc, boolean emb, byte[] ttfAfm, byte[] pfb, boolean forceRead) throws DocumentException, IOException
      Creates a new Type1 font.
      Parameters:
      afmFile - the name of one of the 14 built-in fonts or the location of an AFM file. The file must end in '.afm'
      enc - the encoding to be applied to this font
      emb - true if the font is to be embedded in the PDF
      ttfAfm - the AFM file if the input is made with a byte array
      pfb - the PFB file if the input is made with a byte array
      Throws:
      DocumentException - the AFM file is invalid
      IOException - the AFM file could not be read
      Since:
      2.1.5
  • Method Details

    • getRawWidth

      int getRawWidth(int c, String name)
      Gets the width from the font according to the name or, if the name is null, meaning it is a symbolic font, the char c.
      Specified by:
      getRawWidth in class BaseFont
      Parameters:
      c - the char if the font is symbolic
      name - the glyph name
      Returns:
      the width of the char
    • getKerning

      public int getKerning(int char1, int char2)
      Gets the kerning between two Unicode characters. The characters are converted to names and this names are used to find the kerning pairs in the HashMap KernPairs.
      Specified by:
      getKerning in class BaseFont
      Parameters:
      char1 - the first char
      char2 - the second char
      Returns:
      the kerning to be applied
    • process

      public void process(RandomAccessFileOrArray rf) throws DocumentException, IOException
      Reads the font metrics
      Parameters:
      rf - the AFM file
      Throws:
      DocumentException - the AFM file is invalid
      IOException - the AFM file could not be read
    • getFullFontStream

      public PdfStream getFullFontStream() throws DocumentException
      If the embedded flag is false or if the font is one of the 14 built in types, it returns null, otherwise the font is read and output in a PdfStream object.
      Specified by:
      getFullFontStream in class BaseFont
      Returns:
      the PdfStream containing the font or null
      Throws:
      DocumentException - if there is an error reading the font
      Since:
      2.1.3
    • getFontDescriptor

      private PdfDictionary getFontDescriptor(PdfIndirectReference fontStream)
      Generates the font descriptor for this font or null if it is one of the 14 built in fonts.
      Parameters:
      fontStream - the indirect reference to a PdfStream containing the font or null
      Returns:
      the PdfDictionary containing the font descriptor or null
    • getFontBaseType

      private PdfDictionary getFontBaseType(PdfIndirectReference fontDescriptor, int firstChar, int lastChar, byte[] shortTag)
      Generates the font dictionary for this font.
      Parameters:
      fontDescriptor - the indirect reference to a PdfDictionary containing the font descriptor or null
      firstChar - the first valid character
      lastChar - the last valid character
      shortTag - a 256 bytes long byte array where each unused byte is represented by 0
      Returns:
      the PdfDictionary containing the font dictionary
    • writeFont

      void writeFont(PdfWriter writer, PdfIndirectReference ref, Object[] params) throws DocumentException, IOException
      Outputs to the writer the font dictionaries and streams.
      Specified by:
      writeFont in class BaseFont
      Parameters:
      writer - the writer for this document
      ref - the font indirect reference
      params - several parameters that depend on the font type
      Throws:
      IOException - on error
      DocumentException - error in generating the object
    • getFontDescriptor

      public float getFontDescriptor(int key, float fontSize)
      Gets the font parameter identified by key. Valid values for key are ASCENT, CAPHEIGHT, DESCENT, ITALICANGLE, BBOXLLX, BBOXLLY, BBOXURX and BBOXURY.
      Specified by:
      getFontDescriptor in class BaseFont
      Parameters:
      key - the parameter to be extracted
      fontSize - the font size in points
      Returns:
      the parameter in points
    • getPostscriptFontName

      public String getPostscriptFontName()
      Gets the postscript font name.
      Specified by:
      getPostscriptFontName in class BaseFont
      Returns:
      the postscript font name
    • setPostscriptFontName

      public void setPostscriptFontName(String name)
      Sets the font name that will appear in the pdf font dictionary. Use with care as it can easily make a font unreadable if not embedded.
      Specified by:
      setPostscriptFontName in class BaseFont
      Parameters:
      name - the new font name
    • getFullFontName

      public String[][] getFullFontName()
      Gets the full name of the font. If it is a True Type font each array element will have {Platform ID, Platform Encoding ID, Language ID, font name}. The interpretation of this values can be found in the Open Type specification, chapter 2, in the 'name' table.
      For the other fonts the array has a single element with {"", "", "", font name}.
      Specified by:
      getFullFontName in class BaseFont
      Returns:
      the full name of the font
    • getAllNameEntries

      public String[][] getAllNameEntries()
      Gets all the entries of the names-table. If it is a True Type font each array element will have {Name ID, Platform ID, Platform Encoding ID, Language ID, font name}. The interpretation of this values can be found in the Open Type specification, chapter 2, in the 'name' table.
      For the other fonts the array has a single element with {"4", "", "", "", font name}.
      Specified by:
      getAllNameEntries in class BaseFont
      Returns:
      the full name of the font
    • getFamilyFontName

      public String[][] getFamilyFontName()
      Gets the family name of the font. If it is a True Type font each array element will have {Platform ID, Platform Encoding ID, Language ID, font name}. The interpretation of this values can be found in the Open Type specification, chapter 2, in the 'name' table.
      For the other fonts the array has a single element with {"", "", "", font name}.
      Specified by:
      getFamilyFontName in class BaseFont
      Returns:
      the family name of the font
    • hasKernPairs

      public boolean hasKernPairs()
      Checks if the font has any kerning pairs.
      Specified by:
      hasKernPairs in class BaseFont
      Returns:
      true if the font has any kerning pairs
    • setKerning

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

      protected int[] getRawCharBBox(int c, String name)
      Specified by:
      getRawCharBBox in class BaseFont