org.apache.fontbox.ttf

## Class TrueTypeFont

- java.lang.Object
- - org.apache.fontbox.ttf.TrueTypeFont

All Implemented Interfaces:
  Closeable, AutoCloseable, FontBoxFont

Direct Known Subclasses:
  OpenTypeFont

    public class TrueTypeFont
    extends Object
    implements FontBoxFont, Closeable

A TrueType font file.

Author:
  Ben Litchfield

### Field Summary

Fields
`protected Map<String,TTFTable>` `tables`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `close()`
`void` `disableGsubFeature(String featureTag)` Disable a particular glyph substitution feature.
`void` `enableGsubFeature(String featureTag)` Enable a particular glyph substitution feature.
`void` `enableVerticalSubstitutions()` Enable glyph substitutions for vertical writing.
`int` `getAdvanceHeight(int gid)` Returns the height for the given GID.
`int` `getAdvanceWidth(int gid)` Returns the width for the given GID.
`CmapTable` `getCmap()` Get the "cmap" table for this TTF.
`BoundingBox` `getFontBBox()` Returns the font's bounding box in PostScript units.
`List<Number>` `getFontMatrix()` Returns the FontMatrix in PostScript units.
`GlyphTable` `getGlyph()` Get the glyf table for this TTF.
`GlyphSubstitutionTable` `getGsub()` Get the "gsub" table for this TTF.
`GsubData` `getGsubData()` Returns the GSubData of the GlyphSubstitutionTable if present.
`HeaderTable` `getHeader()` Get the head table for this TTF.
`HorizontalHeaderTable` `getHorizontalHeader()` Get the hhea table for this TTF.
`HorizontalMetricsTable` `getHorizontalMetrics()` Get the hmtx table for this TTF.
`IndexToLocationTable` `getIndexToLocation()` Get the loca table for this TTF.
`KerningTable` `getKerning()` Get the "kern" table for this TTF.
`MaximumProfileTable` `getMaximumProfile()` Get the maxp table for this TTF.
`String` `getName()` The PostScript name of the font.
`NamingTable` `getNaming()` This will get the naming table for the true type font.
`int` `getNumberOfGlyphs()` Returns the number of glyphs (MaximumProfile.numGlyphs).
`InputStream` `getOriginalData()` Get the data of the TrueType Font program representing the stream used to build this object (normally from the TTFParser object).
`long` `getOriginalDataSize()` Get the data size of the TrueType Font program representing the stream used to build this object (normally from the TTFParser object).
`OS2WindowsMetricsTable` `getOS2Windows()` Get the OS/2 table for this TTF.
`GeneralPath` `getPath(String name)` Returns the path for the character with the given name.
`PostScriptTable` `getPostScript()` Get the postscript table for this TTF.
`protected TTFTable` `getTable(String tag)` This will get the table for the given tag.
`byte[]` `getTableBytes(TTFTable table)` Returns the raw bytes of the given table.
`Map<String,TTFTable>` `getTableMap()` Get all of the tables.
`byte[]` `getTableNBytes(TTFTable table, int limit)` Returns the raw bytes of the given table, no more than `limit` bytes.
`Collection<TTFTable>` `getTables()` Get all of the tables.
`CmapLookup` `getUnicodeCmapLookup()` Returns the best Unicode from the font (the most general).
`CmapLookup` `getUnicodeCmapLookup(boolean isStrict)` Returns the best Unicode from the font (the most general).
`int` `getUnitsPerEm()` Returns the units per EM (Header.unitsPerEm).
`float` `getVersion()`
`VerticalHeaderTable` `getVerticalHeader()` Get the vhea table for this TTF.
`VerticalMetricsTable` `getVerticalMetrics()` Get the vmtx table for this TTF.
`VerticalOriginTable` `getVerticalOrigin()` Get the VORG table for this TTF.
`float` `getWidth(String name)` Returns the advance width for the character with the given name.
`boolean` `hasGlyph(String name)` Returns true if the font contains the given glyph.
`boolean` `isEnableGsub()`
`int` `nameToGID(String name)` Returns the GID for the given PostScript name, if the "post" table is present.
`void` `setEnableGsub(boolean enableGsub)` Enable or disable the GSUB table for this font.
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### tables

    protected final Map<String,TTFTable> tables

### Method Detail

#### close

    public void close()
               throws IOException

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Throws:
  `IOException`

#### getVersion

    public float getVersion()

Returns:
  Returns the version.

#### isEnableGsub

    public boolean isEnableGsub()

Returns:
  Returns true if the GSUB table can be used for this font

#### setEnableGsub

    public void setEnableGsub(boolean enableGsub)

