Package com.itextpdf.io.font
Class OpenTypeParser
java.lang.Object
com.itextpdf.io.font.OpenTypeParser
- All Implemented Interfaces:
Closeable
,AutoCloseable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
(package private) static class
The components of table 'head'.(package private) static class
The components of table 'hhea'.(package private) static class
(package private) static class
The components of table 'OS/2'. -
Field Summary
FieldsModifier and TypeFieldDescriptionAll the names of the Names-Table.protected boolean
Indicate, that the font contains 'CFF ' table.protected int
Length of 'CFF ' table.protected int
Offset to 'CFF ' table.protected OpenTypeParser.CmapTable
protected int
The offset from the start of the file to the table directory.protected String
The file name.protected String
The font name.private int[]
protected OpenTypeParser.HeaderTable
private static final int
protected OpenTypeParser.HorizontalHeader
protected OpenTypeParser.WindowsMetrics
protected OpenTypeParser.PostTable
protected RandomAccessFileOrArray
The file in use.Contains the location of the several tables.protected int
The index for the TTC font. -
Constructor Summary
ConstructorsConstructorDescriptionOpenTypeParser
(byte[] ttf) OpenTypeParser
(byte[] ttc, int ttcIndex) OpenTypeParser
(String name) OpenTypeParser
(String ttcPath, int ttcIndex) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkCff()
void
close()
byte[]
protected int
getGlyphWidth
(int glyph) Gets a glyph width.int[]
Gets the Postscript font name.(package private) byte[]
protected static String
getTTCName
(String name) Gets the name from a composed TTC file name.private void
boolean
isCff()
protected void
loadTables
(boolean all) Reads the font data.protected int[][]
readBbox
(int unitsPerEm) Read the glyf bboxes from 'glyf' table.byte[]
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 void
Reads the several maps from the table 'cmap'.The information in the maps of the table 'cmap' is coded in several formats.readFormat4
(boolean fontSpecific) The information in the maps of the table 'cmap' is coded in several formats.The information in the maps of the table 'cmap' is coded in several formats.protected void
Reads the glyphs widths.private void
Read font header, table 'head'.private void
Read horizontal header, table 'hhea'.protected IntHashtable
readKerning
(int unitsPerEm) Reads the kerning information from the 'kern' table.private void
Extracts the names of the font in all the languages available.protected int
private void
Reads the windows metrics table.private void
private String
readStandardString
(int length) Reads aString
from the font file as bytes using the Cp1252 encoding.private String
readUnicodeString
(int length) Reads a UnicodeString
from the font file.
-
Field Details
-
HEAD_LOCA_FORMAT_OFFSET
private static final int HEAD_LOCA_FORMAT_OFFSET- See Also:
-
fileName
The file name. -
raf
The file in use. -
ttcIndex
protected int ttcIndexThe index for the TTC font. It is -1int
for a TTF file. -
directoryOffset
protected int directoryOffsetThe 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
The font name. This name is usually extracted from the table 'name' with the 'Name ID' 6. -
allNameEntries
All the names of the Names-Table. -
cff
protected boolean cffIndicate, that the font contains 'CFF ' table. -
cffOffset
protected int cffOffsetOffset to 'CFF ' table. -
cffLength
protected int cffLengthLength of 'CFF ' table. -
glyphWidthsByIndex
private int[] glyphWidthsByIndex -
head
-
hhea
-
os_2
-
post
-
cmaps
-
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 Details
-
OpenTypeParser
- Throws:
IOException
-
OpenTypeParser
- Throws:
IOException
-
OpenTypeParser
- Throws:
IOException
-
OpenTypeParser
- Throws:
IOException
-
-
Method Details
-
getPsFontName
Gets the Postscript font name. -
getAllNameEntries
-
getPostTable
-
getOs_2Table
-
getHheaTable
-
getHeadTable
-
getCmapTable
-
getGlyphWidthsByIndex
public int[] getGlyphWidthsByIndex() -
getFontNames
-
isCff
public boolean isCff() -
getFullFont
- Throws:
IOException
-
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. If this method is ever made public: make sure to add a test if (cff == true).- Returns:
- a byte array
- Throws:
IOException
-
getSubset
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
initializeSfntTables
- Throws:
IOException
-
loadTables
Reads the font data.- Parameters:
all
- if true, all tables will be read, otherwise only 'head', 'name', and 'os/2'.- Throws:
IOException
-
getTTCName
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
Reads the glyphs widths. The widths are extracted from the table 'hmtx'. The glyphs are normalized to 1000 units (TrueTypeFont.UNITS_NORMALIZATION). Depends onOpenTypeParser.HorizontalHeader.numberOfHMetrics
andOpenTypeParser.HeaderTable.unitsPerEm
.- Throws:
IOException
- the font file could not be read.
-
readKerning
Reads the kerning information from the 'kern' table.- Parameters:
unitsPerEm
-OpenTypeParser.HeaderTable.unitsPerEm
.- Throws:
IOException
- the font file could not be read
-
readBbox
Read the glyf bboxes from 'glyf' table.- Parameters:
unitsPerEm
-OpenTypeParser.HeaderTable.unitsPerEm
- Throws:
IOException
- the font is invalidIOException
- the font file could not be read
-
readNumGlyphs
- Throws:
IOException
-
readNameTable
Extracts the names of the font in all the languages available.- Throws:
IOException
- on errorIOException
- on error
-
readHheaTable
Read horizontal header, table 'hhea'.- Throws:
IOException
- the font is invalid.IOException
- the font file could not be read.
-
readHeadTable
Read font header, table 'head'.- Throws:
IOException
- the font is invalid.IOException
- the font file could not be read.
-
readOs_2Table
Reads the windows metrics table. The metrics are extracted from the table 'OS/2'. Depends onOpenTypeParser.HeaderTable.unitsPerEm
property.- Throws:
IOException
- the font is invalid.IOException
- the font file could not be read.
-
readPostTable
- Throws:
IOException
-
readCmapTable
Reads 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:
IOException
- the font file could not be read
-
readStandardString
Reads aString
from the font file as bytes using the Cp1252 encoding.- Parameters:
length
- the length of bytes to read- Returns:
- the
String
read - Throws:
IOException
- the font file could not be read
-
readUnicodeString
Reads a UnicodeString
from the font file. Each character is represented by two bytes.- Parameters:
length
- the length of bytes to read. TheString
will havelength
/2 characters.- Returns:
- the
String
read. - Throws:
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
The 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
HashMap
representing this map - Throws:
IOException
- the font file could not be read
-
readFormat4
The 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
HashMap
representing this map - Throws:
IOException
- the font file could not be read
-
readFormat6
The 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
HashMap
representing this map - Throws:
IOException
- the font file could not be read
-
readFormat12
- Throws:
IOException
-