Package org.apache.fop.fonts.truetype
Class OpenFont
java.lang.Object
org.apache.fop.fonts.truetype.OpenFont
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumVersion of the PostScript table (post) contained in this font.(package private) static final classKey-value helper class. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected OTFAdvancedTypographicTableReaderprivate int[]private intprivate intprotected booleanprivate List<CMapSegment> private intprotected Map<OFTableName, OFDirTabEntry> Table directoryprotected String(package private) static final intprivate static final Stringprivate static final shortprivate intprivate intprivate intprivate intprotected FontFileReaderThe FontFileReader used to read this TrueType font.protected Stringprivate booleanprivate intprivate intprivate booleanprivate booleanprivate longprivate longprivate shortprotected longOffset to last locaprotected intprotected org.apache.commons.logging.Loglogging instanceprivate static final String[](package private) static final intprotected OFMtxEntry[]Contains glyph dataprotected intprotected String(package private) static final byteprotected intprivate intprivate intprivate intprivate intprotected Stringprivate OpenFont.PostScriptVersionprivate intprivate intprotected Stringprotected Map<Integer, SVGGlyphData> static final booleanSet to true to get even more debug output than with level DEBUGprivate intprivate intprotected List<OpenFont.UnicodeMapping> private intprotected booleanprotected booleanprivate intprivate int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final booleanCheck 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" tableprotected voidprotected voidDetermines the right source for the ascender and descender values.private StringformatUnitsForDebug(int units) Returns the ANSI kerning table.int[]getBBox(int glyphIndex) Returns an array (xMin, yMin, xMax, yMax) for a glyph.int[]Returns the original bounding box values from the HEAD tableintReturns the CapHeight attribute of the font.Returns the name of the character set used.intgetCharWidth(int idx) Returns the width of a given character.intgetCharWidthRaw(int idx) Returns the width of a given character in raw unitsgetCMaps()Returns this font's character to glyph mapping.getDirectoryEntry(OFTableName name) Obtain directory table entry.Returns the font family names of the font.shortReturns the index of the first character.intgetFlags()Returns the Flags attribute of the font.int[]Returns the full name of the font.getGDEF()Returns the GDEF table or null if none present.(package private) StringgetGlyphName(int glyphIndex) getGPOS()Returns the GPOS table or null if none present.getGSUB()Returns the GSUB table or null if none present.Returns the ItalicAngle attribute of the font.Returns the kerning table.shortReturns the index of the last character, but this is for WinAnsiEncoding only, so the last char is < 256.intReturns the LowerCaseAscent attribute of the font.intReturns the LowerCaseDescent attribute of the font.getMtx()protected voidRead the number of glyphs from the "maxp" tableprotected intgetPadSize(int currentPosition) Returns the number of bytes necessary to pad the currentPosition so that a table begins on a 4-byte boundary.Returns the PostScript name of the font.(package private) OpenFont.PostScriptVersiongetStemV()Returns the StemV attribute of the font.intintReturns the font sub family name of the font.Return TTC font namesintintintReturns the weight class of this font.int[]Returns an array of character widths.intReturns the XHeight attribute of the font.private IntegerglyphToUnicode(int glyphIndex) Map a glyph index to the corresponding unicode code pointprotected voidprotected voidbooleanDetermine if advanced (typographic) table is present.protected voidinitialize the ansiWidths array (for winAnsiEncoding) and fill with the missingwidthprotected abstract voidbooleanisCFF()Indicates whether or not the font is an OpenType CFF font (rather than a TrueType font).booleanIndicates if the font may be embedded.private booleanisInPrivateUseArea(int unicode) private booleanisInPrivateUseArea(int start, int end) static voidStatic main method to get info about a TrueType font.private voidvoidDumps a few informational values to System.out.protected booleanreadCMAP()Read the cmap table, return false if the table is not present or only unsupported tables are present.protected voidRead 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, String header) Reads the font using a FontFileReader.booleanreadFont(FontFileReader in, String header, String name) Read the font data.voidreadFont(FontFileReader in, String header, MultiByteFont mbfont) Reads a font.protected voidRead the "head" table, this reads the bounding box and sets the upem (unitsPerEM) variableprotected voidRead 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 voidRead "hmtx" table and put the horizontal metrics in the mtxTab array.protected voidRead the kerning table, create a table for both CIDs and winAnsiEncoding.protected abstract voidreadName()protected voidreadOS2()Read the "OS/2" tableprotected booleanreadPCLT()Read the "PCLT" table to find xHeight and capHeight.protected voidRead the "post" table containing the PostScript names of the glyphs.private voidreadSVG()private booleanreadUnicodeCmap(long cmapUniOffset, int encodingID) booleanseekTab(FontFileReader in, OFTableName tableName, long offset) Position inputstream to position indicated in the dirtab offset + offset(package private) SortedSet<Map.Entry<OFTableName, OFDirTabEntry>> sortDirTabMap(Map<OFTableName, OFDirTabEntry> directoryTabs) Returns the order in which the tables in a TrueType font should be written to file.voidstream(TTFOutputStream ttfOut) Streams a font.private voidstreamGlyf(TTFGlyphOutputStream glyphOut, byte[] fontFile, int tableOffset, int tableLength) private IntegerunicodeToGlyph(int unicodeIndex) Map a unicode code point to the corresponding glyph indexprivate Integer[]unicodeToWinAnsi(int unicode) protected abstract void
-
Field Details
-
NTABS
static final byte NTABS- See Also:
-
MAX_CHAR_CODE
static final int MAX_CHAR_CODE- See Also:
-
ENC_BUF_SIZE
static final int ENC_BUF_SIZE- See Also:
-
MAC_GLYPH_ORDERING
-
fontFile
The FontFileReader used to read this TrueType font. -
TRACE_ENABLED
public static final boolean TRACE_ENABLEDSet to true to get even more debug output than with level DEBUG- See Also:
-
ENCODING
- See Also:
-
FIRST_CHAR
private static final short FIRST_CHAR- See Also:
-
useKerning
protected boolean useKerning -
isEmbeddable
private boolean isEmbeddable -
hasSerifs
private boolean hasSerifs -
dirTabs
Table directory -
kerningTab
-
ansiKerningTab
-
cmaps
-
unicodeMappings
-
upem
private int upem -
nhmtx
protected int nhmtx -
postScriptVersion
-
locaFormat
protected int locaFormat -
lastLoca
protected long lastLocaOffset to last loca -
numberOfGlyphs
protected int numberOfGlyphs -
mtxTab
Contains glyph data -
postScriptName
-
fullName
-
embedFontName
-
notice
-
familyNames
-
subFamilyName
-
cid
protected boolean cid -
italicAngle
private long italicAngle -
isFixedPitch
private long isFixedPitch -
fontBBox1
private int fontBBox1 -
fontBBox2
private int fontBBox2 -
fontBBox3
private int fontBBox3 -
fontBBox4
private int fontBBox4 -
capHeight
private int capHeight -
os2CapHeight
private int os2CapHeight -
underlinePosition
private int underlinePosition -
underlineThickness
private int underlineThickness -
strikeoutPosition
private int strikeoutPosition -
strikeoutThickness
private int strikeoutThickness -
xHeight
private int xHeight -
os2xHeight
private int os2xHeight -
ascender
private int ascender -
descender
private int descender -
hheaAscender
private int hheaAscender -
hheaDescender
private int hheaDescender -
os2Ascender
private int os2Ascender -
os2Descender
private int os2Descender -
usWeightClass
private int usWeightClass -
lastChar
private short lastChar -
ansiWidth
private int[] ansiWidth -
ansiIndex
-
svgs
-
glyphToUnicodeMap
-
unicodeToGlyphMap
-
isCFF
private boolean isCFF -
useAdvanced
protected boolean useAdvanced -
advancedTableReader
-
log
protected org.apache.commons.logging.Log loglogging instance
-
-
Constructor Details
-
OpenFont
public OpenFont() -
OpenFont
public OpenFont(boolean useKerning, boolean useAdvanced) Constructor- Parameters:
useKerning- true if kerning data should be loadeduseAdvanced- true if advanced typographic tables should be loaded
-
-
Method Details
-
getDirectoryEntry
Obtain directory table entry.- Parameters:
name- (tag) of entry- Returns:
- a directory table entry or null if none found
-
seekTab
Position inputstream to position indicated in the dirtab offset + offset- Parameters:
in- font file readertableName- (tag) of tableoffset- from start of table- Returns:
- true if seek succeeded
- Throws:
IOException- if I/O exception occurs during seek
-
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
-
readCMAP
Read the cmap table, return false if the table is not present or only unsupported tables are present. Currently only unicode cmaps are supported. Set the unicodeIndex in the TTFMtxEntries and fills in the cmaps vector.- Throws:
IOException- See Also:
-
readUnicodeCmap
- Throws:
IOException
-
mapSymbol
-
isInPrivateUseArea
private boolean isInPrivateUseArea(int start, int end) -
isInPrivateUseArea
private boolean isInPrivateUseArea(int unicode) -
getMtx
- Returns:
- mmtx data
-
readFont
Reads the font using a FontFileReader.- Parameters:
in- The FontFileReader to use- Throws:
IOException- In case of an I/O problem
-
initAnsiWidths
protected void initAnsiWidths()initialize the ansiWidths array (for winAnsiEncoding) and fill with the missingwidth -
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:
IOException- In case of an I/O problem
-
readFont
Reads a font.- Parameters:
in- FontFileReader to read from- Throws:
IOException- in case of an I/O problem
-
updateBBoxAndOffset
- Throws:
IOException
-
readName
- Throws:
IOException
-
initializeFont
- Throws:
IOException
-
handleCharacterSpacing
- Throws:
IOException
-
createCMaps
protected void createCMaps() -
getPostScriptName
Returns the PostScript name of the font.- Returns:
- String The PostScript name
-
getPostScriptVersion
OpenFont.PostScriptVersion getPostScriptVersion() -
getFamilyNames
Returns the font family names of the font.- Returns:
- Set The family names (a Set of Strings)
-
getSubFamilyName
Returns the font sub family name of the font.- Returns:
- String The sub family name
-
getFullName
Returns the full name of the font.- Returns:
- String The full name
-
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
-
getPadSize
protected int getPadSize(int currentPosition) Returns the number of bytes necessary to pad the currentPosition so that a table begins on a 4-byte boundary.- Parameters:
currentPosition- the position to pad.- Returns:
- int the number of bytes to pad.
-
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
Returns the StemV attribute of the font.- Returns:
- String The StemV
-
getItalicAngle
Returns the ItalicAngle attribute of the font.- Returns:
- String The ItalicAngle
-
getFontBBox
public int[] getFontBBox()- Returns:
- int[] The font bbox
-
getBBoxRaw
public int[] getBBoxRaw()Returns the original bounding box values from the HEAD table- Returns:
- An array of bounding box values
-
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
-
getBoundingBoxes
-
getBBox
public int[] getBBox(int glyphIndex) Returns an array (xMin, yMin, xMax, yMax) for a glyph.- Parameters:
glyphIndex- the index of the glyph- Returns:
- int[] Array defining bounding box.
-
getCharWidth
public int getCharWidth(int idx) Returns the width of a given character.- Parameters:
idx- Index of the character- Returns:
- int Standard width
-
getCharWidthRaw
public int getCharWidthRaw(int idx) Returns the width of a given character in raw units- Parameters:
idx- Index of the character- Returns:
- int Width in it's raw form stored in the font
-
getKerning
Returns the kerning table.- Returns:
- Map The kerning table
-
getAnsiKerning
Returns the ANSI kerning table.- Returns:
- Map The ANSI kerning table
-
getUnderlinePosition
public int getUnderlinePosition() -
getUnderlineThickness
public int getUnderlineThickness() -
getStrikeoutPosition
public int getStrikeoutPosition() -
getStrikeoutThickness
public int getStrikeoutThickness() -
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.- Throws:
IOException- in case of an I/O problem
-
readFontHeader
Read the "head" table, this reads the bounding box and sets the upem (unitsPerEM) variable- Throws:
IOException- in case of an I/O problem
-
getNumGlyphs
Read the number of glyphs from the "maxp" table- Throws:
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.- Throws:
IOException- in case of an I/O problem
-
readSVG
- Throws:
IOException
-
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- Throws:
IOException- in case of an I/O problem
-
readPostScript
Read the "post" table containing the PostScript names of the glyphs.- Throws:
IOException
-
readOS2
Read the "OS/2" table- Throws:
IOException
-
readPCLT
Read the "PCLT" table to find xHeight and capHeight.- Throws:
IOException- In case of a I/O problem
-
determineAscDesc
protected void determineAscDesc()Determines the right source for the ascender and descender values. The problem here is that the interpretation of these values is not the same for every font. There doesn't seem to be a uniform definition of an ascender and a descender. In some fonts the hhea values are defined after the Apple interpretation, but not in every font. The same problem is in the OS/2 table. FOP needs the ascender and descender to determine the baseline so we need values which add up more or less to the "em box". However, due to accent modifiers a character can grow beyond the em box. -
guessVerticalMetricsFromGlyphBBox
protected void guessVerticalMetricsFromGlyphBBox() -
readKerning
Read the kerning table, create a table for both CIDs and winAnsiEncoding.- Throws:
IOException- In case of a I/O problem
-
stream
Streams a font.- Parameters:
ttfOut- The interface for streaming TrueType tables.- Throws:
IOException- file write error
-
streamGlyf
private void streamGlyf(TTFGlyphOutputStream glyphOut, byte[] fontFile, int tableOffset, int tableLength) throws IOException - Throws:
IOException
-
sortDirTabMap
SortedSet<Map.Entry<OFTableName,OFDirTabEntry>> sortDirTabMap(Map<OFTableName, OFDirTabEntry> directoryTabs) Returns the order in which the tables in a TrueType font should be written to file.- Parameters:
directoryTabs- the map that is to be sorted.- Returns:
- TTFTablesNames[] an array of table names sorted in the order they should appear in the TTF file.
-
getCMaps
Returns this font's character to glyph mapping.- Returns:
- the font's cmap
-
checkTTC
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:
name- The name to check- Returns:
- True if not collection or font name present, false otherwise
- Throws:
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:
IOException- In case of an I/O problem
-
unicodeToWinAnsi
-
printStuff
public void printStuff()Dumps a few informational values to System.out. -
formatUnitsForDebug
-
glyphToUnicode
Map a glyph index to the corresponding unicode code point- Parameters:
glyphIndex-- Returns:
- unicode code point
-
unicodeToGlyph
Map a unicode code point to the corresponding glyph index- Parameters:
unicodeIndex- unicode code point- Returns:
- glyph index
- Throws:
IOException
-
getGlyphName
-
hasAdvancedTable
public boolean hasAdvancedTable()Determine if advanced (typographic) table is present.- Returns:
- true if advanced (typographic) table is present
-
getGDEF
Returns the GDEF table or null if none present.- Returns:
- the GDEF table
-
getGSUB
Returns the GSUB table or null if none present.- Returns:
- the GSUB table
-
getGPOS
Returns the GPOS table or null if none present.- Returns:
- the GPOS table
-
main
Static main method to get info about a TrueType font.- Parameters:
args- The command line arguments
-
getEmbedFontName
-
getCopyrightNotice
-