Enable or disable the GSUB table for this font. GSUB table is enabled by default.

#### getTables

    public Collection<TTFTable> getTables()

Get all of the tables.

Returns:
  All of the tables.

#### getTableMap

    public Map<String,TTFTable> getTableMap()

Get all of the tables.

Returns:
  All of the tables.

#### getTableBytes

    public byte[] getTableBytes(TTFTable table)
                         throws IOException

Returns the raw bytes of the given table.

Parameters:
  `table` - the table to read.
Returns:
  the raw bytes of the given table
Throws:
  `IOException` - if there was an error accessing the table.

#### getTable

    protected TTFTable getTable(String tag)
                         throws IOException

This will get the table for the given tag.

Parameters:
  `tag` - the name of the table to be returned
Returns:
  The table with the given tag.
Throws:
  `IOException` - if there was an error reading the table.

#### getTableNBytes

    public byte[] getTableNBytes(TTFTable table,
                                 int limit)
                          throws IOException

Returns the raw bytes of the given table, no more than `limit` bytes.

Parameters:
  `table` - the table to read.
  `limit` - maximum length of array to return
Returns:
  the raw bytes of the given table
Throws:
  `IOException` - if there was an error accessing the table.

#### getNaming

    public NamingTable getNaming()
                          throws IOException

This will get the naming table for the true type font.

Returns:
  The naming table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getPostScript

    public PostScriptTable getPostScript()
                                  throws IOException

Get the postscript table for this TTF.

Returns:
  The postscript table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getOS2Windows

    public OS2WindowsMetricsTable getOS2Windows()
                                         throws IOException

Get the OS/2 table for this TTF.

Returns:
  The OS/2 table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getMaximumProfile

    public MaximumProfileTable getMaximumProfile()
                                          throws IOException

Get the maxp table for this TTF.

Returns:
  The maxp table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getHeader

    public HeaderTable getHeader()
                          throws IOException

Get the head table for this TTF.

Returns:
  The head table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getHorizontalHeader

    public HorizontalHeaderTable getHorizontalHeader()
                                              throws IOException

Get the hhea table for this TTF.

Returns:
  The hhea table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getHorizontalMetrics

    public HorizontalMetricsTable getHorizontalMetrics()
                                                throws IOException

Get the hmtx table for this TTF.

Returns:
  The hmtx table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getIndexToLocation

    public IndexToLocationTable getIndexToLocation()
                                            throws IOException

Get the loca table for this TTF.

Returns:
  The loca table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getGlyph

    public GlyphTable getGlyph()
                        throws IOException

Get the glyf table for this TTF.

Returns:
  The glyf table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getCmap

    public CmapTable getCmap()
                      throws IOException

Get the "cmap" table for this TTF.

Returns:
  The "cmap" table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getVerticalHeader

    public VerticalHeaderTable getVerticalHeader()
                                          throws IOException

Get the vhea table for this TTF.

Returns:
  The vhea table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getVerticalMetrics

    public VerticalMetricsTable getVerticalMetrics()
                                            throws IOException

Get the vmtx table for this TTF.

Returns:
  The vmtx table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getVerticalOrigin

    public VerticalOriginTable getVerticalOrigin()
                                          throws IOException

Get the VORG table for this TTF.

Returns:
  The VORG table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getKerning

    public KerningTable getKerning()
                            throws IOException

Get the "kern" table for this TTF.

Returns:
  The "kern" table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getGsub

    public GlyphSubstitutionTable getGsub()
                                   throws IOException

Get the "gsub" table for this TTF.

Returns:
  The "gsub" table or null if it doesn't exist.
Throws:
  `IOException` - if there was an error reading the table.

#### getOriginalData

    public InputStream getOriginalData()
                                throws IOException

Get the data of the TrueType Font program representing the stream used to build this object (normally from the TTFParser object).

Returns:
  COSStream TrueType font program stream
Throws:
  `IOException` - If there is an error getting the font data.

#### getOriginalDataSize

    public long getOriginalDataSize()

Get the data size of the TrueType Font program representing the stream used to build this object (normally from the TTFParser object).

Returns:
  the size.

#### getNumberOfGlyphs

    public int getNumberOfGlyphs()
                          throws IOException

Returns the number of glyphs (MaximumProfile.numGlyphs).

Returns:
  the number of glyphs
Throws:
  `IOException` - if there was an error reading the table.

#### getUnitsPerEm

    public int getUnitsPerEm()
                      throws IOException

Returns the units per EM (Header.unitsPerEm).

Returns:
  units per EM
Throws:
  `IOException` - if there was an error reading the table.

#### getAdvanceWidth

    public int getAdvanceWidth(int gid)
                        throws IOException

