Package org.apache.fop.fonts.truetype
Class TTFSubSetFile
java.lang.Object
org.apache.fop.fonts.truetype.OpenFont
org.apache.fop.fonts.truetype.TTFFile
org.apache.fop.fonts.truetype.TTFSubSetFile
Reads a TrueType file and generates a subset
that can be used to embed a TrueType CID font.
TrueType tables needed for embedded CID fonts are:
"head", "hhea", "loca", "maxp", "cvt ", "prep", "glyf", "hmtx" and "fpgm".
The TrueType spec can be found at the Microsoft
Typography site: http://www.microsoft.com/truetype/
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.fop.fonts.truetype.OpenFont
OpenFont.PostScriptVersion, OpenFont.UnicodeMapping
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
protected int
protected int[]
Stores the glyph offsets so that we can end strings at glyph boundariesprotected int
protected Map
<OFTableName, OFDirTabEntry> The dir tab entries in the new subset font.protected Map
<OFTableName, Integer> protected byte[]
protected int
Fields inherited from class org.apache.fop.fonts.truetype.OpenFont
advancedTableReader, cid, dirTabs, embedFontName, ENC_BUF_SIZE, familyNames, fontFile, fullName, lastLoca, locaFormat, log, MAX_CHAR_CODE, mtxTab, nhmtx, notice, NTABS, numberOfGlyphs, postScriptName, subFamilyName, svgs, TRACE_ENABLED, unicodeMappings, useAdvanced, useKerning
-
Constructor Summary
ConstructorsConstructorDescriptionDefault ConstructorTTFSubSetFile
(boolean useKerning, boolean useAdvanced) Constructor -
Method Summary
Modifier and TypeMethodDescriptionprotected int[]
buildSubsetIndexToOrigIndexMap
(Map<Integer, Integer> glyphs) private boolean
copyTable
(FontFileReader in, OFTableName tableName) protected void
protected boolean
Copy the cvt table as is from original font to subset fontprotected void
Create the directory tableprotected boolean
Copy the fpgm table as is from original font to subset fontprivate void
createGlyf
(FontFileReader in, Map<Integer, Integer> glyphs) Create the glyf table and fill in loca tableprotected void
Copy the head table as is from original font to subset font and set indexToLocaFormat to long and set checkSumAdjustment to 0, store offset to checkSumAdjustment in checkSumAdjustmentOffsetprotected void
createHhea
(FontFileReader in, int size) Copy the hhea table as is from original font to subset font and fill in size of hmtx tableprotected void
createHmtx
(FontFileReader in, Map<Integer, Integer> glyphs) Create the hmtx table by copying metrics from original font to subset font.protected void
createLoca
(int size) Create an empty loca table without updating checksumprotected void
createMaxp
(FontFileReader in, int size) Copy the maxp table as is from original font to subset font and set num glyphs to sizeprotected boolean
Copy the name table as is from the original.protected boolean
Copy the OS/2 table as is from the original.protected void
protected boolean
Copy the prep table as is from original font to subset fontprivate int
protected static int
getCheckSum
(byte[] data, int start, int size) byte[]
Returns a subset of the fonts (readFont() MUST be called first in order to create the subset).private void
handleGlyphSubset
(TTFGlyphOutputStream glyphOut) private boolean
hasCvt()
private boolean
hasFpgm()
private boolean
hasPrep()
private int
maxPow2
(int max) Returns the maximum power of 2 invalid input: '<'= maxprotected void
pad4()
Create a padding in the fontfile to align on a 4-byte boundaryvoid
Reads a font and creates a subset of the font.protected void
scanGlyphs
(FontFileReader in, Map<Integer, Integer> subsetGlyphs) void
stream
(TTFOutputStream ttfOut) Streams a font.protected void
updateCheckSum
(int tableStart, int tableSize, OFTableName tableName) private void
writeByte
(byte b) Appends a byte to the output array, updates currentPost but not realSizeprotected void
writeBytes
(byte[] b) private int
writeString
(String str) writes a ISO-8859-1 string at the currentPosition updates currentPosition but not realSizeprivate void
writeTableName
(OFTableName tableName) protected void
writeULong
(int pos, int s) Appends a ULONG to the output array, at the given position without changing currentPosprotected void
writeUShort
(int s) Appends a USHORT to the output array, updates currentPost but not realSizeprotected void
writeUShort
(int pos, int s) Appends a USHORT to the output array, at the given position without changing currentPosMethods inherited from class org.apache.fop.fonts.truetype.TTFFile
getLastGlyfLocation, initializeFont, readIndexToLocation, readName, updateBBoxAndOffset
Methods inherited from class org.apache.fop.fonts.truetype.OpenFont
checkTTC, convertTTFUnit2PDFUnit, createCMaps, determineAscDesc, getAnsiKerning, getBBox, getBBoxRaw, getBoundingBoxes, getCapHeight, getCharSetName, getCharWidth, getCharWidthRaw, getCMaps, getCopyrightNotice, getDirectoryEntry, getEmbedFontName, getFamilyNames, getFirstChar, getFlags, getFontBBox, getFullName, getGDEF, getGlyphName, getGPOS, getGSUB, getItalicAngle, getKerning, getLastChar, getLowerCaseAscent, getLowerCaseDescent, getMtx, getNumGlyphs, getPadSize, getPostScriptName, getPostScriptVersion, getStemV, getStrikeoutPosition, getStrikeoutThickness, getSubFamilyName, getTTCnames, getUnderlinePosition, getUnderlineThickness, getWeightClass, getWidths, getXHeight, guessVerticalMetricsFromGlyphBBox, handleCharacterSpacing, hasAdvancedTable, initAnsiWidths, isCFF, isEmbeddable, main, printStuff, readCMAP, readDirTabs, readFont, readFont, readFont, readFontHeader, readHorizontalHeader, readHorizontalMetrics, readKerning, readOS2, readPCLT, readPostScript, seekTab, sortDirTabMap
-
Field Details
-
output
protected byte[] output -
realSize
protected int realSize -
currentPos
protected int currentPos -
offsets
-
checkSumAdjustmentOffset
private int checkSumAdjustmentOffset -
locaOffset
protected int locaOffset -
glyphOffsets
protected int[] glyphOffsetsStores the glyph offsets so that we can end strings at glyph boundaries -
newDirTabs
The dir tab entries in the new subset font.
-
-
Constructor Details
-
TTFSubSetFile
public TTFSubSetFile()Default Constructor -
TTFSubSetFile
public TTFSubSetFile(boolean useKerning, boolean useAdvanced) Constructor- Parameters:
useKerning
- true if kerning data should be loadeduseAdvanced
- true if advanced typographic tables should be loaded
-
-
Method Details
-
determineTableCount
private int determineTableCount() -
createDirectory
protected void createDirectory()Create the directory table -
writeTableName
-
hasCvt
private boolean hasCvt() -
hasFpgm
private boolean hasFpgm() -
hasPrep
private boolean hasPrep() -
createLoca
Create an empty loca table without updating checksum- Throws:
IOException
-
copyTable
- Throws:
IOException
-
createCvt
Copy the cvt table as is from original font to subset font- Throws:
IOException
-
createFpgm
Copy the fpgm table as is from original font to subset font- Throws:
IOException
-
createName
Copy the name table as is from the original.- Throws:
IOException
-
createOS2
Copy the OS/2 table as is from the original.- Throws:
IOException
-
createMaxp
Copy the maxp table as is from original font to subset font and set num glyphs to size- Throws:
IOException
-
createPost
- Throws:
IOException
-
createPrep
Copy the prep table as is from original font to subset font- Throws:
IOException
-
createHhea
Copy the hhea table as is from original font to subset font and fill in size of hmtx table- Throws:
IOException
-
createHead
Copy the head table as is from original font to subset font and set indexToLocaFormat to long and set checkSumAdjustment to 0, store offset to checkSumAdjustment in checkSumAdjustmentOffset- Throws:
IOException
-
createGlyf
Create the glyf table and fill in loca table- Throws:
IOException
-
buildSubsetIndexToOrigIndexMap
-
createHmtx
Create the hmtx table by copying metrics from original font to subset font. The glyphs Map contains an Integer key and Integer value that maps the original metric (key) to the subset metric (value)- Throws:
IOException
-
readFont
public void readFont(FontFileReader in, String name, String header, Map<Integer, Integer> glyphs) throws IOExceptionReads a font and creates a subset of the font.- Parameters:
in
- FontFileReader to read fromname
- Name to be checked for in the font fileglyphs
- Map of glyphs (glyphs has old index as (Integer) key and new index as (Integer) value)- Throws:
IOException
- in case of an I/O problem
-
getFontSubset
public byte[] getFontSubset()Returns a subset of the fonts (readFont() MUST be called first in order to create the subset).- Returns:
- byte array
-
handleGlyphSubset
- Throws:
IOException
-
stream
Description copied from class:OpenFont
Streams a font.- Overrides:
stream
in classOpenFont
- Parameters:
ttfOut
- The interface for streaming TrueType tables.- Throws:
IOException
- file write error
-
scanGlyphs
- Throws:
IOException
-
writeString
writes a ISO-8859-1 string at the currentPosition updates currentPosition but not realSize- Returns:
- number of bytes written
-
writeByte
private void writeByte(byte b) Appends a byte to the output array, updates currentPost but not realSize -
writeBytes
protected void writeBytes(byte[] b) -
writeUShort
protected void writeUShort(int s) Appends a USHORT to the output array, updates currentPost but not realSize -
writeUShort
protected void writeUShort(int pos, int s) Appends a USHORT to the output array, at the given position without changing currentPos -
writeULong
protected void writeULong(int pos, int s) Appends a ULONG to the output array, at the given position without changing currentPos -
pad4
protected void pad4()Create a padding in the fontfile to align on a 4-byte boundary -
maxPow2
private int maxPow2(int max) Returns the maximum power of 2 invalid input: '<'= max -
updateCheckSum
-
getCheckSum
protected static int getCheckSum(byte[] data, int start, int size) -
createCheckSumAdjustment
protected void createCheckSumAdjustment()
-