Class TTFFile
java.lang.Object
org.docx4j.fonts.fop.fonts.truetype.TTFFile
- Direct Known Subclasses:
TTFSubSetFile
public class TTFFile
extends java.lang.Object
Reads a TrueType file or a TrueType Collection.
The TrueType spec can be found at the Microsoft.
Typography site: http://www.microsoft.com/truetype/
-
Field Summary
Fields Modifier and Type Field Description protected java.util.MapdirTabsTable directoryprotected longlastLocaOffset to last locaprotected org.slf4j.Loggerloglogging instanceprotected org.docx4j.fonts.fop.fonts.truetype.TTFMtxEntry[]mtxTabContains glyph datastatic booleanTRACE_ENABLEDSet to true to get even more debug output than with level DEBUG -
Constructor Summary
Constructors Constructor Description TTFFile() -
Method Summary
Modifier and Type Method Description protected booleancheckTTC(FontFileReader in, java.lang.String name)Check if this is a TrueType collection and that the given name exists in the collection.intconvertTTFUnit2PDFUnit(int n)Convert from truetype unit to pdf unit based on the unitsPerEm field in the "head" tablejava.util.MapgetAnsiKerning()Returns the ANSI kerning table.intgetCapHeight()Returns the CapHeight attribute of the font.java.lang.StringgetCharSetName()Returns the name of the character set used.intgetCharWidth(int idx)Returns the width of a given character.java.util.ListgetCMaps()Return a List with TTFCmapEntry.java.util.SetgetFamilyNames()Returns the font family names of the font.shortgetFirstChar()Returns the index of the first character.intgetFlags()Returns the Flags attribute of the font.int[]getFontBBox()Returns the font bounding box.java.lang.StringgetFullName()Returns the full name of the font.java.lang.StringgetItalicAngle()Returns the ItalicAngle attribute of the font.java.util.MapgetKerning()Returns the kerning table.shortgetLastChar()Returns the index of the last character, but this is for WinAnsiEncoding only, so the last char is < 256.intgetLowerCaseAscent()Returns the LowerCaseAscent attribute of the font.intgetLowerCaseDescent()Returns the LowerCaseDescent attribute of the font.protected voidgetNumGlyphs(FontFileReader in)Read the number of glyphs from the "maxp" tablePanosegetPanose()java.lang.StringgetPostScriptName()Returns the PostScript name of the font.java.lang.StringgetStemV()Returns the StemV attribute of the font.java.lang.StringgetSubFamilyName()Returns the font sub family name of the font.java.util.ListgetTTCnames(FontFileReader in)Return TTC font namesintgetWeightClass()Returns the weight class of this font.int[]getWidths()Returns an array of character widths.intgetXHeight()Returns the XHeight attribute of the font.booleanisCFF()Indicates whether or not the font is an OpenType CFF font (rather than a TrueType font).booleanisEmbeddable()Indicates if the font may be embedded.static voidmain(java.lang.String[] args)Static main method to get info about a TrueType font.voidprintStuff()Dumps a few informational values to System.out.protected voidreadDirTabs(FontFileReader in)Read Table Directory from the current position in the FontFileReader and fill the global HashMap dirTabs with the table name (String) as key and a TTFDirTabEntry as value.voidreadFont(FontFileReader in)Reads the font using a FontFileReader.booleanreadFont(FontFileReader in, java.lang.String name)Read the font data.protected voidreadFontHeader(FontFileReader in)Read the "head" table, this reads the bounding box and sets the upem (unitsPerEM) variableprotected voidreadHorizontalHeader(FontFileReader in)Read the "hhea" table to find the ascender and descender and size of "hmtx" table, as a fixed size font might have only one width.protected voidreadHorizontalMetrics(FontFileReader in)Read "hmtx" table and put the horizontal metrics in the mtxTab array.protected voidreadIndexToLocation(FontFileReader in)Read the "loca" table.
-
Field Details
-
TRACE_ENABLED
public static final boolean TRACE_ENABLEDSet to true to get even more debug output than with level DEBUG- See Also:
- Constant Field Values
-
dirTabs
protected java.util.Map dirTabsTable directory -
lastLoca
protected long lastLocaOffset to last loca -
mtxTab
protected org.docx4j.fonts.fop.fonts.truetype.TTFMtxEntry[] mtxTabContains glyph data -
log
protected org.slf4j.Logger loglogging instance
-
-
Constructor Details
-
TTFFile
public TTFFile()
-
-
Method Details
-
convertTTFUnit2PDFUnit
public int convertTTFUnit2PDFUnit(int n)Convert from truetype unit to pdf unit based on the unitsPerEm field in the "head" table- Parameters:
n- truetype unit- Returns:
- pdf unit
-
readFont
Reads the font using a FontFileReader.- Parameters:
in- The FontFileReader to use- Throws:
java.io.IOException- In case of an I/O problem
-
readFont
Read the font data. If the fontfile is a TrueType Collection (.ttc file) the name of the font to read data for must be supplied, else the name is ignored.- Parameters:
in- The FontFileReader to usename- The name of the font- Returns:
- boolean Returns true if the font is valid
- Throws:
java.io.IOException- In case of an I/O problem
-
getPostScriptName
public java.lang.String getPostScriptName()Returns the PostScript name of the font.- Returns:
- String The PostScript name
-
getFamilyNames
public java.util.Set getFamilyNames()Returns the font family names of the font.- Returns:
- Set The family names (a Set of Strings)
-
getSubFamilyName
public java.lang.String getSubFamilyName()Returns the font sub family name of the font.- Returns:
- String The sub family name
-
getFullName
public java.lang.String getFullName()Returns the full name of the font.- Returns:
- String The full name
-
getCharSetName
public java.lang.String getCharSetName()Returns the name of the character set used.- Returns:
- String The caracter set
-
getCapHeight
public int getCapHeight()Returns the CapHeight attribute of the font.- Returns:
- int The CapHeight
-
getXHeight
public int getXHeight()Returns the XHeight attribute of the font.- Returns:
- int The XHeight
-
getFlags
public int getFlags()Returns the Flags attribute of the font.- Returns:
- int The Flags
-
getWeightClass
public int getWeightClass()Returns the weight class of this font. Valid values are 100, 200....,800, 900.- Returns:
- the weight class value (or 0 if there was no OS/2 table in the font)
-
getStemV
public java.lang.String getStemV()Returns the StemV attribute of the font.- Returns:
- String The StemV
-
getItalicAngle
public java.lang.String getItalicAngle()Returns the ItalicAngle attribute of the font.- Returns:
- String The ItalicAngle
-
getFontBBox
public int[] getFontBBox()Returns the font bounding box.- Returns:
- int[] The font bbox
-
getLowerCaseAscent
public int getLowerCaseAscent()Returns the LowerCaseAscent attribute of the font.- Returns:
- int The LowerCaseAscent
-
getLowerCaseDescent
public int getLowerCaseDescent()Returns the LowerCaseDescent attribute of the font.- Returns:
- int The LowerCaseDescent
-
getLastChar
public short getLastChar()Returns the index of the last character, but this is for WinAnsiEncoding only, so the last char is < 256.- Returns:
- short Index of the last character (<256)
-
getFirstChar
public short getFirstChar()Returns the index of the first character.- Returns:
- short Index of the first character
-
getWidths
public int[] getWidths()Returns an array of character widths.- Returns:
- int[] The character widths
-
getCharWidth
public int getCharWidth(int idx)Returns the width of a given character.- Parameters:
idx- Index of the character- Returns:
- int Standard width
-
getKerning
public java.util.Map getKerning()Returns the kerning table.- Returns:
- Map The kerning table
-
getAnsiKerning
public java.util.Map getAnsiKerning()Returns the ANSI kerning table.- Returns:
- Map The ANSI kerning table
-
isEmbeddable
public boolean isEmbeddable()Indicates if the font may be embedded.- Returns:
- boolean True if it may be embedded
-
isCFF
public boolean isCFF()Indicates whether or not the font is an OpenType CFF font (rather than a TrueType font).- Returns:
- true if the font is in OpenType CFF format.
-
readDirTabs
Read Table Directory from the current position in the FontFileReader and fill the global HashMap dirTabs with the table name (String) as key and a TTFDirTabEntry as value.- Parameters:
in- FontFileReader to read the table directory from- Throws:
java.io.IOException- in case of an I/O problem
-
readFontHeader
Read the "head" table, this reads the bounding box and sets the upem (unitsPerEM) variable- Parameters:
in- FontFileReader to read the header from- Throws:
java.io.IOException- in case of an I/O problem
-
getNumGlyphs
Read the number of glyphs from the "maxp" table- Parameters:
in- FontFileReader to read the number of glyphs from- Throws:
java.io.IOException- in case of an I/O problem
-
readHorizontalHeader
Read the "hhea" table to find the ascender and descender and size of "hmtx" table, as a fixed size font might have only one width.- Parameters:
in- FontFileReader to read the hhea table from- Throws:
java.io.IOException- in case of an I/O problem
-
readHorizontalMetrics
Read "hmtx" table and put the horizontal metrics in the mtxTab array. If the number of metrics is less than the number of glyphs (eg fixed size fonts), extend the mtxTab array and fill in the missing widths- Parameters:
in- FontFileReader to read the hmtx table from- Throws:
java.io.IOException- in case of an I/O problem
-
readIndexToLocation
Read the "loca" table.- Parameters:
in- FontFileReader to read from- Throws:
java.io.IOException- In case of a I/O problem
-
getCMaps
public java.util.List getCMaps()Return a List with TTFCmapEntry.- Returns:
- A list of TTFCmapEntry objects
-
checkTTC
protected final boolean checkTTC(FontFileReader in, java.lang.String name) throws java.io.IOExceptionCheck if this is a TrueType collection and that the given name exists in the collection. If it does, set offset in fontfile to the beginning of the Table Directory for that font.- Parameters:
in- FontFileReader to read fromname- The name to check- Returns:
- True if not collection or font name present, false otherwise
- Throws:
java.io.IOException- In case of an I/O problem
-
getTTCnames
Return TTC font names- Parameters:
in- FontFileReader to read from- Returns:
- True if not collection or font name present, false otherwise
- Throws:
java.io.IOException- In case of an I/O problem
-
getPanose
-
printStuff
public void printStuff()Dumps a few informational values to System.out. -
main
public static void main(java.lang.String[] args)Static main method to get info about a TrueType font.- Parameters:
args- The command line arguments
-