Class Type1Font

Direct Known Subclasses:
BuiltinFont

public class Type1Font extends OutlineFont
A representation, with parser, of an Adobe Type 1 font.
  • Field Details

    • chr2name

      String[] chr2name
    • password

      int password
    • subrs

      byte[][] subrs
    • lenIV

      int lenIV
    • name2outline

      Map<String,Object> name2outline
    • name2width

      Map<String,FlPoint> name2width
    • at

    • stack

      float[] stack
      the Type1 stack of command values
    • sloc

      int sloc
      the current position in the Type1 stack
    • psStack

      float[] psStack
      the stack of postscript commands (used by callothersubr)
    • psLoc

      int psLoc
      the current position in the postscript stack
    • callcount

      int callcount
  • Constructor Details

    • Type1Font

      public Type1Font(String baseName, PDFObject src, PDFFontDescriptor descriptor) throws IOException
      create a new Type1Font based on a font data stream and an encoding.
      Parameters:
      baseName - the postscript name of this font
      src - the Font object as a stream with a dictionary
      descriptor - the descriptor for this font
      Throws:
      IOException
  • Method Details

    • parseFont

      protected void parseFont(byte[] font, int start, int len)
      Read a font from it's data, start position and length
    • readEncoding

      private String[] readEncoding(byte[] d)
      parse the encoding portion of the font definition
      Parameters:
      d - the font definition stream
      Returns:
      an array of the glyphs corresponding to each byte
    • readSubrs

      private byte[][] readSubrs(byte[] d)
      read the subroutines out of the font definition
      Parameters:
      d - the font definition stream
      Returns:
      an array of the subroutines, each as a byte array.
    • readArray

      private byte[][] readArray(byte[] d, String key, String end)
      read a named array out of the font definition.

      this function attempts to parse an array out of a postscript definition without doing any postscript. It's actually looking for things that look like "dup id elt put", and placing the elt at the ith position in the array.

      Parameters:
      d - the font definition stream
      key - the name of the array
      end - a string that appears at the end of the array
      Returns:
      an array consisting of a byte array for each entry
    • decrypt

      private byte[] decrypt(byte[] d, int start, int end, int key, int skip)
      decrypt an array using the Adobe Type 1 Font decryption algorithm.
      Parameters:
      d - the input array of bytes
      start - where in the array to start decoding
      end - where in the array to stop decoding
      key - the decryption key
      skip - how many bytes to skip initially
      Returns:
      the decrypted bytes. The length of this array will be (start-end-skip) bytes long
    • readASCII

      private byte[] readASCII(byte[] data, int start, int end)
      Read data formatted as ASCII strings as binary data
      Parameters:
      data - the data, formatted as ASCII strings
      start - where in the array to start decrypting
      end - where in the array to stop decrypting
    • isASCII

      private boolean isASCII(byte[] data, int start)
      Determine if data is in ASCII or binary format. According to the spec, if any of the first 4 bytes are not character codes ('0' - '9' or 'A' - 'F' or 'a' - 'f'), then the data is binary. Otherwise it is ASCII
    • findSlashName

      private int findSlashName(byte[] d, String name)
      get the index into the byte array of a slashed name, like "/name".
      Parameters:
      d - the search array
      name - the name to look for, without the initial /
      Returns:
      the index of the first occurance of /name in the array.
    • readChars

      private HashMap<String,byte[]> readChars(byte[] d)
      get the character definitions of the font.
      Parameters:
      d - the font data
      Returns:
      a HashMap that maps string glyph names to byte arrays of decoded font data.
    • pop

      private float pop()
      pop the next item off the stack
    • parse

      private void parse(byte[] cs, GeneralPath gp, FlPoint pt, FlPoint wid)
      parse glyph data into a GeneralPath, and return the advance width. The working point is passed in as a parameter in order to allow recursion.
      Parameters:
      cs - the decrypted glyph data
      gp - a GeneralPath into which the glyph shape will be stored
      pt - a FlPoint object that will be used to generate the path
      wid - a FlPoint into which the advance width will be placed.
    • buildAccentChar

      private void buildAccentChar(float x, float y, char a, char b, GeneralPath gp)
      build an accented character out of two pre-defined glyphs.
      Parameters:
      x - the x offset of the accent
      y - the y offset of the accent
      a - the index of the accent glyph
      b - the index of the base glyph
      gp - the GeneralPath into which the combined glyph will be written.
    • getWidth

      public float getWidth(char code, String name)
      Get the width of a given character This method is overridden to work if the width array hasn't been populated (as for one of the 14 base fonts)
      Overrides:
      getWidth in class OutlineFont
    • parseGlyph

      private GeneralPath parseGlyph(byte[] cs, FlPoint advance, AffineTransform at)
      Decrypt a glyph stored in byte form
    • getOutline

      protected GeneralPath getOutline(String name, float width)
      Get a glyph outline by name
      Specified by:
      getOutline in class OutlineFont
      Parameters:
      name - the name of the desired glyph
      Returns:
      the glyph outline, or null if unavailable
    • getOutline

      protected GeneralPath getOutline(char src, float width)
      Get a glyph outline by character code Note this method must always return an outline
      Specified by:
      getOutline in class OutlineFont
      Parameters:
      src - the character code of the desired glyph
      Returns:
      the glyph outline