Top Description Fields Constructors Methods
org.apache.fontbox.type1

pack-priv final Class Type1Parser

extends Object
Class Inheritance
Imports
org.apache.fontbox.encoding.BuiltInEncoding, .StandardEncoding, java.io.IOException, java.util.ArrayList, .HashMap, .List, .Map

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.
Author
John Hewson
See Also
Adobe Type 1 Font Format, Adobe Systems (1999)

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private Type1Font
private Type1Lexer

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private List<Number>
arrayToNumbers(List<Token> value)

Extracts values from an array as numbers.

private byte[]

Returns:

plain text
decrypt
(byte[]
cipher text
cipherBytes
,
int
key
r
,
int
number of random bytes (lenIV)
n
)

Type 1 Decryption (eexec, charstring).

private byte[]
hexToBinary(byte[] bytes)

private boolean
isBinary(byte[] bytes)

public Type1Font
parse(byte[]
Segment 1: ASCII
segment1
,
byte[]
Segment 2: Binary
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

Returns:

token, never null
read
(Token.Kind kind)

Reads the next token and throws an exception if it is not of the given kind.

private void
read(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 void
readCharStrings(int
The number of random bytes used in charstring encryption.
lenIV
)

Reads the /CharStrings dictionary.

private void
readDef()

Reads the sequence "noaccess def" or equivalent.

private List<Token>
readDictValue()

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

Returns:

token or null if not the expected one
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
private void
readPrivate(String key, List<Token> value)

Extracts values from the /Private dictionary.

private List<Token>
readProc()

Reads a procedure.

private void
readProcVoid()

Reads a procedure but without returning anything.

private void
readPut()

Reads the sequence "noaccess put" or equivalent.

private Map<String, List<Token>>
readSimpleDict()

Reads a dictionary whose values are simple, i.e., do not contain nested dictionaries.

private void
private void
readSubrs(int
The number of random bytes used in charstring encryption.
lenIV
)

Reads the /Subrs array.

private List<Token>
readValue()

Reads a simple value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CHARSTRING_KEYback to summary
private static final int CHARSTRING_KEY
EEXEC_KEYback to summary
private static final int EEXEC_KEY
fontback to summary
private Type1Font font
lexerback to summary
private Type1Lexer lexer

Constructor Detail

Type1Parserback to summary
pack-priv Type1Parser()

Method Detail

arrayToNumbersback to summary
private List<Number> arrayToNumbers(List<Token> value) throws IOException

Extracts values from an array as numbers.

decryptback to summary
private byte[] decrypt(byte[] cipherBytes, int r, int n)

Type 1 Decryption (eexec, charstring).

Parameters
cipherBytes:byte[]

cipher text

r:int

key

n:int

number of random bytes (lenIV)

Returns:byte[]

plain text

hexToBinaryback to summary
private byte[] hexToBinary(byte[] bytes)
isBinaryback to summary
private boolean isBinary(byte[] bytes)
parseback to summary
public Type1Font parse(byte[] segment1, byte[] segment2) throws IOException

Parses a Type 1 font and returns a Type1Font class which represents it.

Parameters
segment1:byte[]

Segment 1: ASCII

segment2:byte[]

Segment 2: Binary

parseASCIIback to summary
private void parseASCII(byte[] bytes) throws IOException

Parses the ASCII portion of a Type 1 font.

parseBinaryback to summary
private void parseBinary(byte[] bytes) throws IOException

Parses the binary portion of a Type 1 font.

readback to summary
private Token read(Token.Kind kind) throws IOException

Reads the next token and throws an exception if it is not of the given kind.

Returns:Token

token, never null

readback to summary
private void read(Token.Kind kind, String name) throws IOException

Reads the next token and throws an exception if it is not of the given kind and does not have the given value.

readCharStringsback to summary
private void readCharStrings(int lenIV) throws IOException

Reads the /CharStrings dictionary.

Parameters
lenIV:int

The number of random bytes used in charstring encryption.

readDefback to summary
private void readDef() throws IOException

Reads the sequence "noaccess def" or equivalent.

readDictValueback to summary
private List<Token> readDictValue() throws IOException

Reads a simple value from a dictionary.

readEncodingback to summary
private void readEncoding() throws IOException
readFontInfoback to summary
private void readFontInfo(Map<String, List<Token>> fontInfo)

Extracts values from the /FontInfo dictionary.

readMaybeback to summary
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.

Returns:Token

token or null if not the expected one

readOtherSubrsback to summary
private void readOtherSubrs() throws IOException
readPostScriptWrapperback to summary
private void readPostScriptWrapper(List<Token> value) throws IOException
readPrivateback to summary
private void readPrivate(String key, List<Token> value) throws IOException

Extracts values from the /Private dictionary.

readProcback to summary
private List<Token> readProc() throws IOException

Reads a procedure.

readProcVoidback to summary
private void readProcVoid() throws IOException

Reads a procedure but without returning anything.

readPutback to summary
private void readPut() throws IOException

Reads the sequence "noaccess put" or equivalent.

readSimpleDictback to summary
private Map<String, List<Token>> readSimpleDict() throws IOException

Reads a dictionary whose values are simple, i.e., do not contain nested dictionaries.

readSimpleValueback to summary
private void readSimpleValue(String key) throws IOException
readSubrsback to summary
private void readSubrs(int lenIV) throws IOException

Reads the /Subrs array.

Parameters
lenIV:int

The number of random bytes used in charstring encryption.

readValueback to summary
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 unless they're empty.