Class Type1Parser


  • final class Type1Parser
    extends java.lang.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)"
    • Constructor Summary

      Constructors 
      Constructor Description
      Type1Parser()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.util.List<java.lang.Number> arrayToNumbers​(java.util.List<Token> value)
      Extracts values from an array as numbers.
      private byte[] decrypt​(byte[] cipherBytes, int r, int n)
      Type 1 Decryption (eexec, charstring).
      private byte[] hexToBinary​(byte[] bytes)  
      private boolean isBinary​(byte[] bytes)  
      Type1Font parse​(byte[] segment1, byte[] segment2)
      Parses a Type 1 font and returns a Type1Font class which represents it.
      private void parseASCII​(byte[] bytes)
      Parses the ASCII portion of a Type 1 font.
      private void parseBinary​(byte[] bytes)
      Parses the binary portion of a Type 1 font.
      private Token read​(Token.Kind kind)
      Reads the next token and throws an error if it is not of the given kind.
      private void read​(Token.Kind kind, java.lang.String name)
      Reads the next token and throws an error if it is not of the given kind and does not have the given value.
      private void readCharStrings​(int lenIV)
      Reads the /CharStrings dictionary.
      private void readDef()
      Reads the sequence "noaccess def" or equivalent.
      private java.util.List<Token> readDictValue()
      Reads a simple value from a dictionary.
      private void readEncoding()  
      private void readFontInfo​(java.util.Map<java.lang.String,​java.util.List<Token>> fontInfo)
      Extracts values from the /FontInfo dictionary.
      private Token readMaybe​(Token.Kind kind, java.lang.String name)
      Reads the next token if and only if it is of the given kind and has the given value.
      private void readOtherSubrs()  
      private void readPostScriptWrapper​(java.util.List<Token> value)  
      private void readPrivate​(java.lang.String key, java.util.List<Token> value)
      Extracts values from the /Private dictionary.
      private java.util.List<Token> readProc()
      Reads a procedure.
      private void readPut()
      Reads the sequence "noaccess put" or equivalent.
      private java.util.Map<java.lang.String,​java.util.List<Token>> readSimpleDict()
      Reads a dictionary whose values are simple, i.e., do not contain nested dictionaries.
      private void readSimpleValue​(java.lang.String key)  
      private void readSubrs​(int lenIV)
      Reads the /Subrs array.
      private java.util.List<Token> readValue()
      Reads a simple value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Type1Parser

        Type1Parser()
    • Method Detail

      • parse

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

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

        private void readSimpleValue​(java.lang.String key)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • readEncoding

        private void readEncoding()
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • arrayToNumbers

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

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

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

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

        private java.util.List<Token> readValue()
                                         throws java.io.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:
        java.io.IOException
      • readPostScriptWrapper

        private void readPostScriptWrapper​(java.util.List<Token> value)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • readProc

        private java.util.List<Token> readProc()
                                        throws java.io.IOException
        Reads a procedure.
        Throws:
        java.io.IOException
      • parseBinary

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

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

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

        private void readOtherSubrs()
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • readCharStrings

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

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

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

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

        private void read​(Token.Kind kind,
                          java.lang.String name)
                   throws java.io.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:
        java.io.IOException
      • readMaybe

        private Token readMaybe​(Token.Kind kind,
                                java.lang.String name)
                         throws java.io.IOException
        Reads the next token if and only if it is of the given kind and has the given value.
        Throws:
        java.io.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)