Package com.itextpdf.io.font
Class OpenTypeParser
- java.lang.Object
-
- com.itextpdf.io.font.OpenTypeParser
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
class OpenTypeParser extends java.lang.Object implements java.io.Closeable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classOpenTypeParser.CmapTable(package private) static classOpenTypeParser.HeaderTableThe components of table 'head'.(package private) static classOpenTypeParser.HorizontalHeaderThe components of table 'hhea'.(package private) static classOpenTypeParser.PostTable(package private) static classOpenTypeParser.WindowsMetricsThe components of table 'OS/2'.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.Integer,java.util.List<java.lang.String[]>>allNameEntriesAll the names of the Names-Table.protected booleancffIndicate, that the font contains 'CFF ' table.protected intcffLengthLength of 'CFF ' table.protected intcffOffsetOffset to 'CFF ' table.protected OpenTypeParser.CmapTablecmapsprotected intdirectoryOffsetThe offset from the start of the file to the table directory.protected java.lang.StringfileNameThe file name.protected java.lang.StringfontNameThe font name.private int[]glyphWidthsByIndexprotected OpenTypeParser.HeaderTableheadprivate static intHEAD_LOCA_FORMAT_OFFSETprotected OpenTypeParser.HorizontalHeaderhheaprotected OpenTypeParser.WindowsMetricsos_2protected OpenTypeParser.PostTablepostprotected RandomAccessFileOrArrayrafThe file in use.protected java.util.Map<java.lang.String,int[]>tablesContains the location of the several tables.protected intttcIndexThe index for the TTC font.
-
Constructor Summary
Constructors Constructor Description OpenTypeParser(byte[] ttf)OpenTypeParser(byte[] ttc, int ttcIndex)OpenTypeParser(java.lang.String name)OpenTypeParser(java.lang.String ttcPath, int ttcIndex)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckCff()voidclose()java.util.Map<java.lang.Integer,java.util.List<java.lang.String[]>>getAllNameEntries()OpenTypeParser.CmapTablegetCmapTable()FontNamesgetFontNames()byte[]getFullFont()protected intgetGlyphWidth(int glyph)Gets a glyph width.int[]getGlyphWidthsByIndex()OpenTypeParser.HeaderTablegetHeadTable()OpenTypeParser.HorizontalHeadergetHheaTable()OpenTypeParser.WindowsMetricsgetOs_2Table()OpenTypeParser.PostTablegetPostTable()java.lang.StringgetPsFontName()Gets the Postscript font name.(package private) byte[]getSubset(java.util.Set<java.lang.Integer> glyphs, boolean subset)protected static java.lang.StringgetTTCName(java.lang.String name)Gets the name from a composed TTC file name.private voidinitializeSfntTables()booleanisCff()protected voidloadTables(boolean all)Reads the font data.protected int[][]readBbox(int unitsPerEm)Read the glyf bboxes from 'glyf' table.byte[]readCffFont()If this font file is using the Compact Font File Format, then this method will return the raw bytes needed for the font stream.private voidreadCmapTable()Reads the several maps from the table 'cmap'.private java.util.Map<java.lang.Integer,int[]>readFormat0()The information in the maps of the table 'cmap' is coded in several formats.private java.util.Map<java.lang.Integer,int[]>readFormat12()private java.util.Map<java.lang.Integer,int[]>readFormat4(boolean fontSpecific)The information in the maps of the table 'cmap' is coded in several formats.private java.util.Map<java.lang.Integer,int[]>readFormat6()The information in the maps of the table 'cmap' is coded in several formats.protected voidreadGlyphWidths()Reads the glyphs widths.private voidreadHeadTable()Read font header, table 'head'.private voidreadHheaTable()Read horizontal header, table 'hhea'.protected IntHashtablereadKerning(int unitsPerEm)Reads the kerning information from the 'kern' table.private voidreadNameTable()Extracts the names of the font in all the languages available.protected intreadNumGlyphs()private voidreadOs_2Table()Reads the windows metrics table.private voidreadPostTable()private java.lang.StringreadStandardString(int length)Reads aStringfrom the font file as bytes using the Cp1252 encoding.private java.lang.StringreadUnicodeString(int length)Reads a UnicodeStringfrom the font file.
-
-
-
Field Detail
-
HEAD_LOCA_FORMAT_OFFSET
private static final int HEAD_LOCA_FORMAT_OFFSET
- See Also:
- Constant Field Values
-
fileName
protected java.lang.String fileName
The file name.
-
raf
protected RandomAccessFileOrArray raf
The file in use.
-
ttcIndex
protected int ttcIndex
The index for the TTC font. It is -1intfor a TTF file.
-
directoryOffset
protected int directoryOffset
The offset from the start of the file to the table directory. It is 0 for TTF and may vary for TTC depending on the chosen font.
-
fontName
protected java.lang.String fontName
The font name. This name is usually extracted from the table 'name' with the 'Name ID' 6.
-
allNameEntries
protected java.util.Map<java.lang.Integer,java.util.List<java.lang.String[]>> allNameEntries
All the names of the Names-Table.
-
cff
protected boolean cff
Indicate, that the font contains 'CFF ' table.
-
cffOffset
protected int cffOffset
Offset to 'CFF ' table.
-
cffLength
protected int cffLength
Length of 'CFF ' table.
-
glyphWidthsByIndex
private int[] glyphWidthsByIndex
-
head
protected OpenTypeParser.HeaderTable head
-
hhea
protected OpenTypeParser.HorizontalHeader hhea
-
os_2
protected OpenTypeParser.WindowsMetrics os_2
-
post
protected OpenTypeParser.PostTable post
-
cmaps
protected OpenTypeParser.CmapTable cmaps
-
tables
protected java.util.Map<java.lang.String,int[]> tables
Contains the location of the several tables. The key is the name of the table and the value is anint[2]where position 0 is the offset from the start of the file and position 1 is the length of the table.
-
-
Constructor Detail
-
OpenTypeParser
public OpenTypeParser(byte[] ttf) throws java.io.IOException- Throws:
java.io.IOException
-
OpenTypeParser
public OpenTypeParser(byte[] ttc, int ttcIndex) throws java.io.IOException- Throws:
java.io.IOException
-
OpenTypeParser
public OpenTypeParser(java.lang.String ttcPath, int ttcIndex) throws java.io.IOException- Throws:
java.io.IOException
-
OpenTypeParser
public OpenTypeParser(java.lang.String name) throws java.io.IOException- Throws:
java.io.IOException
-
-
Method Detail
-
getPsFontName
public java.lang.String getPsFontName()
Gets the Postscript font name.
-
getAllNameEntries
public java.util.Map<java.lang.Integer,java.util.List<java.lang.String[]>> getAllNameEntries()
-
getPostTable
public OpenTypeParser.PostTable getPostTable()
-
getOs_2Table
public OpenTypeParser.WindowsMetrics getOs_2Table()
-
getHheaTable
public OpenTypeParser.HorizontalHeader getHheaTable()
-
getHeadTable
public OpenTypeParser.HeaderTable getHeadTable()
-
getCmapTable
public OpenTypeParser.CmapTable getCmapTable()
-
getGlyphWidthsByIndex
public int[] getGlyphWidthsByIndex()
-
getFontNames
public FontNames getFontNames()
-
isCff
public boolean isCff()
-
getFullFont
public byte[] getFullFont() throws java.io.IOException- Throws:
java.io.IOException
-
readCffFont
public byte[] readCffFont() throws java.io.IOExceptionIf this font file is using the Compact Font File Format, then this method will return the raw bytes needed for the font stream. If this method is ever made public: make sure to add a test if (cff == true).- Returns:
- a byte array
- Throws:
java.io.IOException
-
getSubset
byte[] getSubset(java.util.Set<java.lang.Integer> glyphs, boolean subset) throws java.io.IOException- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
initializeSfntTables
private void initializeSfntTables() throws java.io.IOException- Throws:
java.io.IOException
-
loadTables
protected void loadTables(boolean all) throws java.io.IOExceptionReads the font data.- Parameters:
all- iftrue, all tables will be read, otherwise only 'head', 'name', and 'os/2'- Throws:
java.io.IOException
-
getTTCName
protected static java.lang.String getTTCName(java.lang.String name)
Gets the name from a composed TTC file name. If I have for input "myfont.ttc,2" the return will be "myfont.ttc".- Parameters:
name- the full name- Returns:
- the simple file name
-
checkCff
protected void checkCff()
-
readGlyphWidths
protected void readGlyphWidths() throws java.io.IOExceptionReads the glyphs widths. The widths are extracted from the table 'hmtx'. The glyphs are normalized to 1000 units (TrueTypeFont.UNITS_NORMALIZATION). Depends onOpenTypeParser.HorizontalHeader.numberOfHMetricsandOpenTypeParser.HeaderTable.unitsPerEm.- Throws:
java.io.IOException- the font file could not be read.
-
readKerning
protected IntHashtable readKerning(int unitsPerEm) throws java.io.IOException
Reads the kerning information from the 'kern' table.- Parameters:
unitsPerEm-OpenTypeParser.HeaderTable.unitsPerEm.- Throws:
java.io.IOException- the font file could not be read
-
readBbox
protected int[][] readBbox(int unitsPerEm) throws java.io.IOExceptionRead the glyf bboxes from 'glyf' table.- Parameters:
unitsPerEm-OpenTypeParser.HeaderTable.unitsPerEm- Throws:
IOException- the font is invalidjava.io.IOException- the font file could not be read
-
readNumGlyphs
protected int readNumGlyphs() throws java.io.IOException- Throws:
java.io.IOException
-
readNameTable
private void readNameTable() throws java.io.IOExceptionExtracts the names of the font in all the languages available.- Throws:
IOException- on errorjava.io.IOException- on error
-
readHheaTable
private void readHheaTable() throws java.io.IOExceptionRead horizontal header, table 'hhea'.- Throws:
IOException- the font is invalid.java.io.IOException- the font file could not be read.
-
readHeadTable
private void readHeadTable() throws java.io.IOExceptionRead font header, table 'head'.- Throws:
IOException- the font is invalid.java.io.IOException- the font file could not be read.
-
readOs_2Table
private void readOs_2Table() throws java.io.IOExceptionReads the windows metrics table. The metrics are extracted from the table 'OS/2'. Depends onOpenTypeParser.HeaderTable.unitsPerEmproperty.- Throws:
IOException- the font is invalid.java.io.IOException- the font file could not be read.
-
readPostTable
private void readPostTable() throws java.io.IOException- Throws:
java.io.IOException
-
readCmapTable
private void readCmapTable() throws java.io.IOExceptionReads the several maps from the table 'cmap'. The maps of interest are 1.0 for symbolic fonts and 3.1 for all others. A symbolic font is defined as having the map 3.0. Depends fromreadGlyphWidths().- Throws:
java.io.IOException- the font file could not be read
-
readStandardString
private java.lang.String readStandardString(int length) throws java.io.IOExceptionReads aStringfrom the font file as bytes using the Cp1252 encoding.- Parameters:
length- the length of bytes to read- Returns:
- the
Stringread - Throws:
java.io.IOException- the font file could not be read
-
readUnicodeString
private java.lang.String readUnicodeString(int length) throws java.io.IOExceptionReads a UnicodeStringfrom the font file. Each character is represented by two bytes.- Parameters:
length- the length of bytes to read. TheStringwill havelength/2 characters.- Returns:
- the
Stringread. - Throws:
java.io.IOException- the font file could not be read.
-
getGlyphWidth
protected int getGlyphWidth(int glyph)
Gets a glyph width.- Parameters:
glyph- the glyph to get the width of- Returns:
- the width of the glyph in normalized 1000 units (TrueTypeFont.UNITS_NORMALIZATION)
-
readFormat0
private java.util.Map<java.lang.Integer,int[]> readFormat0() throws java.io.IOExceptionThe information in the maps of the table 'cmap' is coded in several formats. Format 0 is the Apple standard character to glyph index mapping table.- Returns:
- a
HashMaprepresenting this map - Throws:
java.io.IOException- the font file could not be read
-
readFormat4
private java.util.Map<java.lang.Integer,int[]> readFormat4(boolean fontSpecific) throws java.io.IOExceptionThe information in the maps of the table 'cmap' is coded in several formats. Format 4 is the Microsoft standard character to glyph index mapping table.- Returns:
- a
HashMaprepresenting this map - Throws:
java.io.IOException- the font file could not be read
-
readFormat6
private java.util.Map<java.lang.Integer,int[]> readFormat6() throws java.io.IOExceptionThe information in the maps of the table 'cmap' is coded in several formats. Format 6 is a trimmed table mapping. It is similar to format 0 but can have less than 256 entries.- Returns:
- a
HashMaprepresenting this map - Throws:
java.io.IOException- the font file could not be read
-
readFormat12
private java.util.Map<java.lang.Integer,int[]> readFormat12() throws java.io.IOException- Throws:
java.io.IOException
-
-