org.apache.fop.fonts.truetype

Class TTFFile

Known Direct 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

static boolean
TRACE_ENABLED
Set to true to get even more debug output than with level DEBUG
protected Map
dirTabs
Table directory
protected long
lastLoca
Offset to last loca
protected Log
log
logging instance
protected org.apache.fop.fonts.truetype.TTFMtxEntry[]
mtxTab
Contains glyph data

Method Summary

protected boolean
checkTTC(FontFileReader in, String name)
Check if this is a TrueType collection and that the given name exists in the collection.
int
convertTTFUnit2PDFUnit(int n)
Convert from truetype unit to pdf unit based on the unitsPerEm field in the "head" table
Map
getAnsiKerning()
Returns the ANSI kerning table.
List
getCMaps()
Return a List with TTFCmapEntry.
int
getCapHeight()
Returns the CapHeight attribute of the font.
String
getCharSetName()
Returns the name of the character set used.
int
getCharWidth(int idx)
Returns the width of a given character.
String
getFamilyName()
Returns the font family name of the font.
short
getFirstChar()
Returns the index of the first character.
int
getFlags()
Returns the Flags attribute of the font.
int[]
getFontBBox()
Returns the font bounding box.
String
getItalicAngle()
Returns the ItalicAngle attribute of the font.
Map
getKerning()
Returns the kerning table.
short
getLastChar()
Returns the index of the last character, but this is for WinAnsiEncoding only, so the last char is <32256.
int
getLowerCaseAscent()
Returns the LowerCaseAscent attribute of the font.
int
getLowerCaseDescent()
Returns the LowerCaseDescent attribute of the font.
protected void
getNumGlyphs(FontFileReader in)
Read the number of glyphs from the "maxp" table
String
getPostScriptName()
Returns the PostScript name of the font.
String
getStemV()
Returns the StemV attribute of the font.
String
getSubFamilyName()
Returns the font sub family name of the font.
int[]
getWidths()
Returns an array of character widths.
String
getWindowsName()
Returns the Windows name of the font.
int
getXHeight()
Returns the XHeight attribute of the font.
boolean
isCFF()
Indicates whether or not the font is an OpenType CFF font (rather than a TrueType font).
boolean
isEmbeddable()
Indicates if the font may be embedded.
static void
main(String[] args)
Static main method to get info about a TrueType font.
void
printStuff()
Dumps a few informational values to System.out.
protected void
readDirTabs(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.
void
readFont(FontFileReader in)
Reads the font using a FontFileReader.
boolean
readFont(FontFileReader in, String name)
Read the font data.
protected void
readFontHeader(FontFileReader in)
Read the "head" table, this reads the bounding box and sets the upem (unitsPerEM) variable
protected void
readHorizontalHeader(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 void
readHorizontalMetrics(FontFileReader in)
Read "hmtx" table and put the horizontal metrics in the mtxTab array.
protected void
readIndexToLocation(FontFileReader in)
Read the "loca" table.

Field Details

TRACE_ENABLED

public static final boolean TRACE_ENABLED
Set to true to get even more debug output than with level DEBUG
Field Value:
false

dirTabs

protected Map dirTabs
Table directory

lastLoca

protected long lastLoca
Offset to last loca

log

protected Log log
logging instance

mtxTab

protected org.apache.fop.fonts.truetype.TTFMtxEntry[] mtxTab
Contains glyph data

Method Details

checkTTC

protected final boolean checkTTC(FontFileReader in,
                                 String name)
            throws IOException
Check 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 from
name - The name to check
Returns:
True if not collection or font name present, false otherwise

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

getAnsiKerning

public Map getAnsiKerning()
Returns the ANSI kerning table.
Returns:
Map The ANSI kerning table

getCMaps

public List getCMaps()
Return a List with TTFCmapEntry.
Returns:
A list of TTFCmapEntry objects

getCapHeight

public int getCapHeight()
Returns the CapHeight attribute of the font.
Returns:
int The CapHeight

getCharSetName

public String getCharSetName()
Returns the name of the character set used.
Returns:
String The caracter set

getCharWidth

public int getCharWidth(int idx)
Returns the width of a given character.
Parameters:
idx - Index of the character
Returns:
int Standard width

getFamilyName

public String getFamilyName()
Returns the font family name of the font.
Returns:
String The family name

getFirstChar

public short getFirstChar()
Returns the index of the first character.
Returns:
short Index of the first character

getFlags

public int getFlags()
Returns the Flags attribute of the font.
Returns:
int The Flags

getFontBBox

public int[] getFontBBox()
Returns the font bounding box.
Returns:
int[] The font bbox

getItalicAngle

public String getItalicAngle()
Returns the ItalicAngle attribute of the font.
Returns:
String The ItalicAngle

getKerning

public Map getKerning()
Returns the kerning table.
Returns:
Map The kerning table

getLastChar

public short getLastChar()
Returns the index of the last character, but this is for WinAnsiEncoding only, so the last char is <32256.
Returns:
short Index of the last character (<256)

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

getNumGlyphs

protected void getNumGlyphs(FontFileReader in)
            throws IOException
Read the number of glyphs from the "maxp" table
Parameters:
in - FontFileReader to read the number of glyphs from

getPostScriptName

public String getPostScriptName()
Returns the PostScript name of the font.
Returns:
String The PostScript name

getStemV

public String getStemV()
Returns the StemV attribute of the font.
Returns:
String The StemV

getSubFamilyName

public String getSubFamilyName()
Returns the font sub family name of the font.
Returns:
String The sub family name

getWidths

public int[] getWidths()
Returns an array of character widths.
Returns:
int[] The character widths

getWindowsName

public String getWindowsName()
Returns the Windows name of the font.
Returns:
String The Windows name

getXHeight

public int getXHeight()
Returns the XHeight attribute of the font.
Returns:
int The XHeight

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.

isEmbeddable

public boolean isEmbeddable()
Indicates if the font may be embedded.
Returns:
boolean True if it may be embedded

main

public static void main(String[] args)
Static main method to get info about a TrueType font.
Parameters:
args - The command line arguments

printStuff

public void printStuff()
Dumps a few informational values to System.out.

readDirTabs

protected void readDirTabs(FontFileReader in)
            throws IOException
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

readFont

public void readFont(FontFileReader in)
            throws IOException
Reads the font using a FontFileReader.
Parameters:
in - The FontFileReader to use

readFont

public boolean readFont(FontFileReader in,
                        String name)
            throws IOException
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 use
name - The name of the font
Returns:
boolean Returns true if the font is valid

readFontHeader

protected void readFontHeader(FontFileReader in)
            throws IOException
Read the "head" table, this reads the bounding box and sets the upem (unitsPerEM) variable
Parameters:
in - FontFileReader to read the header from

readHorizontalHeader

protected void readHorizontalHeader(FontFileReader in)
            throws IOException
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

readHorizontalMetrics

protected void readHorizontalMetrics(FontFileReader in)
            throws IOException
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

readIndexToLocation

protected final void readIndexToLocation(FontFileReader in)
            throws IOException
Read the "loca" table.
Parameters:
in - FontFileReader to read from

Copyright 1999-2007 The Apache Software Foundation. All Rights Reserved.