Package org.apache.fontbox.afm
Class AFMParser
- java.lang.Object
-
- org.apache.fontbox.afm.AFMParser
-
public class AFMParser extends java.lang.ObjectThis class is used to parse AFM(Adobe Font Metrics) documents.- See Also:
- AFM Documentation
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringASCENDERThis is ascender attribute.private static intBITS_IN_HEXstatic java.lang.StringCAP_HEIGHTThis is the cap height attribute.static java.lang.StringCCThis is a composite character.static java.lang.StringCHAR_WIDTHThis is the char width.static java.lang.StringCHARACTER_SETThis is the character set.static java.lang.StringCHARACTERSThis is the characters attribute.static java.lang.StringCHARMETRICS_BThe character metrics value.static java.lang.StringCHARMETRICS_CThe character metrics c value.static java.lang.StringCHARMETRICS_CHThe character metrics c value.static java.lang.StringCHARMETRICS_LThe character metrics value.static java.lang.StringCHARMETRICS_NThe character metrics value.static java.lang.StringCHARMETRICS_VVThe character metrics value.static java.lang.StringCHARMETRICS_WThe character metrics value.static java.lang.StringCHARMETRICS_W0The character metrics value.static java.lang.StringCHARMETRICS_W0XThe character metrics value.static java.lang.StringCHARMETRICS_W0YThe character metrics value.static java.lang.StringCHARMETRICS_W1The character metrics value.static java.lang.StringCHARMETRICS_W1XThe character metrics value.static java.lang.StringCHARMETRICS_W1YThe character metrics value.static java.lang.StringCHARMETRICS_WXThe character metrics value.static java.lang.StringCHARMETRICS_WYThe character metrics value.static java.lang.StringCOMMENTThis is a comment in a AFM file.static java.lang.StringDESCENDERThis is the descender attribute.static java.lang.StringENCODING_SCHEMEThis is the encoding scheme.static java.lang.StringEND_CHAR_METRICSThis is the end of character metrics.static java.lang.StringEND_COMPOSITESThis is the end composites data section.static java.lang.StringEND_FONT_METRICSThis is the constant used in the AFM file to end a font metrics item.static java.lang.StringEND_KERN_DATAThis is the end of kern data.static java.lang.StringEND_KERN_PAIRSThis is the end of kern pairs data.static java.lang.StringEND_TRACK_KERNThis is the end of track kern data.static java.lang.StringESC_CHARThis is the escape character.static java.lang.StringFAMILY_NAMEThis is the Family name.static java.lang.StringFONT_BBOXThis is the font bounding box.static java.lang.StringFONT_NAMEThis is the font name.static java.lang.StringFULL_NAMEThis is the full name.private java.io.InputStreaminputstatic java.lang.StringIS_BASE_FONTThis will determine if this is a base font.static java.lang.StringIS_FIXED_PITCHThis will determine if this is fixed pitch.static java.lang.StringIS_FIXED_VThis will tell if the V is fixed.static java.lang.StringITALIC_ANGLEThis is the italic angle.static java.lang.StringKERN_PAIR_KPThis is a kern pair.static java.lang.StringKERN_PAIR_KPHThis is a kern pair.static java.lang.StringKERN_PAIR_KPXThis is a kern pair.static java.lang.StringKERN_PAIR_KPYThis is a kern pair.static java.lang.StringMAPPING_SCHEMEThis is the mapping scheme.static java.lang.StringNOTICEThis is the notice.static java.lang.StringPCCThis is a composite character part.static java.lang.StringSTART_CHAR_METRICSThis is the start of character metrics.static java.lang.StringSTART_COMPOSITESThis is the start composites data section.static java.lang.StringSTART_FONT_METRICSThis is the constant used in the AFM file to start a font metrics item.static java.lang.StringSTART_KERN_DATAThis is the start of kern data.static java.lang.StringSTART_KERN_PAIRSThis is the start of kern pairs data.static java.lang.StringSTART_KERN_PAIRS0This is the start of kern pairs data.static java.lang.StringSTART_KERN_PAIRS1This is the start of kern pairs data.static java.lang.StringSTART_TRACK_KERNThis is the start of track kern data.static java.lang.StringSTD_HWThe character metrics value.static java.lang.StringSTD_VWThe character metrics value.static java.lang.StringUNDERLINE_POSITIONThe underline position.static java.lang.StringUNDERLINE_THICKNESSThis is the Underline thickness.static java.lang.StringV_VECTORThis is the V Vector attribute.static java.lang.StringVERSIONThis is the version of the font.static java.lang.StringWEIGHTThis is the weight.static java.lang.StringX_HEIGHTThis is the X height.
-
Constructor Summary
Constructors Constructor Description AFMParser(java.io.InputStream in)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.StringhexToString(java.lang.String hexToString)This will convert and angle bracket hex string to a string.private static booleanisEOL(int character)This will determine if the byte is a whitespace character or not.private static booleanisWhitespace(int character)This will determine if the byte is a whitespace character or not.FontMetricsparse()This will parse the AFM document.FontMetricsparse(boolean reducedDataset)This will parse the AFM document.private CharMetricparseCharMetric()This will parse a single CharMetric object from the stream.private booleanparseCharMetrics(FontMetrics fontMetrics)private CompositeparseComposite()This will parse a composite part from the stream.private voidparseComposites(FontMetrics fontMetrics)private floatparseFloat(java.lang.String floatValue)private FontMetricsparseFontMetric(boolean reducedDataset)This will parse a font metrics item.private intparseInt(java.lang.String intValue)private intparseInt(java.lang.String intValue, int radix)private voidparseKernData(FontMetrics fontMetrics)This will parse the kern data.private KernPairparseKernPair()This will parse a kern pair from the data stream.private voidparseKernPairs(FontMetrics fontMetrics)private voidparseKernPairs0(FontMetrics fontMetrics)private voidparseKernPairs1(FontMetrics fontMetrics)private booleanreadBoolean()This will read a boolean from the stream.private voidreadCommand(java.lang.String expectedCommand)Read the next string.private floatreadFloat()This will read a float from the stream.private intreadInt()This will read an integer from the stream.private java.lang.StringreadLine()This will read until the end of a line.private java.lang.StringreadString()This will read a string from the input stream and stop at any whitespace.private voidverifySemicolon(java.util.StringTokenizer tokenizer)This is used to verify that a semicolon is the next token in the stream.
-
-
-
Field Detail
-
COMMENT
public static final java.lang.String COMMENT
This is a comment in a AFM file.- See Also:
- Constant Field Values
-
START_FONT_METRICS
public static final java.lang.String START_FONT_METRICS
This is the constant used in the AFM file to start a font metrics item.- See Also:
- Constant Field Values
-
END_FONT_METRICS
public static final java.lang.String END_FONT_METRICS
This is the constant used in the AFM file to end a font metrics item.- See Also:
- Constant Field Values
-
FONT_NAME
public static final java.lang.String FONT_NAME
This is the font name.- See Also:
- Constant Field Values
-
FULL_NAME
public static final java.lang.String FULL_NAME
This is the full name.- See Also:
- Constant Field Values
-
FAMILY_NAME
public static final java.lang.String FAMILY_NAME
This is the Family name.- See Also:
- Constant Field Values
-
WEIGHT
public static final java.lang.String WEIGHT
This is the weight.- See Also:
- Constant Field Values
-
FONT_BBOX
public static final java.lang.String FONT_BBOX
This is the font bounding box.- See Also:
- Constant Field Values
-
VERSION
public static final java.lang.String VERSION
This is the version of the font.- See Also:
- Constant Field Values
-
NOTICE
public static final java.lang.String NOTICE
This is the notice.- See Also:
- Constant Field Values
-
ENCODING_SCHEME
public static final java.lang.String ENCODING_SCHEME
This is the encoding scheme.- See Also:
- Constant Field Values
-
MAPPING_SCHEME
public static final java.lang.String MAPPING_SCHEME
This is the mapping scheme.- See Also:
- Constant Field Values
-
ESC_CHAR
public static final java.lang.String ESC_CHAR
This is the escape character.- See Also:
- Constant Field Values
-
CHARACTER_SET
public static final java.lang.String CHARACTER_SET
This is the character set.- See Also:
- Constant Field Values
-
CHARACTERS
public static final java.lang.String CHARACTERS
This is the characters attribute.- See Also:
- Constant Field Values
-
IS_BASE_FONT
public static final java.lang.String IS_BASE_FONT
This will determine if this is a base font.- See Also:
- Constant Field Values
-
V_VECTOR
public static final java.lang.String V_VECTOR
This is the V Vector attribute.- See Also:
- Constant Field Values
-
IS_FIXED_V
public static final java.lang.String IS_FIXED_V
This will tell if the V is fixed.- See Also:
- Constant Field Values
-
CAP_HEIGHT
public static final java.lang.String CAP_HEIGHT
This is the cap height attribute.- See Also:
- Constant Field Values
-
X_HEIGHT
public static final java.lang.String X_HEIGHT
This is the X height.- See Also:
- Constant Field Values
-
ASCENDER
public static final java.lang.String ASCENDER
This is ascender attribute.- See Also:
- Constant Field Values
-
DESCENDER
public static final java.lang.String DESCENDER
This is the descender attribute.- See Also:
- Constant Field Values
-
UNDERLINE_POSITION
public static final java.lang.String UNDERLINE_POSITION
The underline position.- See Also:
- Constant Field Values
-
UNDERLINE_THICKNESS
public static final java.lang.String UNDERLINE_THICKNESS
This is the Underline thickness.- See Also:
- Constant Field Values
-
ITALIC_ANGLE
public static final java.lang.String ITALIC_ANGLE
This is the italic angle.- See Also:
- Constant Field Values
-
CHAR_WIDTH
public static final java.lang.String CHAR_WIDTH
This is the char width.- See Also:
- Constant Field Values
-
IS_FIXED_PITCH
public static final java.lang.String IS_FIXED_PITCH
This will determine if this is fixed pitch.- See Also:
- Constant Field Values
-
START_CHAR_METRICS
public static final java.lang.String START_CHAR_METRICS
This is the start of character metrics.- See Also:
- Constant Field Values
-
END_CHAR_METRICS
public static final java.lang.String END_CHAR_METRICS
This is the end of character metrics.- See Also:
- Constant Field Values
-
CHARMETRICS_C
public static final java.lang.String CHARMETRICS_C
The character metrics c value.- See Also:
- Constant Field Values
-
CHARMETRICS_CH
public static final java.lang.String CHARMETRICS_CH
The character metrics c value.- See Also:
- Constant Field Values
-
CHARMETRICS_WX
public static final java.lang.String CHARMETRICS_WX
The character metrics value.- See Also:
- Constant Field Values
-
CHARMETRICS_W0X
public static final java.lang.String CHARMETRICS_W0X
The character metrics value.- See Also:
- Constant Field Values
-
CHARMETRICS_W1X
public static final java.lang.String CHARMETRICS_W1X
The character metrics value.- See Also:
- Constant Field Values
-
CHARMETRICS_WY
public static final java.lang.String CHARMETRICS_WY
The character metrics value.- See Also:
- Constant Field Values
-
CHARMETRICS_W0Y
public static final java.lang.String CHARMETRICS_W0Y
The character metrics value.- See Also:
- Constant Field Values
-
CHARMETRICS_W1Y
public static final java.lang.String CHARMETRICS_W1Y
The character metrics value.- See Also:
- Constant Field Values
-
CHARMETRICS_W
public static final java.lang.String CHARMETRICS_W
The character metrics value.- See Also:
- Constant Field Values
-
CHARMETRICS_W0
public static final java.lang.String CHARMETRICS_W0
The character metrics value.- See Also:
- Constant Field Values
-
CHARMETRICS_W1
public static final java.lang.String CHARMETRICS_W1
The character metrics value.- See Also:
- Constant Field Values
-
CHARMETRICS_VV
public static final java.lang.String CHARMETRICS_VV
The character metrics value.- See Also:
- Constant Field Values
-
CHARMETRICS_N
public static final java.lang.String CHARMETRICS_N
The character metrics value.- See Also:
- Constant Field Values
-
CHARMETRICS_B
public static final java.lang.String CHARMETRICS_B
The character metrics value.- See Also:
- Constant Field Values
-
CHARMETRICS_L
public static final java.lang.String CHARMETRICS_L
The character metrics value.- See Also:
- Constant Field Values
-
STD_HW
public static final java.lang.String STD_HW
The character metrics value.- See Also:
- Constant Field Values
-
STD_VW
public static final java.lang.String STD_VW
The character metrics value.- See Also:
- Constant Field Values
-
START_TRACK_KERN
public static final java.lang.String START_TRACK_KERN
This is the start of track kern data.- See Also:
- Constant Field Values
-
END_TRACK_KERN
public static final java.lang.String END_TRACK_KERN
This is the end of track kern data.- See Also:
- Constant Field Values
-
START_KERN_DATA
public static final java.lang.String START_KERN_DATA
This is the start of kern data.- See Also:
- Constant Field Values
-
END_KERN_DATA
public static final java.lang.String END_KERN_DATA
This is the end of kern data.- See Also:
- Constant Field Values
-
START_KERN_PAIRS
public static final java.lang.String START_KERN_PAIRS
This is the start of kern pairs data.- See Also:
- Constant Field Values
-
END_KERN_PAIRS
public static final java.lang.String END_KERN_PAIRS
This is the end of kern pairs data.- See Also:
- Constant Field Values
-
START_KERN_PAIRS0
public static final java.lang.String START_KERN_PAIRS0
This is the start of kern pairs data.- See Also:
- Constant Field Values
-
START_KERN_PAIRS1
public static final java.lang.String START_KERN_PAIRS1
This is the start of kern pairs data.- See Also:
- Constant Field Values
-
START_COMPOSITES
public static final java.lang.String START_COMPOSITES
This is the start composites data section.- See Also:
- Constant Field Values
-
END_COMPOSITES
public static final java.lang.String END_COMPOSITES
This is the end composites data section.- See Also:
- Constant Field Values
-
CC
public static final java.lang.String CC
This is a composite character.- See Also:
- Constant Field Values
-
PCC
public static final java.lang.String PCC
This is a composite character part.- See Also:
- Constant Field Values
-
KERN_PAIR_KP
public static final java.lang.String KERN_PAIR_KP
This is a kern pair.- See Also:
- Constant Field Values
-
KERN_PAIR_KPH
public static final java.lang.String KERN_PAIR_KPH
This is a kern pair.- See Also:
- Constant Field Values
-
KERN_PAIR_KPX
public static final java.lang.String KERN_PAIR_KPX
This is a kern pair.- See Also:
- Constant Field Values
-
KERN_PAIR_KPY
public static final java.lang.String KERN_PAIR_KPY
This is a kern pair.- See Also:
- Constant Field Values
-
BITS_IN_HEX
private static final int BITS_IN_HEX
- See Also:
- Constant Field Values
-
input
private final java.io.InputStream input
-
-
Method Detail
-
parse
public FontMetrics parse() throws java.io.IOException
This will parse the AFM document. The input stream is closed when the parsing is finished.- Returns:
- the parsed FontMetric
- Throws:
java.io.IOException- If there is an IO error reading the document.
-
parse
public FontMetrics parse(boolean reducedDataset) throws java.io.IOException
This will parse the AFM document. The input stream is closed when the parsing is finished.- Parameters:
reducedDataset- parse a reduced subset of data if set to true- Returns:
- the parsed FontMetric
- Throws:
java.io.IOException- If there is an IO error reading the document.
-
parseFontMetric
private FontMetrics parseFontMetric(boolean reducedDataset) throws java.io.IOException
This will parse a font metrics item.- Returns:
- The parse font metrics item.
- Throws:
java.io.IOException- If there is an error reading the AFM file.
-
parseKernData
private void parseKernData(FontMetrics fontMetrics) throws java.io.IOException
This will parse the kern data.- Parameters:
fontMetrics- The metrics class to put the parsed data into.- Throws:
java.io.IOException- If there is an error parsing the data.
-
parseKernPairs
private void parseKernPairs(FontMetrics fontMetrics) throws java.io.IOException
- Throws:
java.io.IOException
-
parseKernPairs0
private void parseKernPairs0(FontMetrics fontMetrics) throws java.io.IOException
- Throws:
java.io.IOException
-
parseKernPairs1
private void parseKernPairs1(FontMetrics fontMetrics) throws java.io.IOException
- Throws:
java.io.IOException
-
parseKernPair
private KernPair parseKernPair() throws java.io.IOException
This will parse a kern pair from the data stream.- Returns:
- The kern pair that was parsed from the stream.
- Throws:
java.io.IOException- If there is an error reading from the stream.
-
hexToString
private java.lang.String hexToString(java.lang.String hexToString) throws java.io.IOExceptionThis will convert and angle bracket hex string to a string.- Parameters:
hexToString- An angle bracket string.- Returns:
- The bytes of the hex string.
- Throws:
java.io.IOException- If the string is in an invalid format.
-
parseComposites
private void parseComposites(FontMetrics fontMetrics) throws java.io.IOException
- Throws:
java.io.IOException
-
parseComposite
private Composite parseComposite() throws java.io.IOException
This will parse a composite part from the stream.- Returns:
- The composite.
- Throws:
java.io.IOException- If there is an error parsing the composite.
-
parseCharMetrics
private boolean parseCharMetrics(FontMetrics fontMetrics) throws java.io.IOException
- Throws:
java.io.IOException
-
parseCharMetric
private CharMetric parseCharMetric() throws java.io.IOException
This will parse a single CharMetric object from the stream.- Returns:
- The next char metric in the stream.
- Throws:
java.io.IOException- If there is an error reading from the stream.
-
verifySemicolon
private void verifySemicolon(java.util.StringTokenizer tokenizer) throws java.io.IOExceptionThis is used to verify that a semicolon is the next token in the stream.- Parameters:
tokenizer- The tokenizer to read from.- Throws:
java.io.IOException- If the semicolon is missing.
-
readBoolean
private boolean readBoolean() throws java.io.IOExceptionThis will read a boolean from the stream.- Returns:
- The boolean in the stream.
- Throws:
java.io.IOException
-
readInt
private int readInt() throws java.io.IOExceptionThis will read an integer from the stream.- Returns:
- The integer in the stream.
- Throws:
java.io.IOException
-
parseInt
private int parseInt(java.lang.String intValue) throws java.io.IOException- Throws:
java.io.IOException
-
parseInt
private int parseInt(java.lang.String intValue, int radix) throws java.io.IOException- Throws:
java.io.IOException
-
readFloat
private float readFloat() throws java.io.IOExceptionThis will read a float from the stream.- Returns:
- The float in the stream.
- Throws:
java.io.IOException
-
parseFloat
private float parseFloat(java.lang.String floatValue) throws java.io.IOException- Throws:
java.io.IOException
-
readLine
private java.lang.String readLine() throws java.io.IOExceptionThis will read until the end of a line.- Returns:
- The string that is read.
- Throws:
java.io.IOException
-
readString
private java.lang.String readString() throws java.io.IOExceptionThis will read a string from the input stream and stop at any whitespace.- Returns:
- The string read from the stream.
- Throws:
java.io.IOException- If an IO error occurs when reading from the stream.
-
readCommand
private void readCommand(java.lang.String expectedCommand) throws java.io.IOExceptionRead the next string. Throw an exception if it differs from the expected command.- Parameters:
expectedCommand- the expected command- Throws:
java.io.IOException- IF the read string differs from the expected command
-
isEOL
private static boolean isEOL(int character)
This will determine if the byte is a whitespace character or not.- Parameters:
character- The character to test for whitespace.- Returns:
- true If the character is whitespace as defined by the AFM spec.
-
isWhitespace
private static boolean isWhitespace(int character)
This will determine if the byte is a whitespace character or not.- Parameters:
character- The character to test for whitespace.- Returns:
- true If the character is whitespace as defined by the AFM spec.
-
-