Package org.apache.fontbox.cff
Class CFFParser
- java.lang.Object
-
- org.apache.fontbox.cff.CFFParser
-
public class CFFParser extends java.lang.ObjectThis class represents a parser for a CFF font.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceCFFParser.ByteSourceSource from which bytes may be read in the future.(package private) static classCFFParser.CFFBuiltInEncodingInner class representing a font's built-in CFF encoding.private static classCFFParser.CFFBytesourceAllows bytes to be re-read later by CFFParser.private static classCFFParser.DictDataInner class holding the DictData of a CFF font.private static classCFFParser.EmptyCharsetCIDAn empty charset in a malformed CID font.private static classCFFParser.EmptyCharsetType1An empty charset in a malformed Type1 font.private static classCFFParser.Format0CharsetInner class representing a Format0 charset.private static classCFFParser.Format0EncodingInner class representing a Format0 encoding.private static classCFFParser.Format0FDSelectFormat 0 FDSelect.private static classCFFParser.Format1CharsetInner class representing a Format1 charset.private static classCFFParser.Format1EncodingInner class representing a Format1 encoding.private static classCFFParser.Format2CharsetInner class representing a Format2 charset.private static classCFFParser.Format3FDSelectFormat 3 FDSelect data.private static classCFFParser.HeaderInner class holding the header of a CFF font.private static classCFFParser.Range3Structure of a Range3 element.private static classCFFParser.RangeMappingInner class representing a rang mapping for a CID charset.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringdebugFontNameprivate static org.apache.commons.logging.LogLOGLog instance.private CFFParser.ByteSourcesourceprivate java.lang.String[]stringIndexprivate static java.lang.StringTAG_OTTOprivate static java.lang.StringTAG_TTCFprivate static java.lang.StringTAG_TTFONLY
-
Constructor Summary
Constructors Constructor Description CFFParser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidconcatenateMatrix(java.util.List<java.lang.Number> matrixDest, java.util.List<java.lang.Number> matrixConcat)private DataInputcreateTaggedCFFDataInput(DataInput input)private java.lang.StringgetString(CFFParser.DictData dict, java.lang.String name)java.util.List<CFFFont>parse(byte[] bytes, CFFParser.ByteSource source)Parse CFF font using byte array, also passing in a byte source for future use.private java.util.List<CFFFont>parse(DataInput input)Parse CFF font using a DataInput as input.java.util.List<CFFFont>parse(RandomAccessRead randomAccessRead)Parse CFF font using a RandomAccessRead as input.private voidparseCIDFontDicts(DataInput input, CFFParser.DictData topDict, CFFCIDFont font, int nrOfcharStrings)Parse dictionaries specific to a CIDFont.voidparseFirstSubFontROS(RandomAccessRead randomAccessRead, FontHeaders outHeaders)Extract "Registry", "Ordering" and "Supplement" properties from the first CFF subfont.private CFFFontparseFont(DataInput input, java.lang.String name, byte[] topDictIndex)private CFFCIDFontparseROS(CFFParser.DictData topDict)Extracts Registry, Ordering and Supplement fromtopDict["ROS"].private voidparseType1Dicts(DataInput input, CFFParser.DictData topDict, CFFType1Font font, CFFCharset charset)Parse dictionaries specific to a Type 1-equivalent font.private CFFCharsetreadCharset(DataInput dataInput, int nGlyphs, boolean isCIDFont)private static CFFParser.DictDatareadDictData(DataInput input)private static CFFParser.DictDatareadDictData(DataInput input, int offset, int dictSize)private CFFEncodingreadEncoding(DataInput dataInput, CFFCharset charset)private static CFFParser.DictData.EntryreadEntry(DataInput input)private static FDSelectreadFDSelect(DataInput dataInput, int nGlyphs)Read the FDSelect Data according to the format.private CFFParser.Format0CharsetreadFormat0Charset(DataInput dataInput, int nGlyphs, boolean isCIDFont)private CFFParser.Format0EncodingreadFormat0Encoding(DataInput dataInput, CFFCharset charset, int format)private static CFFParser.Format0FDSelectreadFormat0FDSelect(DataInput dataInput, int nGlyphs)Read the Format 0 of the FDSelect data structure.private CFFParser.Format1CharsetreadFormat1Charset(DataInput dataInput, int nGlyphs, boolean isCIDFont)private CFFParser.Format1EncodingreadFormat1Encoding(DataInput dataInput, CFFCharset charset, int format)private CFFParser.Format2CharsetreadFormat2Charset(DataInput dataInput, int nGlyphs, boolean isCIDFont)private static CFFParser.Format3FDSelectreadFormat3FDSelect(DataInput dataInput)Read the Format 3 of the FDSelect data structure.private static CFFParser.HeaderreadHeader(DataInput input)private static byte[][]readIndexData(DataInput input)private static int[]readIndexDataOffsets(DataInput input)private static java.lang.IntegerreadIntegerNumber(DataInput input, int b0)private static longreadLong(DataInput input)private static intreadOffSize(DataInput input)private static java.lang.StringreadOperator(DataInput input, int b0)private java.util.Map<java.lang.String,java.lang.Object>readPrivateDict(CFFParser.DictData privateDict)private static java.lang.DoublereadRealNumber(DataInput input)private java.lang.StringreadString(int index)private static java.lang.String[]readStringIndexData(DataInput input)private voidreadSupplement(DataInput dataInput, CFFParser.CFFBuiltInEncoding encoding)private static java.lang.StringreadTagName(DataInput input)private DataInputskipHeader(DataInput input)java.lang.StringtoString()
-
-
-
Field Detail
-
LOG
private static final org.apache.commons.logging.Log LOG
Log instance.
-
TAG_OTTO
private static final java.lang.String TAG_OTTO
- See Also:
- Constant Field Values
-
TAG_TTCF
private static final java.lang.String TAG_TTCF
- See Also:
- Constant Field Values
-
TAG_TTFONLY
private static final java.lang.String TAG_TTFONLY
- See Also:
- Constant Field Values
-
stringIndex
private java.lang.String[] stringIndex
-
source
private CFFParser.ByteSource source
-
debugFontName
private java.lang.String debugFontName
-
-
Method Detail
-
parse
public java.util.List<CFFFont> parse(byte[] bytes, CFFParser.ByteSource source) throws java.io.IOException
Parse CFF font using byte array, also passing in a byte source for future use.- Parameters:
bytes- source bytessource- source to re-read bytes from in the future- Returns:
- the parsed CFF fonts
- Throws:
java.io.IOException- If there is an error reading from the stream
-
parse
public java.util.List<CFFFont> parse(RandomAccessRead randomAccessRead) throws java.io.IOException
Parse CFF font using a RandomAccessRead as input.- Parameters:
randomAccessRead- the source to be parsed- Returns:
- the parsed CFF fonts
- Throws:
java.io.IOException- If there is an error reading from the stream
-
parseFirstSubFontROS
public void parseFirstSubFontROS(RandomAccessRead randomAccessRead, FontHeaders outHeaders) throws java.io.IOException
Extract "Registry", "Ordering" and "Supplement" properties from the first CFF subfont.- Parameters:
randomAccessRead- the source to be parsedoutHeaders- where to put results- Throws:
java.io.IOException- If there is an error reading from the stream
-
skipHeader
private DataInput skipHeader(DataInput input) throws java.io.IOException
- Throws:
java.io.IOException
-
parse
private java.util.List<CFFFont> parse(DataInput input) throws java.io.IOException
Parse CFF font using a DataInput as input.- Parameters:
input- the source to be parsed- Throws:
java.io.IOException- If there is an error reading from the stream
-
createTaggedCFFDataInput
private DataInput createTaggedCFFDataInput(DataInput input) throws java.io.IOException
- Throws:
java.io.IOException
-
readTagName
private static java.lang.String readTagName(DataInput input) throws java.io.IOException
- Throws:
java.io.IOException
-
readLong
private static long readLong(DataInput input) throws java.io.IOException
- Throws:
java.io.IOException
-
readOffSize
private static int readOffSize(DataInput input) throws java.io.IOException
- Throws:
java.io.IOException
-
readHeader
private static CFFParser.Header readHeader(DataInput input) throws java.io.IOException
- Throws:
java.io.IOException
-
readIndexDataOffsets
private static int[] readIndexDataOffsets(DataInput input) throws java.io.IOException
- Throws:
java.io.IOException
-
readIndexData
private static byte[][] readIndexData(DataInput input) throws java.io.IOException
- Throws:
java.io.IOException
-
readStringIndexData
private static java.lang.String[] readStringIndexData(DataInput input) throws java.io.IOException
- Throws:
java.io.IOException
-
readDictData
private static CFFParser.DictData readDictData(DataInput input) throws java.io.IOException
- Throws:
java.io.IOException
-
readDictData
private static CFFParser.DictData readDictData(DataInput input, int offset, int dictSize) throws java.io.IOException
- Throws:
java.io.IOException
-
readEntry
private static CFFParser.DictData.Entry readEntry(DataInput input) throws java.io.IOException
- Throws:
java.io.IOException
-
readOperator
private static java.lang.String readOperator(DataInput input, int b0) throws java.io.IOException
- Throws:
java.io.IOException
-
readIntegerNumber
private static java.lang.Integer readIntegerNumber(DataInput input, int b0) throws java.io.IOException
- Throws:
java.io.IOException
-
readRealNumber
private static java.lang.Double readRealNumber(DataInput input) throws java.io.IOException
- Throws:
java.io.IOException
-
parseROS
private CFFCIDFont parseROS(CFFParser.DictData topDict) throws java.io.IOException
Extracts Registry, Ordering and Supplement fromtopDict["ROS"].- Throws:
java.io.IOException
-
parseFont
private CFFFont parseFont(DataInput input, java.lang.String name, byte[] topDictIndex) throws java.io.IOException
- Throws:
java.io.IOException
-
concatenateMatrix
private void concatenateMatrix(java.util.List<java.lang.Number> matrixDest, java.util.List<java.lang.Number> matrixConcat)
-
parseCIDFontDicts
private void parseCIDFontDicts(DataInput input, CFFParser.DictData topDict, CFFCIDFont font, int nrOfcharStrings) throws java.io.IOException
Parse dictionaries specific to a CIDFont.- Throws:
java.io.IOException
-
readPrivateDict
private java.util.Map<java.lang.String,java.lang.Object> readPrivateDict(CFFParser.DictData privateDict)
-
parseType1Dicts
private void parseType1Dicts(DataInput input, CFFParser.DictData topDict, CFFType1Font font, CFFCharset charset) throws java.io.IOException
Parse dictionaries specific to a Type 1-equivalent font.- Throws:
java.io.IOException
-
readString
private java.lang.String readString(int index) throws java.io.IOException- Throws:
java.io.IOException
-
getString
private java.lang.String getString(CFFParser.DictData dict, java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
readEncoding
private CFFEncoding readEncoding(DataInput dataInput, CFFCharset charset) throws java.io.IOException
- Throws:
java.io.IOException
-
readFormat0Encoding
private CFFParser.Format0Encoding readFormat0Encoding(DataInput dataInput, CFFCharset charset, int format) throws java.io.IOException
- Throws:
java.io.IOException
-
readFormat1Encoding
private CFFParser.Format1Encoding readFormat1Encoding(DataInput dataInput, CFFCharset charset, int format) throws java.io.IOException
- Throws:
java.io.IOException
-
readSupplement
private void readSupplement(DataInput dataInput, CFFParser.CFFBuiltInEncoding encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
readFDSelect
private static FDSelect readFDSelect(DataInput dataInput, int nGlyphs) throws java.io.IOException
Read the FDSelect Data according to the format.- Parameters:
dataInput-nGlyphs-- Returns:
- the FDSelect data
- Throws:
java.io.IOException
-
readFormat0FDSelect
private static CFFParser.Format0FDSelect readFormat0FDSelect(DataInput dataInput, int nGlyphs) throws java.io.IOException
Read the Format 0 of the FDSelect data structure.- Parameters:
dataInput-nGlyphs-- Returns:
- the Format 0 of the FDSelect data
- Throws:
java.io.IOException
-
readFormat3FDSelect
private static CFFParser.Format3FDSelect readFormat3FDSelect(DataInput dataInput) throws java.io.IOException
Read the Format 3 of the FDSelect data structure.- Parameters:
dataInput-- Returns:
- the Format 3 of the FDSelect data
- Throws:
java.io.IOException
-
readCharset
private CFFCharset readCharset(DataInput dataInput, int nGlyphs, boolean isCIDFont) throws java.io.IOException
- Throws:
java.io.IOException
-
readFormat0Charset
private CFFParser.Format0Charset readFormat0Charset(DataInput dataInput, int nGlyphs, boolean isCIDFont) throws java.io.IOException
- Throws:
java.io.IOException
-
readFormat1Charset
private CFFParser.Format1Charset readFormat1Charset(DataInput dataInput, int nGlyphs, boolean isCIDFont) throws java.io.IOException
- Throws:
java.io.IOException
-
readFormat2Charset
private CFFParser.Format2Charset readFormat2Charset(DataInput dataInput, int nGlyphs, boolean isCIDFont) throws java.io.IOException
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-