Package org.apache.fop.fonts.truetype
Class OTFSubSetFile
- java.lang.Object
-
- org.apache.fop.fonts.truetype.OpenFont
-
- org.apache.fop.fonts.truetype.OTFFile
-
- org.apache.fop.fonts.truetype.OTFSubSetWriter
-
- org.apache.fop.fonts.truetype.OTFSubSetFile
-
public class OTFSubSetFile extends OTFSubSetWriter
Reads an OpenType CFF file and generates a subset The OpenType specification can be found at the Microsoft Typography site: http://www.microsoft.com/typography/otspec/
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classOTFSubSetFile.BytesNumberA class used to store the last number operand and also it's size in bytesprivate static classOTFSubSetFile.FDIndexReference(package private) static classOTFSubSetFile.Offsets(package private) static classOTFSubSetFile.Type2Parser-
Nested classes/interfaces inherited from class org.apache.fop.fonts.truetype.OpenFont
OpenFont.PostScriptVersion, OpenFont.UnicodeMapping
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringACCENT_CMDprotected CFFDataReadercffReaderThe CFF reader object used to read data and offsets from the original font fileprotected java.lang.StringembeddedNameThe embedded name to change in the name tableprotected java.util.List<java.util.List<byte[]>>fdSubrsFor fonts which have an FDSelect or ROS flag in Top Dict, this is used to store the local subroutine indexes for each group as opposed to the above subsetLocalIndexSubrprotected java.util.Map<java.lang.Integer,java.lang.Integer>gidToSIDA map of the new GID to SID used to construct the charset tableprivate static intGLOBAL_SUBROUTINEThe operator used to identify a global subroutine referenceprotected CFFDataReader.CFFIndexDataglobalIndexSubrprotected java.util.List<java.lang.Integer>globalUniquesprivate static intLOCAL_SUBROUTINEThe operator used to identify a local subroutine referenceprotected CFFDataReader.CFFIndexDatalocalIndexSubrprotected java.util.List<java.lang.Integer>localUniquesA list of unique subroutines from the global / local subroutine indexesprivate MultiByteFontmbFontThe class used to represent this fontstatic intNUM_STANDARD_STRINGSThe number of standard strings in CFFprotected java.util.List<byte[]>stringIndexDataAn array used to hold the string index data for the subset fontprotected java.util.List<byte[]>subsetCharStringsIndexA list of char string data for each glyph to be stored in the subset fontprivate java.util.Map<java.lang.Integer,OTFSubSetFile.FDIndexReference>subsetFDSelectThe subset FD Select table used to store the mappings between glyphs and their associated FDFont object which point to a private dict and local subroutines.protected java.util.List<byte[]>subsetGlobalIndexSubrprotected intsubsetGlobalSubrCountprotected java.util.Map<java.lang.Integer,java.lang.Integer>subsetGlyphsA map containing each glyph to be included in the subset with their existing and new GID'sprotected java.util.List<byte[]>subsetLocalIndexSubrList of subroutines to write to the local / global indexes in the subset fontprotected intsubsetLocalSubrCountA store of the number of subroutines each global / local subroutine will storeprivate OTFSubSetFile.Type2Parsertype2ParserThe parser used to parse type2 charstring-
Fields inherited from class org.apache.fop.fonts.truetype.OTFSubSetWriter
currentPos, output
-
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
Constructors Constructor Description OTFSubSetFile()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private byte[]constructNewRefData(int curDataPos, byte[] currentData, OTFSubSetFile.BytesNumber operand, int fullSubsetIndexSize, int curSubsetIndexSize, int[] operatorCode)protected voidcreateCFF()private voidcreateCharStringData()protected voidcreateCharStringDataCID()static byte[]createNewRef(int newRef, int[] operatorCode, int forceLength, boolean isDict)private intgetBias(int subrCount)CFFDataReadergetCFFReader()Returns the parsed CFF data for the original font.private java.util.Map<java.lang.Integer,java.lang.Integer>getFormat3Index()private intgetNewRefForReference(int subrNumber, java.util.List<java.lang.Integer> uniquesArray, CFFDataReader.CFFIndexData indexSubr, java.util.List<byte[]> subsetIndexSubr, int subrCount)private intgetOffSize(int totLength)private intgetSubrNumber(int numSubroutines, int operand)protected java.util.List<java.lang.Integer>getUsedFDFonts()private booleanisCharStringBeforeFD()private voidmapChars(java.util.Map<java.lang.Integer,java.lang.Integer> usedGlyphs)private voidpreScanForSubsetIndexSize(byte[] data)private voidpreScanForSubsetIndexSize(CFFDataReader.CFFIndexData indexSubr, java.util.List<java.lang.Integer> uniques)private byte[]readCharStringData(byte[] data, int subsetLocalSubrCount)voidreadFont(FontFileReader in, java.lang.String embeddedName, MultiByteFont mbFont)Reads a font.(package private) voidreadFont(FontFileReader in, java.lang.String embeddedName, MultiByteFont mbFont, java.util.Map<java.lang.Integer,java.lang.Integer> usedGlyphs)Reads and creates a subset of the font.private byte[]resizeToFitOpLen(byte[] fdPrivateDictByteData, CFFDataReader.DICTEntry subrs)private java.util.Map<java.lang.Integer,java.lang.Integer>sortByValue(java.util.Map<java.lang.Integer,java.lang.Integer> map)protected java.util.List<java.lang.Integer>storeFDStrings(java.util.List<java.lang.Integer> uniqueNewRefs)protected voidupdateCIDOffsets(OTFSubSetFile.Offsets offsets)protected voidupdateFixedOffsets(java.util.Map<java.lang.String,CFFDataReader.DICTEntry> topDICT, OTFSubSetFile.Offsets offsets)private voidupdateOffset(byte[] out, int position, int length, int replacement)private voidupdateOffset(int position, int length, int replacement)protected voidupdateOffsets(OTFSubSetFile.Offsets offsets)private voidwriteCharsetTable(boolean cidFont)protected byte[]writeCIDCount(CFFDataReader.DICTEntry dictEntry)protected java.util.List<java.lang.Integer>writeCIDDictsAndSubrs(java.util.List<java.lang.Integer> uniqueNewRefs)private intwriteFDArray(java.util.List<java.lang.Integer> subsetFDFonts, java.util.List<java.lang.Integer> fontNameSIDs)protected intwriteFDArray(java.util.List<java.lang.Integer> uniqueNewRefs, java.util.List<java.lang.Integer> privateDictOffsets, java.util.List<java.lang.Integer> fontNameSIDs)protected voidwriteFDSelect()protected intwriteIndex(java.util.List<byte[]> dataArray)protected intwriteIndex(java.util.List<byte[]> dataArray, int offSize)protected voidwritePrivateDict()private byte[]writeROSEntry(CFFDataReader.DICTEntry dictEntry)private voidwriteStringIndex()protected intwriteTopDICT()private byte[]writeTopDictStringEntry(CFFDataReader.DICTEntry dictEntry)-
Methods inherited from class org.apache.fop.fonts.truetype.OTFSubSetWriter
concatArray, getFontSubset, writeByte, writeBytes, writeCard16, writeThreeByteNumber, writeULong
-
Methods inherited from class org.apache.fop.fonts.truetype.OTFFile
getCFFData, initializeFont, isType1, 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, readFontHeader, readHorizontalHeader, readHorizontalMetrics, readKerning, readOS2, readPCLT, readPostScript, seekTab, sortDirTabMap, stream
-
-
-
-
Field Detail
-
subsetGlyphs
protected java.util.Map<java.lang.Integer,java.lang.Integer> subsetGlyphs
A map containing each glyph to be included in the subset with their existing and new GID's
-
gidToSID
protected java.util.Map<java.lang.Integer,java.lang.Integer> gidToSID
A map of the new GID to SID used to construct the charset table
-
localIndexSubr
protected CFFDataReader.CFFIndexData localIndexSubr
-
globalIndexSubr
protected CFFDataReader.CFFIndexData globalIndexSubr
-
subsetLocalIndexSubr
protected java.util.List<byte[]> subsetLocalIndexSubr
List of subroutines to write to the local / global indexes in the subset font
-
subsetGlobalIndexSubr
protected java.util.List<byte[]> subsetGlobalIndexSubr
-
fdSubrs
protected java.util.List<java.util.List<byte[]>> fdSubrs
For fonts which have an FDSelect or ROS flag in Top Dict, this is used to store the local subroutine indexes for each group as opposed to the above subsetLocalIndexSubr
-
subsetFDSelect
private java.util.Map<java.lang.Integer,OTFSubSetFile.FDIndexReference> subsetFDSelect
The subset FD Select table used to store the mappings between glyphs and their associated FDFont object which point to a private dict and local subroutines.
-
localUniques
protected java.util.List<java.lang.Integer> localUniques
A list of unique subroutines from the global / local subroutine indexes
-
globalUniques
protected java.util.List<java.lang.Integer> globalUniques
-
subsetLocalSubrCount
protected int subsetLocalSubrCount
A store of the number of subroutines each global / local subroutine will store
-
subsetGlobalSubrCount
protected int subsetGlobalSubrCount
-
subsetCharStringsIndex
protected java.util.List<byte[]> subsetCharStringsIndex
A list of char string data for each glyph to be stored in the subset font
-
embeddedName
protected java.lang.String embeddedName
The embedded name to change in the name table
-
stringIndexData
protected java.util.List<byte[]> stringIndexData
An array used to hold the string index data for the subset font
-
cffReader
protected CFFDataReader cffReader
The CFF reader object used to read data and offsets from the original font file
-
mbFont
private MultiByteFont mbFont
The class used to represent this font
-
NUM_STANDARD_STRINGS
public static final int NUM_STANDARD_STRINGS
The number of standard strings in CFF- See Also:
- Constant Field Values
-
LOCAL_SUBROUTINE
private static final int LOCAL_SUBROUTINE
The operator used to identify a local subroutine reference- See Also:
- Constant Field Values
-
GLOBAL_SUBROUTINE
private static final int GLOBAL_SUBROUTINE
The operator used to identify a global subroutine reference- See Also:
- Constant Field Values
-
ACCENT_CMD
private static final java.lang.String ACCENT_CMD
- See Also:
- Constant Field Values
-
type2Parser
private OTFSubSetFile.Type2Parser type2Parser
The parser used to parse type2 charstring
-
-
Method Detail
-
readFont
public void readFont(FontFileReader in, java.lang.String embeddedName, MultiByteFont mbFont) throws java.io.IOException
Description copied from class:OpenFontReads a font.
-
readFont
void readFont(FontFileReader in, java.lang.String embeddedName, MultiByteFont mbFont, java.util.Map<java.lang.Integer,java.lang.Integer> usedGlyphs) throws java.io.IOException
Reads and creates a subset of the font.- Parameters:
in- FontFileReader to read fromembeddedName- Name to be checked for in the font fileusedGlyphs- 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
-
mapChars
private void mapChars(java.util.Map<java.lang.Integer,java.lang.Integer> usedGlyphs) throws java.io.IOException- Throws:
java.io.IOException
-
sortByValue
private java.util.Map<java.lang.Integer,java.lang.Integer> sortByValue(java.util.Map<java.lang.Integer,java.lang.Integer> map)
-
createCFF
protected void createCFF() throws java.io.IOException- Throws:
java.io.IOException
-
writeFDArray
private int writeFDArray(java.util.List<java.lang.Integer> subsetFDFonts, java.util.List<java.lang.Integer> fontNameSIDs) throws java.io.IOException- Throws:
java.io.IOException
-
isCharStringBeforeFD
private boolean isCharStringBeforeFD()
-
storeFDStrings
protected java.util.List<java.lang.Integer> storeFDStrings(java.util.List<java.lang.Integer> uniqueNewRefs) throws java.io.IOException- Throws:
java.io.IOException
-
writeTopDICT
protected int writeTopDICT() throws java.io.IOException- Throws:
java.io.IOException
-
writeROSEntry
private byte[] writeROSEntry(CFFDataReader.DICTEntry dictEntry) throws java.io.IOException
- Throws:
java.io.IOException
-
writeCIDCount
protected byte[] writeCIDCount(CFFDataReader.DICTEntry dictEntry) throws java.io.IOException
- Throws:
java.io.IOException
-
writeTopDictStringEntry
private byte[] writeTopDictStringEntry(CFFDataReader.DICTEntry dictEntry) throws java.io.IOException
- Throws:
java.io.IOException
-
writeStringIndex
private void writeStringIndex() throws java.io.IOException- Throws:
java.io.IOException
-
createCharStringDataCID
protected void createCharStringDataCID() throws java.io.IOException- Throws:
java.io.IOException
-
writeFDSelect
protected void writeFDSelect()
-
getFormat3Index
private java.util.Map<java.lang.Integer,java.lang.Integer> getFormat3Index()
-
getUsedFDFonts
protected java.util.List<java.lang.Integer> getUsedFDFonts()
-
writeCIDDictsAndSubrs
protected java.util.List<java.lang.Integer> writeCIDDictsAndSubrs(java.util.List<java.lang.Integer> uniqueNewRefs) throws java.io.IOException- Throws:
java.io.IOException
-
resizeToFitOpLen
private byte[] resizeToFitOpLen(byte[] fdPrivateDictByteData, CFFDataReader.DICTEntry subrs) throws java.io.IOException- Throws:
java.io.IOException
-
writeFDArray
protected int writeFDArray(java.util.List<java.lang.Integer> uniqueNewRefs, java.util.List<java.lang.Integer> privateDictOffsets, java.util.List<java.lang.Integer> fontNameSIDs) throws java.io.IOException- Throws:
java.io.IOException
-
createCharStringData
private void createCharStringData() throws java.io.IOException- Throws:
java.io.IOException
-
preScanForSubsetIndexSize
private void preScanForSubsetIndexSize(byte[] data) throws java.io.IOException- Throws:
java.io.IOException
-
preScanForSubsetIndexSize
private void preScanForSubsetIndexSize(CFFDataReader.CFFIndexData indexSubr, java.util.List<java.lang.Integer> uniques) throws java.io.IOException
- Throws:
java.io.IOException
-
getSubrNumber
private int getSubrNumber(int numSubroutines, int operand)
-
readCharStringData
private byte[] readCharStringData(byte[] data, int subsetLocalSubrCount) throws java.io.IOException- Throws:
java.io.IOException
-
getNewRefForReference
private int getNewRefForReference(int subrNumber, java.util.List<java.lang.Integer> uniquesArray, CFFDataReader.CFFIndexData indexSubr, java.util.List<byte[]> subsetIndexSubr, int subrCount) throws java.io.IOException- Throws:
java.io.IOException
-
getBias
private int getBias(int subrCount)
-
constructNewRefData
private byte[] constructNewRefData(int curDataPos, byte[] currentData, OTFSubSetFile.BytesNumber operand, int fullSubsetIndexSize, int curSubsetIndexSize, int[] operatorCode) throws java.io.IOException- Throws:
java.io.IOException
-
createNewRef
public static byte[] createNewRef(int newRef, int[] operatorCode, int forceLength, boolean isDict)
-
writeIndex
protected int writeIndex(java.util.List<byte[]> dataArray)
-
writeIndex
protected int writeIndex(java.util.List<byte[]> dataArray, int offSize)
-
getOffSize
private int getOffSize(int totLength)
-
writeCharsetTable
private void writeCharsetTable(boolean cidFont) throws java.io.IOException- Throws:
java.io.IOException
-
writePrivateDict
protected void writePrivateDict() throws java.io.IOException- Throws:
java.io.IOException
-
updateOffsets
protected void updateOffsets(OTFSubSetFile.Offsets offsets) throws java.io.IOException
- Throws:
java.io.IOException
-
updateFixedOffsets
protected void updateFixedOffsets(java.util.Map<java.lang.String,CFFDataReader.DICTEntry> topDICT, OTFSubSetFile.Offsets offsets) throws java.io.IOException
- Throws:
java.io.IOException
-
updateCIDOffsets
protected void updateCIDOffsets(OTFSubSetFile.Offsets offsets) throws java.io.IOException
- Throws:
java.io.IOException
-
updateOffset
private void updateOffset(int position, int length, int replacement) throws java.io.IOException- Throws:
java.io.IOException
-
updateOffset
private void updateOffset(byte[] out, int position, int length, int replacement)
-
getCFFReader
public CFFDataReader getCFFReader()
Returns the parsed CFF data for the original font.- Returns:
- The CFFDataReader contaiing the parsed data
-
-