Package org.apache.fontbox.type1
Class Type1Parser
java.lang.Object
org.apache.fontbox.type1.Type1Parser
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final intprivate Type1Fontprivate Type1Lexer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionarrayToNumbers(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 booleanisBinary(byte[] bytes) parse(byte[] segment1, byte[] segment2) Parses a Type 1 font and returns a Type1Font class which represents it.private voidparseASCII(byte[] bytes) Parses the ASCII portion of a Type 1 font.private voidparseBinary(byte[] bytes) Parses the binary portion of a Type 1 font.private Tokenread(Token.Kind kind) Reads the next token and throws an exception if it is not of the given kind.private voidread(Token.Kind kind, String name) Reads the next token and throws an exception if it is not of the given kind and does not have the given value.private voidreadCharStrings(int lenIV) Reads the /CharStrings dictionary.private voidreadDef()Reads the sequence "noaccess def" or equivalent.Reads a simple value from a dictionary.private voidprivate voidreadFontInfo(Map<String, List<Token>> fontInfo) Extracts values from the /FontInfo dictionary.private TokenreadMaybe(Token.Kind kind, String name) Reads the next token if and only if it is of the given kind and has the given value.private voidprivate voidreadPostScriptWrapper(List<Token> value) private voidreadPrivate(String key, List<Token> value) Extracts values from the /Private dictionary.readProc()Reads a procedure.private voidReads a procedure but without returning anything.private voidreadPut()Reads the sequence "noaccess put" or equivalent.Reads a dictionary whose values are simple, i.e., do not contain nested dictionaries.private voidreadSimpleValue(String key) private voidreadSubrs(int lenIV) Reads the /Subrs array.Reads a simple value.
-
Field Details
-
EEXEC_KEY
private static final int EEXEC_KEY- See Also:
-
CHARSTRING_KEY
private static final int CHARSTRING_KEY- See Also:
-
lexer
-
font
-
-
Constructor Details
-
Type1Parser
Type1Parser()
-
-
Method Details
-
parse
Parses a Type 1 font and returns a Type1Font class which represents it.- Parameters:
segment1- Segment 1: ASCIIsegment2- Segment 2: Binary- Throws:
IOException
-
parseASCII
Parses the ASCII portion of a Type 1 font.- Throws:
IOException
-
readSimpleValue
- Throws:
IOException
-
readEncoding
- Throws:
IOException
-
arrayToNumbers
Extracts values from an array as numbers.- Throws:
IOException
-
readFontInfo
Extracts values from the /FontInfo dictionary. -
readSimpleDict
Reads a dictionary whose values are simple, i.e., do not contain nested dictionaries.- Throws:
IOException
-
readDictValue
Reads a simple value from a dictionary.- Throws:
IOException
-
readValue
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
- Throws:
IOException
-
readProc
Reads a procedure.- Throws:
IOException
-
readProcVoid
Reads a procedure but without returning anything.- Throws:
IOException
-
parseBinary
Parses the binary portion of a Type 1 font.- Throws:
IOException
-
readPrivate
Extracts values from the /Private dictionary.- Throws:
IOException
-
readSubrs
Reads the /Subrs array.- Parameters:
lenIV- The number of random bytes used in charstring encryption.- Throws:
IOException
-
readOtherSubrs
- Throws:
IOException
-
readCharStrings
Reads the /CharStrings dictionary.- Parameters:
lenIV- The number of random bytes used in charstring encryption.- Throws:
IOException
-
readDef
Reads the sequence "noaccess def" or equivalent.- Throws:
IOException
-
readPut
Reads the sequence "noaccess put" or equivalent.- Throws:
IOException
-
read
Reads the next token and throws an exception if it is not of the given kind.- Returns:
- token, never null
- Throws:
IOException
-
read
Reads the next token and throws an exception if it is not of the given kind and does not have the given value.- Throws:
IOException
-
readMaybe
Reads the next token if and only if it is of the given kind and has the given value.- Returns:
- token or null if not the expected one
- Throws:
IOException
-
decrypt
private byte[] decrypt(byte[] cipherBytes, int r, int n) Type 1 Decryption (eexec, charstring).- Parameters:
cipherBytes- cipher textr- keyn- number of random bytes (lenIV)- Returns:
- plain text
-
isBinary
private boolean isBinary(byte[] bytes) -
hexToBinary
private byte[] hexToBinary(byte[] bytes)
-