Class Type1Parser

java.lang.Object
org.apache.fontbox.type1.Type1Parser

final class Type1Parser extends Object
Parses an Adobe Type 1 (.pfb) font. It is used exclusively by Type1Font. The Type 1 font format is a free-text format which is somewhat difficult to parse. This is made worse by the fact that many Type 1 font files do not conform to the specification, especially those embedded in PDFs. This parser therefore tries to be as forgiving as possible.
See Also:
  • "Adobe Type 1 Font Format, Adobe Systems (1999)"
  • Field Details

  • Constructor Details

    • Type1Parser

      Type1Parser()
  • Method Details

    • parse

      public Type1Font parse(byte[] segment1, byte[] segment2) throws IOException
      Parses a Type 1 font and returns a Type1Font class which represents it.
      Parameters:
      segment1 - Segment 1: ASCII
      segment2 - Segment 2: Binary
      Throws:
      IOException
    • parseASCII

      private void parseASCII(byte[] bytes) throws IOException
      Parses the ASCII portion of a Type 1 font.
      Throws:
      IOException
    • readSimpleValue

      private void readSimpleValue(String key) throws IOException
      Throws:
      IOException
    • readEncoding

      private void readEncoding() throws IOException
      Throws:
      IOException
    • arrayToNumbers

      private List<Number> arrayToNumbers(List<Token> value) throws IOException
      Extracts values from an array as numbers.
      Throws:
      IOException
    • readFontInfo

      private void readFontInfo(Map<String,List<Token>> fontInfo)
      Extracts values from the /FontInfo dictionary.
    • readSimpleDict

      private Map<String,List<Token>> readSimpleDict() throws IOException
      Reads a dictionary whose values are simple, i.e., do not contain nested dictionaries.
      Throws:
      IOException
    • readDictValue

      private List<Token> readDictValue() throws IOException
      Reads a simple value from a dictionary.
      Throws:
      IOException
    • readValue

      private List<Token> readValue() throws IOException
      Reads a simple value. This is either a number, a string, a name, a literal name, an array, a procedure, or a charstring. This method does not support reading nested dictionaries.
      Throws:
      IOException
    • readPostScriptWrapper

      private void readPostScriptWrapper(List<Token> value) throws IOException
      Throws:
      IOException
    • readProc

      private List<Token> readProc() throws IOException
      Reads a procedure.
      Throws:
      IOException
    • readProcVoid

      private void readProcVoid() throws IOException
      Reads a procedure but without returning anything.
      Throws:
      IOException
    • parseBinary

      private void parseBinary(byte[] bytes) throws IOException
      Parses the binary portion of a Type 1 font.
      Throws:
      IOException
    • readPrivate

      private void readPrivate(String key, List<Token> value) throws IOException
      Extracts values from the /Private dictionary.
      Throws:
      IOException
    • readSubrs

      private void readSubrs(int lenIV) throws IOException
      Reads the /Subrs array.
      Parameters:
      lenIV - The number of random bytes used in charstring encryption.
      Throws:
      IOException
    • readOtherSubrs

      private void readOtherSubrs() throws IOException
      Throws:
      IOException
    • readCharStrings

      private void readCharStrings(int lenIV) throws IOException
      Reads the /CharStrings dictionary.
      Parameters:
      lenIV - The number of random bytes used in charstring encryption.
      Throws:
      IOException
    • readDef

      private void readDef() throws IOException
      Reads the sequence "noaccess def" or equivalent.
      Throws:
      IOException
    • readPut

      private void readPut() throws IOException
      Reads the sequence "noaccess put" or equivalent.
      Throws:
      IOException
    • read

      private Token read(Token.Kind kind) throws IOException
      Reads the next token and throws an error if it is not of the given kind.
      Throws:
      IOException
    • read

      private void read(Token.Kind kind, String name) throws IOException
      Reads the next token and throws an error if it is not of the given kind and does not have the given value.
      Throws:
      IOException
    • readMaybe

      private Token readMaybe(Token.Kind kind, String name) throws IOException
      Reads the next token if and only if it is of the given kind and has the given value.
      Throws:
      IOException
    • decrypt

      private byte[] decrypt(byte[] cipherBytes, int r, int n)
      Type 1 Decryption (eexec, charstring).
      Parameters:
      cipherBytes - cipher text
      r - key
      n - number of random bytes (lenIV)
      Returns:
      plain text
    • isBinary

      private boolean isBinary(byte[] bytes)
    • hexToBinary

      private byte[] hexToBinary(byte[] bytes)