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

public Class AFMParser

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, java.nio.charset.StandardCharsets, java.util.StringTokenizer, org.apache.fontbox.util.BoundingBox

This class is used to parse AFM(Adobe Font Metrics) documents.
Author
Ben Litchfield
See Also
AFM Documentation

Field Summary

Modifier and TypeField and Description
public static final String
ASCENDER

This is ascender attribute.

private static final int
public static final String
CAP_HEIGHT

This is the cap height attribute.

public static final String
CC

This is a composite character.

public static final String
CHAR_WIDTH

This is the char width.

public static final String
CHARACTER_SET

This is the character set.

public static final String
CHARACTERS

This is the characters attribute.

public static final String
CHARMETRICS_B

The character metrics value.

public static final String
CHARMETRICS_C

The character metrics c value.

public static final String
CHARMETRICS_CH

The character metrics c value.

public static final String
CHARMETRICS_L

The character metrics value.

public static final String
CHARMETRICS_N

The character metrics value.

public static final String
CHARMETRICS_VV

The character metrics value.

public static final String
CHARMETRICS_W

The character metrics value.

public static final String
CHARMETRICS_W0

The character metrics value.

public static final String
CHARMETRICS_W0X

The character metrics value.

public static final String
CHARMETRICS_W0Y

The character metrics value.

public static final String
CHARMETRICS_W1

The character metrics value.

public static final String
CHARMETRICS_W1X

The character metrics value.

public static final String
CHARMETRICS_W1Y

The character metrics value.

public static final String
CHARMETRICS_WX

The character metrics value.

public static final String
CHARMETRICS_WY

The character metrics value.

public static final String
COMMENT

This is a comment in a AFM file.

public static final String
DESCENDER

This is the descender attribute.

public static final String
ENCODING_SCHEME

This is the encoding scheme.

public static final String
END_CHAR_METRICS

This is the end of character metrics.

public static final String
END_COMPOSITES

This is the end composites data section.

public static final String
END_FONT_METRICS

This is the constant used in the AFM file to end a font metrics item.

public static final String
END_KERN_DATA

This is the end of kern data.

public static final String
END_KERN_PAIRS

This is the end of kern pairs data.

public static final String
END_TRACK_KERN

This is the end of track kern data.

public static final String
ESC_CHAR

This is the escape character.

public static final String
FAMILY_NAME

This is the Family name.

public static final String
FONT_BBOX

This is the font bounding box.

public static final String
FONT_NAME

This is the font name.

public static final String
FULL_NAME

This is the full name.

private final InputStream
public static final String
IS_BASE_FONT

This will determine if this is a base font.

public static final String
IS_FIXED_PITCH

This will determine if this is fixed pitch.

public static final String
IS_FIXED_V

This will tell if the V is fixed.

public static final String
ITALIC_ANGLE

This is the italic angle.

public static final String
KERN_PAIR_KP

This is a kern pair.

public static final String
KERN_PAIR_KPH

This is a kern pair.

public static final String
KERN_PAIR_KPX

This is a kern pair.

public static final String
KERN_PAIR_KPY

This is a kern pair.

public static final String
MAPPING_SCHEME

This is the mapping scheme.

public static final String
NOTICE

This is the notice.

public static final String
PCC

This is a composite character part.

public static final String
START_CHAR_METRICS

This is the start of character metrics.

public static final String
START_COMPOSITES

This is the start composites data section.

public static final String
START_FONT_METRICS

This is the constant used in the AFM file to start a font metrics item.

public static final String
START_KERN_DATA

This is the start of kern data.

public static final String
START_KERN_PAIRS

This is the start of kern pairs data.

public static final String
START_KERN_PAIRS0

This is the start of kern pairs data.

public static final String
START_KERN_PAIRS1

This is the start of kern pairs data.

public static final String
START_TRACK_KERN

This is the start of track kern data.

public static final String
STD_HW

The character metrics value.

public static final String
STD_VW

The character metrics value.

public static final String
UNDERLINE_POSITION

The underline position.

public static final String
UNDERLINE_THICKNESS

This is the Underline thickness.

public static final String
V_VECTOR

This is the V Vector attribute.

public static final String
VERSION

This is the version of the font.

public static final String
WEIGHT

This is the weight.

public static final String
X_HEIGHT

This is the X height.

Constructor Summary

