Class TTFSubSetFile
java.lang.Object
org.docx4j.fonts.fop.fonts.truetype.OpenFont
org.docx4j.fonts.fop.fonts.truetype.TTFFile
org.docx4j.fonts.fop.fonts.truetype.TTFSubSetFile
public class TTFSubSetFile extends TTFFile
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.docx4j.fonts.fop.fonts.truetype.OpenFont
OpenFont.PostScriptVersion -
Field Summary
Fields Modifier and Type Field Description protected intcurrentPosprotected int[]glyphOffsetsStores the glyph offsets so that we can end strings at glyph boundariesprotected intlocaOffsetprotected java.util.Map<OFTableName,OFDirTabEntry>newDirTabsThe dir tab entries in the new subset font.protected java.util.Map<OFTableName,java.lang.Integer>offsetsprotected byte[]outputprotected intrealSizeFields inherited from class org.docx4j.fonts.fop.fonts.truetype.OpenFont
advancedTableReader, cid, dirTabs, embedFontName, familyNames, fontFile, fullName, lastLoca, locaFormat, mtxTab, nhmtx, notice, numberOfGlyphs, postScriptName, subFamilyName, TRACE_ENABLED, unicodeMappings, useAdvanced, useKerning -
Constructor Summary
Constructors Constructor Description TTFSubSetFile()Default ConstructorTTFSubSetFile(boolean useKerning, boolean useAdvanced)Constructor -
Method Summary
Modifier and Type Method Description protected int[]buildSubsetIndexToOrigIndexMap(java.util.Map<java.lang.Integer,java.lang.Integer> glyphs)protected voidcreateCheckSumAdjustment()protected booleancreateCvt(FontFileReader in)Copy the cvt table as is from original font to subset fontprotected voidcreateDirectory()Create the directory tableprotected booleancreateFpgm(FontFileReader in)Copy the fpgm table as is from original font to subset fontprotected voidcreateHead(FontFileReader in)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 voidcreateHhea(FontFileReader in, int size)Copy the hhea table as is from original font to subset font and fill in size of hmtx tableprotected voidcreateHmtx(FontFileReader in, java.util.Map<java.lang.Integer,java.lang.Integer> glyphs)Create the hmtx table by copying metrics from original font to subset font.protected voidcreateLoca(int size)Create an empty loca table without updating checksumprotected voidcreateMaxp(FontFileReader in, int size)Copy the maxp table as is from original font to subset font and set num glyphs to sizeprotected booleancreateName(FontFileReader in)Copy the name table as is from the original.protected booleancreateOS2(FontFileReader in)Copy the OS/2 table as is from the original.protected voidcreatePost(FontFileReader in)protected booleancreatePrep(FontFileReader in)Copy the prep table as is from original font to subset fontprotected static intgetCheckSum(byte[] data, int start, int size)byte[]getFontSubset()Returns a subset of the fonts (readFont() MUST be called first in order to create the subset).protected voidpad4()Create a padding in the fontfile to align on a 4-byte boundaryvoidreadFont(FontFileReader in, java.lang.String name, java.lang.String header, java.util.Map<java.lang.Integer,java.lang.Integer> glyphs)Reads a font and creates a subset of the font.protected voidscanGlyphs(FontFileReader in, java.util.Map<java.lang.Integer,java.lang.Integer> subsetGlyphs)voidstream(TTFOutputStream ttfOut)Streams a font.protected voidupdateCheckSum(int tableStart, int tableSize, OFTableName tableName)protected voidwriteBytes(byte[] b)protected voidwriteULong(int pos, int s)Appends a ULONG to the output array, at the given position without changing currentPosprotected voidwriteUShort(int s)Appends a USHORT to the output array, updates currentPost but not realSizeprotected voidwriteUShort(int pos, int s)Appends a USHORT to the output array, at the given position without changing currentPosMethods inherited from class org.docx4j.fonts.fop.fonts.truetype.TTFFile
getLastGlyfLocation, initializeFont, readIndexToLocation, readName, updateBBoxAndOffsetMethods inherited from class org.docx4j.fonts.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, getGPOS, getGSUB, getItalicAngle, getKerning, getLastChar, getLowerCaseAscent, getLowerCaseDescent, getMtx, getNumGlyphs, getPadSize, getPanose, getPostScriptName, 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, seekTabMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
output
protected byte[] output -
realSize
protected int realSize -
currentPos
protected int currentPos -
offsets
-
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
-
createDirectory
protected void createDirectory()Create the directory table -
createLoca
protected void createLoca(int size) throws java.io.IOExceptionCreate an empty loca table without updating checksum- Throws:
java.io.IOException
-
createCvt
Copy the cvt table as is from original font to subset font- Throws:
java.io.IOException
-
createFpgm
Copy the fpgm table as is from original font to subset font- Throws:
java.io.IOException
-
createName
Copy the name table as is from the original.- Throws:
java.io.IOException
-
createOS2
Copy the OS/2 table as is from the original.- Throws:
java.io.IOException
-
createMaxp
Copy the maxp table as is from original font to subset font and set num glyphs to size- Throws:
java.io.IOException
-
createPost
- Throws:
java.io.IOException
-
createPrep
Copy the prep table as is from original font to subset font- Throws:
java.io.IOException
-
createHhea
Copy the hhea table as is from original font to subset font and fill in size of hmtx table- Throws:
java.io.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:
java.io.IOException
-
buildSubsetIndexToOrigIndexMap
protected int[] buildSubsetIndexToOrigIndexMap(java.util.Map<java.lang.Integer,java.lang.Integer> glyphs) -
createHmtx
protected void createHmtx(FontFileReader in, java.util.Map<java.lang.Integer,java.lang.Integer> glyphs) throws java.io.IOExceptionCreate 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:
java.io.IOException
-
readFont
public void readFont(FontFileReader in, java.lang.String name, java.lang.String header, java.util.Map<java.lang.Integer,java.lang.Integer> glyphs) throws java.io.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:
java.io.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
-
stream
Description copied from class:OpenFontStreams a font. -
scanGlyphs
protected void scanGlyphs(FontFileReader in, java.util.Map<java.lang.Integer,java.lang.Integer> subsetGlyphs) throws java.io.IOException- Throws:
java.io.IOException
-
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 -
updateCheckSum
-
getCheckSum
protected static int getCheckSum(byte[] data, int start, int size) -
createCheckSumAdjustment
protected void createCheckSumAdjustment()
-