Returns the width for the given GID.

Parameters:
  `gid` - the GID
Returns:
  the width
Throws:
  `IOException` - if there was an error reading the metrics table.

#### getAdvanceHeight

    public int getAdvanceHeight(int gid)
                         throws IOException

Returns the height for the given GID.

Parameters:
  `gid` - the GID
Returns:
  the height
Throws:
  `IOException` - if there was an error reading the metrics table.

#### getName

    public String getName()
                   throws IOException

Description copied from interface: `FontBoxFont`
The PostScript name of the font.

Specified by:
  `getName` in interface `FontBoxFont`
Returns:
  the postscript of the font or null
Throws:
  `IOException` - if something went wrong when accessing the font data

#### getUnicodeCmapLookup

    public CmapLookup getUnicodeCmapLookup()
                                    throws IOException

Returns the best Unicode from the font (the most general). The PDF spec says that "The means by which this is accomplished are implementation-dependent." The returned cmap will perform glyph substitution.

Returns:
  cmap to perform glyph substitution
Throws:
  `IOException` - if the font could not be read

#### getUnicodeCmapLookup

    public CmapLookup getUnicodeCmapLookup(boolean isStrict)
                                    throws IOException

Returns the best Unicode from the font (the most general). The PDF spec says that "The means by which this is accomplished are implementation-dependent." The returned cmap will perform glyph substitution.

Parameters:
  `isStrict` - False if we allow falling back to any cmap, even if it's not Unicode.
Returns:
  cmap to perform glyph substitution
Throws:
  `IOException` - if the font could not be read, or there is no Unicode cmap

#### nameToGID

    public int nameToGID(String name)
                  throws IOException

Returns the GID for the given PostScript name, if the "post" table is present.

Parameters:
  `name` - the PostScript name.
Returns:
  the GID for the given PostScript name
Throws:
  `IOException` - if the font data could not be read

#### getGsubData

    public GsubData getGsubData()
                         throws IOException

Returns the GSubData of the GlyphSubstitutionTable if present.

Returns:
  the GSubData of the GlyphSubstitutionTable or `GsubData.NO_DATA_FOUND` if no GSUB data is available, its scripts are not supported or it was disabled for that font
Throws:
  `IOException` - if the font data could not be read

#### getPath

    public GeneralPath getPath(String name)
                        throws IOException

Description copied from interface: `FontBoxFont`
Returns the path for the character with the given name.

Specified by:
  `getPath` in interface `FontBoxFont`
Parameters:
  `name` - PostScript glyph name
Returns:
  glyph path
Throws:
  `IOException` - if the path could not be read

#### getWidth

    public float getWidth(String name)
                   throws IOException

Description copied from interface: `FontBoxFont`
Returns the advance width for the character with the given name.

Specified by:
  `getWidth` in interface `FontBoxFont`
Parameters:
  `name` - PostScript glyph name
Returns:
  glyph advance width
Throws:
  `IOException` - if the path could not be read

#### hasGlyph

    public boolean hasGlyph(String name)
                     throws IOException

Description copied from interface: `FontBoxFont`
Returns true if the font contains the given glyph.

Specified by:
  `hasGlyph` in interface `FontBoxFont`
Parameters:
  `name` - PostScript glyph name
Returns:
  true if the font contains a glyph with the given name, otherwise false
Throws:
  `IOException` - if something went wrong when accessing the font data

#### getFontBBox

    public BoundingBox getFontBBox()
                            throws IOException

Description copied from interface: `FontBoxFont`
Returns the font's bounding box in PostScript units.

Specified by:
  `getFontBBox` in interface `FontBoxFont`
Returns:
  the bounding box of the font
Throws:
  `IOException` - if something went wrong when accessing the font data

#### getFontMatrix

    public List<Number> getFontMatrix()
                               throws IOException

Description copied from interface: `FontBoxFont`
Returns the FontMatrix in PostScript units.

Specified by:
  `getFontMatrix` in interface `FontBoxFont`
Returns:
  the font matrix
Throws:
  `IOException` - if something went wrong when accessing the font data

#### enableGsubFeature

    public void enableGsubFeature(String featureTag)

Enable a particular glyph substitution feature. This feature might not be supported by the font, or might not be implemented in PDFBox yet.

Parameters:
  `featureTag` - The GSUB feature to enable

#### disableGsubFeature

    public void disableGsubFeature(String featureTag)

Disable a particular glyph substitution feature.

Parameters:
  `featureTag` - The GSUB feature to disable

#### enableVerticalSubstitutions

    public void enableVerticalSubstitutions()

Enable glyph substitutions for vertical writing.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`