AccessConstructor and Description
public
AFMParser(InputStream
The input stream to read the AFM document from.
in
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
private String

Returns:

The bytes of the hex string.
hexToString
(String
An angle bracket string.
hexToString
)

This will convert and angle bracket hex string to a string.

private static boolean

Returns:

true If the character is whitespace as defined by the AFM spec.
isEOL
(int
The character to test for whitespace.
character
)

This will determine if the byte is a whitespace character or not.

private static boolean

Returns:

true If the character is whitespace as defined by the AFM spec.
isWhitespace
(int
The character to test for whitespace.
character
)

This will determine if the byte is a whitespace character or not.

public FontMetrics

Returns:

the parsed FontMetric
parse
()

This will parse the AFM document.

public FontMetrics

Returns:

the parsed FontMetric
parse
(boolean
parse a reduced subset of data if set to true
reducedDataset
)

This will parse the AFM document.

private CharMetric

Returns:

The next char metric in the stream.
parseCharMetric
()

This will parse a single CharMetric object from the stream.

private boolean
private Composite

Returns:

The composite.
parseComposite
()

This will parse a composite part from the stream.

private void
private float
parseFloat(String floatValue)

private FontMetrics

Returns:

The parse font metrics item.
parseFontMetric
(boolean reducedDataset)

This will parse a font metrics item.

private int
parseInt(String intValue)

private int
parseInt(String intValue, int radix)

private void
parseKernData(FontMetrics
The metrics class to put the parsed data into.
fontMetrics
)

This will parse the kern data.

private KernPair

Returns:

The kern pair that was parsed from the stream.
parseKernPair
()

This will parse a kern pair from the data stream.

private void
private void
private void
private boolean

Returns:

The boolean in the stream.
readBoolean
()

This will read a boolean from the stream.

private void
readCommand(String
the expected command
expectedCommand
)

Read the next string.

private float

Returns:

The float in the stream.
readFloat
()

This will read a float from the stream.

private int

Returns:

The integer in the stream.
readInt
()

This will read an integer from the stream.

private String

Returns:

The string that is read.
readLine
()

This will read until the end of a line.

private String

Returns:

The string read from the stream.
readString
()

This will read a string from the input stream and stop at any whitespace.

private void
verifySemicolon(StringTokenizer
The tokenizer to read from.
tokenizer
)

This is used to verify that a semicolon is the next token in the stream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ASCENDERback to summary
public static final String ASCENDER

This is ascender attribute.

BITS_IN_HEXback to summary
private static final int BITS_IN_HEX
CAP_HEIGHTback to summary
public static final String CAP_HEIGHT

This is the cap height attribute.

CCback to summary
public static final String CC

This is a composite character.

CHAR_WIDTHback to summary
public static final String CHAR_WIDTH

This is the char width.

CHARACTER_SETback to summary
public static final String CHARACTER_SET

This is the character set.

CHARACTERSback to summary
public static final String CHARACTERS

This is the characters attribute.

CHARMETRICS_Bback to summary
public static final String CHARMETRICS_B

The character metrics value.

CHARMETRICS_Cback to summary
public static final String CHARMETRICS_C

The character metrics c value.

CHARMETRICS_CHback to summary
public static final String CHARMETRICS_CH

The character metrics c value.

CHARMETRICS_Lback to summary
public static final String CHARMETRICS_L

The character metrics value.

CHARMETRICS_Nback to summary
public static final String CHARMETRICS_N

The character metrics value.

CHARMETRICS_VVback to summary
public static final String CHARMETRICS_VV

The character metrics value.

CHARMETRICS_Wback to summary
public static final String CHARMETRICS_W

The character metrics value.

CHARMETRICS_W0back to summary
public static final String CHARMETRICS_W0

The character metrics value.

CHARMETRICS_W0Xback to summary
public static final String CHARMETRICS_W0X

The character metrics value.

CHARMETRICS_W0Yback to summary
public static final String CHARMETRICS_W0Y

The character metrics value.

CHARMETRICS_W1back to summary
public static final String CHARMETRICS_W1

The character metrics value.

CHARMETRICS_W1Xback to summary
public static final String CHARMETRICS_W1X

The character metrics value.

CHARMETRICS_W1Yback to summary
public static final String CHARMETRICS_W1Y

The character metrics value.

CHARMETRICS_WXback to summary
public static final String CHARMETRICS_WX

The character metrics value.

CHARMETRICS_WYback to summary
public static final String CHARMETRICS_WY

The character metrics value.

COMMENTback to summary
public static final String COMMENT

This is a comment in a AFM file.

DESCENDERback to summary
public static final String DESCENDER

This is the descender attribute.

ENCODING_SCHEMEback to summary
public static final String ENCODING_SCHEME

This is the encoding scheme.

END_CHAR_METRICSback to summary
public static final String END_CHAR_METRICS

This is the end of character metrics.

END_COMPOSITESback to summary
public static final String END_COMPOSITES

This is the end composites data section.

END_FONT_METRICSback to summary
public static final String END_FONT_METRICS

This is the constant used in the AFM file to end a font metrics item.

END_KERN_DATAback to summary
public static final String END_KERN_DATA

This is the end of kern data.

END_KERN_PAIRSback to summary
public static final String END_KERN_PAIRS

This is the end of kern pairs data.

END_TRACK_KERNback to summary
public static final String END_TRACK_KERN

This is the end of track kern data.

ESC_CHARback to summary
public static final String ESC_CHAR

This is the escape character.

FAMILY_NAMEback to summary
public static final String FAMILY_NAME

This is the Family name.

FONT_BBOXback to summary
public static final String FONT_BBOX

This is the font bounding box.

FONT_NAMEback to summary
public static final String FONT_NAME

This is the font name.

FULL_NAMEback to summary
public static final String FULL_NAME

This is the full name.

inputback to summary
private final InputStream input
IS_BASE_FONTback to summary
public static final String IS_BASE_FONT

This will determine if this is a base font.

IS_FIXED_PITCHback to summary
public static final String IS_FIXED_PITCH

This will determine if this is fixed pitch.

IS_FIXED_Vback to summary
public static final String IS_FIXED_V

This will tell if the V is fixed.

ITALIC_ANGLEback to summary
public static final String ITALIC_ANGLE

This is the italic angle.

KERN_PAIR_KPback to summary
public static final String KERN_PAIR_KP

This is a kern pair.

KERN_PAIR_KPHback to summary
public static final String KERN_PAIR_KPH

This is a kern pair.

KERN_PAIR_KPXback to summary
public static final String KERN_PAIR_KPX

This is a kern pair.

KERN_PAIR_KPYback to summary
public static final String KERN_PAIR_KPY

This is a kern pair.

MAPPING_SCHEMEback to summary
public static final String MAPPING_SCHEME

This is the mapping scheme.

NOTICEback to summary
public static final String NOTICE

This is the notice.

PCCback to summary
public static final String PCC

This is a composite character part.

START_CHAR_METRICSback to summary
public static final String START_CHAR_METRICS

This is the start of character metrics.

START_COMPOSITESback to summary
public static final String START_COMPOSITES

This is the start composites data section.

START_FONT_METRICSback to summary
public static final String START_FONT_METRICS

This is the constant used in the AFM file to start a font metrics item.

START_KERN_DATAback to summary
public static final String START_KERN_DATA

This is the start of kern data.

START_KERN_PAIRSback to summary
public static final String START_KERN_PAIRS

This is the start of kern pairs data.

START_KERN_PAIRS0back to summary
public static final String START_KERN_PAIRS0

This is the start of kern pairs data.

START_KERN_PAIRS1back to summary
public static final String START_KERN_PAIRS1

This is the start of kern pairs data.

START_TRACK_KERNback to summary
public static final String START_TRACK_KERN

This is the start of track kern data.

STD_HWback to summary
public static final String STD_HW

The character metrics value.

STD_VWback to summary
public static final String STD_VW

The character metrics value.

UNDERLINE_POSITIONback to summary
public static final String UNDERLINE_POSITION

The underline position.

UNDERLINE_THICKNESSback to summary
public static final String UNDERLINE_THICKNESS

This is the Underline thickness.

V_VECTORback to summary
public static final String V_VECTOR

This is the V Vector attribute.

VERSIONback to summary
public static final String VERSION

This is the version of the font.

WEIGHTback to summary
public static final String WEIGHT

This is the weight.

X_HEIGHTback to summary
public static final String X_HEIGHT

This is the X height.

Constructor Detail

AFMParserback to summary
public AFMParser(InputStream in)

Constructor.

Parameters
in:InputStream

The input stream to read the AFM document from.

Method Detail

hexToStringback to summary
private String hexToString(String hexToString) throws IOException

This will convert and angle bracket hex string to a string.

Parameters
hexToString:String

An angle bracket string.

Returns:String

The bytes of the hex string.

Exceptions
IOException:
If the string is in an invalid format.
isEOLback to summary
private static boolean isEOL(int character)

This will determine if the byte is a whitespace character or not.

Parameters
character:int

The character to test for whitespace.

Returns:boolean

true If the character is whitespace as defined by the AFM spec.

isWhitespaceback to summary
private static boolean isWhitespace(int character)

This will determine if the byte is a whitespace character or not.

Parameters
character:int

The character to test for whitespace.

Returns:boolean

true If the character is whitespace as defined by the AFM spec.

parseback to summary
public FontMetrics parse() throws IOException

This will parse the AFM document. The input stream is closed when the parsing is finished.

Returns:FontMetrics

the parsed FontMetric

Exceptions
IOException:
If there is an IO error reading the document.
parseback to summary
public FontMetrics parse(boolean reducedDataset) throws IOException

This will parse the AFM document. The input stream is closed when the parsing is finished.

Parameters
reducedDataset:boolean

parse a reduced subset of data if set to true

Returns:FontMetrics

the parsed FontMetric

Exceptions
IOException:
If there is an IO error reading the document.
parseCharMetricback to summary
private CharMetric parseCharMetric() throws IOException

This will parse a single CharMetric object from the stream.

Returns:CharMetric

The next char metric in the stream.

Exceptions
IOException:
If there is an error reading from the stream.
parseCharMetricsback to summary
private boolean parseCharMetrics(FontMetrics fontMetrics) throws IOException
parseCompositeback to summary
private Composite parseComposite() throws IOException

This will parse a composite part from the stream.

Returns:Composite

The composite.

Exceptions
IOException:
If there is an error parsing the composite.
parseCompositesback to summary
private void parseComposites(FontMetrics fontMetrics) throws IOException
parseFloatback to summary
private float parseFloat(String floatValue) throws IOException
parseFontMetricback to summary
private FontMetrics parseFontMetric(boolean reducedDataset) throws IOException

This will parse a font metrics item.

Returns:FontMetrics

The parse font metrics item.

Exceptions
IOException:
If there is an error reading the AFM file.
parseIntback to summary
private int parseInt(String intValue) throws IOException
parseIntback to summary
private int parseInt(String intValue, int radix) throws IOException
parseKernDataback to summary
private void parseKernData(FontMetrics fontMetrics) throws IOException

This will parse the kern data.

Parameters
fontMetrics:FontMetrics

The metrics class to put the parsed data into.

Exceptions
IOException:
If there is an error parsing the data.
parseKernPairback to summary
private KernPair parseKernPair() throws IOException

This will parse a kern pair from the data stream.

Returns:KernPair

The kern pair that was parsed from the stream.

Exceptions
IOException:
If there is an error reading from the stream.
parseKernPairsback to summary
private void parseKernPairs(FontMetrics fontMetrics) throws IOException
parseKernPairs0back to summary
private void parseKernPairs0(FontMetrics fontMetrics) throws IOException
parseKernPairs1back to summary
private void parseKernPairs1(FontMetrics fontMetrics) throws IOException
readBooleanback to summary
private boolean readBoolean() throws IOException

This will read a boolean from the stream.

Returns:boolean

The boolean in the stream.

readCommandback to summary
private void readCommand(String expectedCommand) throws IOException

Read the next string. Throw an exception if it differs from the expected command.

Parameters
expectedCommand:String

the expected command

Exceptions
IOException:
IF the read string differs from the expected command
readFloatback to summary
private float readFloat() throws IOException

This will read a float from the stream.

Returns:float

The float in the stream.

readIntback to summary
private int readInt() throws IOException

This will read an integer from the stream.

Returns:int

The integer in the stream.

readLineback to summary
private String readLine() throws IOException

This will read until the end of a line.

Returns:String

The string that is read.

readStringback to summary
private String readString() throws IOException

This will read a string from the input stream and stop at any whitespace.

Returns:String

The string read from the stream.

Exceptions
IOException:
If an IO error occurs when reading from the stream.
verifySemicolonback to summary
private void verifySemicolon(StringTokenizer tokenizer) throws IOException

This is used to verify that a semicolon is the next token in the stream.

Parameters
tokenizer:StringTokenizer

The tokenizer to read from.

Exceptions
IOException:
If the semicolon is missing.