Package com.tom_roush.fontbox.ttf
Class TrueTypeFont
- java.lang.Object
-
- com.tom_roush.fontbox.ttf.TrueTypeFont
-
- All Implemented Interfaces:
FontBoxFont,Closeable,AutoCloseable
- Direct Known Subclasses:
OpenTypeFont
public class TrueTypeFont extends Object implements FontBoxFont, Closeable
A TrueType font file.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()intgetAdvanceHeight(int gid)Returns the height for the given GID.intgetAdvanceWidth(int gid)Returns the width for the given GID.CmapTablegetCmap()Get the "cmap" table for this TTF.BoundingBoxgetFontBBox()Returns the font's bounding box in PostScript units.List<Number>getFontMatrix()Returns the FontMatrix in PostScript units.GlyphTablegetGlyph()Get the glyf table for this TTF.HeaderTablegetHeader()Get the head table for this TTF.HorizontalHeaderTablegetHorizontalHeader()Get the hhea table for this TTF.HorizontalMetricsTablegetHorizontalMetrics()Get the hmtx table for this TTF.IndexToLocationTablegetIndexToLocation()Get the loca table for this TTF.KerningTablegetKerning()Get the "kern" table for this TTF.MaximumProfileTablegetMaximumProfile()Get the maxp table for this TTF.StringgetName()The PostScript name of the font.NamingTablegetNaming()This will get the naming table for the true type font.intgetNumberOfGlyphs()Returns the number of glyphs (MaximuProfile.numGlyphs).InputStreamgetOriginalData()This permit to get the data of the True Type Font program representing the stream used to build this object (normally from the TTFParser object).OS2WindowsMetricsTablegetOS2Windows()Get the OS/2 table for this TTF.android.graphics.PathgetPath(String name)Returns the path for the character with the given name.PostScriptTablegetPostScript()Get the postscript table for this TTF.byte[]getTableBytes(TTFTable table)Returns the war bytes of the given table.Map<String,TTFTable>getTableMap()Get all of the tables.Collection<TTFTable>getTables()Get all of the tables.CmapSubtablegetUnicodeCmap()Returns the best Unicode from the font (the most general).CmapSubtablegetUnicodeCmap(boolean isStrict)Returns the best Unicode from the font (the most general).intgetUnitsPerEm()Returns the units per EM (Header.unitsPerEm).floatgetVersion()VerticalHeaderTablegetVerticalHeader()Get the vhea table for this TTF.VerticalMetricsTablegetVerticalMetrics()Get the vmtx table for this TTF.VerticalOriginTablegetVerticalOrigin()Get the VORG table for this TTF.floatgetWidth(String name)Returns the advance width for the character with the given name.booleanhasGlyph(String name)Returns true if the font contains the given glyph.intnameToGID(String name)Returns the GID for the given PostScript name, if the "post" table is present.StringtoString()
-
-
-
Method Detail
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getVersion
public float getVersion()
- Returns:
- Returns the version.
-
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 war bytes of the given table.- Parameters:
table- the table to read.- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- Throws:
IOException- if there was an error reading the table.
-
getOriginalData
public InputStream getOriginalData() throws IOException
This permit to get the data of the True Type Font program representing the stream used to build this object (normally from the TTFParser object).- Returns:
- COSStream True type font program stream
- Throws:
IOException- If there is an error getting the font data.
-
getNumberOfGlyphs
public int getNumberOfGlyphs() throws IOExceptionReturns the number of glyphs (MaximuProfile.numGlyphs).- Returns:
- the number of glyphs
- Throws:
IOException- if there was an error reading the table.
-
getUnitsPerEm
public int getUnitsPerEm() throws IOExceptionReturns 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 IOExceptionReturns 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 IOExceptionReturns 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:FontBoxFontThe PostScript name of the font.- Specified by:
getNamein interfaceFontBoxFont- Throws:
IOException
-
getUnicodeCmap
public CmapSubtable getUnicodeCmap() 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."- Throws:
IOException- if the font could not be read
-
getUnicodeCmap
public CmapSubtable getUnicodeCmap(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."- 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
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.- Throws:
IOException
-
getPath
public android.graphics.Path getPath(String name) throws IOException
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
public float getWidth(String name) throws IOException
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
public boolean hasGlyph(String name) throws IOException
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
public BoundingBox getFontBBox() throws IOException
Description copied from interface:FontBoxFontReturns the font's bounding box in PostScript units.- Specified by:
getFontBBoxin interfaceFontBoxFont- Throws:
IOException
-
getFontMatrix
public List<Number> getFontMatrix() throws IOException
Description copied from interface:FontBoxFontReturns the FontMatrix in PostScript units.- Specified by:
getFontMatrixin interfaceFontBoxFont- Throws:
IOException
-
-