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 int
private static final int
private Type1Font
private 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 boolean
isBinary
(byte[] bytes) 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, 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.Reads a simple value from a dictionary.private void
private void
readFontInfo
(Map<String, List<Token>> fontInfo) Extracts values from the /FontInfo dictionary.private Token
readMaybe
(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 void
private void
readPostScriptWrapper
(List<Token> value) private void
readPrivate
(String key, List<Token> value) Extracts values from the /Private dictionary.readProc()
Reads a procedure.private void
Reads a procedure but without returning anything.private void
readPut()
Reads the sequence "noaccess put" or equivalent.Reads a dictionary whose values are simple, i.e., do not contain nested dictionaries.private void
readSimpleValue
(String key) private void
readSubrs
(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 error if it is not of the given kind.- Throws:
IOException
-
read
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
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 textr
- keyn
- number of random bytes (lenIV)- Returns:
- plain text
-
isBinary
private boolean isBinary(byte[] bytes) -
hexToBinary
private byte[] hexToBinary(byte[] bytes)
-