Package org.apache.fontbox.ttf
Class TrueTypeFont
java.lang.Object
org.apache.fontbox.ttf.TrueTypeFont
- All Implemented Interfaces:
Closeable,AutoCloseable,FontBoxFont
- Direct Known Subclasses:
OpenTypeFont
A TrueType font file.
- Author:
- Ben Litchfield
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voiddisableGsubFeature(String featureTag) Disable a particular glyph substitution feature.voidenableGsubFeature(String featureTag) Enable a particular glyph substitution feature.voidEnable glyph substitutions for vertical writing.protected voidfinalize()intgetAdvanceHeight(int gid) Returns the height for the given GID.intgetAdvanceWidth(int gid) Returns the width for the given GID.getCmap()Get the "cmap" table for this TTF.Returns the font's bounding box in PostScript units.Returns the FontMatrix in PostScript units.getGlyph()Get the glyf table for this TTF.getGsub()Get the "gsub" table for this TTF.Get the head table for this TTF.Get the hhea table for this TTF.Get the hmtx table for this TTF.Get the loca table for this TTF.Get the "kern" table for this TTF.Get the maxp table for this TTF.getName()The PostScript name of the font.This will get the naming table for the true type font.intReturns the number of glyphs (MaximumProfile.numGlyphs).Get the data of the TrueType Font program representing the stream used to build this object (normally from the TTFParser object).longGet the data size of the TrueType Font program representing the stream used to build this object (normally from the TTFParser object).Get the OS/2 table for this TTF.Returns the path for the character with the given name.Get the postscript table for this TTF.protected TTFTableThis will get the table for the given tag.byte[]getTableBytes(TTFTable table) Returns the raw bytes of the given table.Get all of the tables.Get all of the tables.Deprecated.getUnicodeCmap(boolean isStrict) Deprecated.UsegetUnicodeCmapLookup(boolean)insteadReturns the best Unicode from the font (the most general).getUnicodeCmapLookup(boolean isStrict) Returns the best Unicode from the font (the most general).intReturns the units per EM (Header.unitsPerEm).floatGet the vhea table for this TTF.Get the vmtx table for this TTF.Get the VORG table for this TTF.floatReturns the advance width for the character with the given name.booleanReturns true if the font contains the given glyph.intReturns the GID for the given PostScript name, if the "post" table is present.toString()
-
Field Details
-
tables
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
finalize
-
getVersion
public float getVersion()- Returns:
- Returns the version.
-
getTables
Get all of the tables.- Returns:
- All of the tables.
-
getTableMap
Get all of the tables.- Returns:
- All of the tables.
-
getTableBytes
Returns the raw bytes of the given table.- Parameters:
table- the table to read.- Throws:
IOException- if there was an error accessing the table.
-
getTable
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.
-
getNaming
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Returns the number of glyphs (MaximumProfile.numGlyphs).- Returns:
- the number of glyphs
- Throws:
IOException- if there was an error reading the table.
-
getUnitsPerEm
Returns the units per EM (Header.unitsPerEm).- Returns:
- units per EM
- Throws:
IOException- if there was an error reading the table.
-
getAdvanceWidth
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
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
Description copied from interface:FontBoxFontThe PostScript name of the font.- Specified by:
getNamein interfaceFontBoxFont- Throws:
IOException
-
getUnicodeCmap
Deprecated.UsegetUnicodeCmapLookup()insteadReturns the best Unicode from the font (the most general). The PDF spec says that "The means by which this is accomplished are implementation-dependent."- Throws:
IOException- if the font could not be read
-
getUnicodeCmap
Deprecated.UsegetUnicodeCmapLookup(boolean)insteadReturns the best Unicode from the font (the most general). The PDF spec says that "The means by which this is accomplished are implementation-dependent."- Parameters:
isStrict- False if we allow falling back to any cmap, even if it's not Unicode.- Throws:
IOException- if the font could not be read, or there is no Unicode cmap
-
getUnicodeCmapLookup
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.- Throws:
IOException- if the font could not be read
-
getUnicodeCmapLookup
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.- Throws:
IOException- if the font could not be read, or there is no Unicode cmap
-
nameToGID
Returns the GID for the given PostScript name, if the "post" table is present.- Parameters:
name- the PostScript name.- Throws:
IOException
-
getPath
Description copied from interface:FontBoxFontReturns the path for the character with the given name.- Specified by:
getPathin interfaceFontBoxFont- Returns:
- glyph path
- Throws:
IOException- if the path could not be read
-
getWidth
Description copied from interface:FontBoxFontReturns the advance width for the character with the given name.- Specified by:
getWidthin interfaceFontBoxFont- Returns:
- glyph advance width
- Throws:
IOException- if the path could not be read
-
hasGlyph
Description copied from interface:FontBoxFontReturns true if the font contains the given glyph.- Specified by:
hasGlyphin interfaceFontBoxFont- Parameters:
name- PostScript glyph name- Throws:
IOException
-
getFontBBox
Description copied from interface:FontBoxFontReturns the font's bounding box in PostScript units.- Specified by:
getFontBBoxin interfaceFontBoxFont- Throws:
IOException
-
getFontMatrix
Description copied from interface:FontBoxFontReturns the FontMatrix in PostScript units.- Specified by:
getFontMatrixin interfaceFontBoxFont- Throws:
IOException
-
enableGsubFeature
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
Disable a particular glyph substitution feature.- Parameters:
featureTag- The GSUB feature to disable
-
enableVerticalSubstitutions
public void enableVerticalSubstitutions()Enable glyph substitutions for vertical writing. -
toString
-
getUnicodeCmapLookup()instead