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
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 ClassesModifier and TypeClassDescription(package private) static class
A class used to store the last number operand and also it's size in bytesprivate static class
(package private) static class
(package private) static class
Nested classes/interfaces inherited from class org.apache.fop.fonts.truetype.OpenFont
OpenFont.PostScriptVersion, OpenFont.UnicodeMapping
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
protected CFFDataReader
The CFF reader object used to read data and offsets from the original font fileprotected String
The embedded name to change in the name tableFor 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 subsetLocalIndexSubrA map of the new GID to SID used to construct the charset tableprivate static final int
The operator used to identify a global subroutine referenceprotected CFFDataReader.CFFIndexData
private static final int
The operator used to identify a local subroutine referenceprotected CFFDataReader.CFFIndexData
A list of unique subroutines from the global / local subroutine indexesprivate MultiByteFont
The class used to represent this fontstatic final int
The number of standard strings in CFFprotected List<byte[]>
An array used to hold the string index data for the subset fontprotected List<byte[]>
A list of char string data for each glyph to be stored in the subset fontprivate Map<Integer,
OTFSubSetFile.FDIndexReference> 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.protected List<byte[]>
protected int
A map containing each glyph to be included in the subset with their existing and new GID'sprotected List<byte[]>
List of subroutines to write to the local / global indexes in the subset fontprotected int
A store of the number of subroutines each global / local subroutine will storeprivate OTFSubSetFile.Type2Parser
The parser used to parse type2 charstringFields 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 -
Method Summary
Modifier and TypeMethodDescriptionprivate byte[]
constructNewRefData
(int curDataPos, byte[] currentData, OTFSubSetFile.BytesNumber operand, int fullSubsetIndexSize, int curSubsetIndexSize, int[] operatorCode) protected void
private void
protected void
static byte[]
createNewRef
(int newRef, int[] operatorCode, int forceLength, boolean isDict) private int
getBias
(int subrCount) Returns the parsed CFF data for the original font.private int
getNewRefForReference
(int subrNumber, List<Integer> uniquesArray, CFFDataReader.CFFIndexData indexSubr, List<byte[]> subsetIndexSubr, int subrCount) private int
getOffSize
(int totLength) private int
getSubrNumber
(int numSubroutines, int operand) private boolean
private void
private void
preScanForSubsetIndexSize
(byte[] data) private void
preScanForSubsetIndexSize
(CFFDataReader.CFFIndexData indexSubr, List<Integer> uniques) private byte[]
readCharStringData
(byte[] data, int subsetLocalSubrCount) void
readFont
(FontFileReader in, String embeddedName, MultiByteFont mbFont) Reads a font.(package private) void
readFont
(FontFileReader in, String embeddedName, MultiByteFont mbFont, Map<Integer, Integer> usedGlyphs) Reads and creates a subset of the font.private byte[]
resizeToFitOpLen
(byte[] fdPrivateDictByteData, CFFDataReader.DICTEntry subrs) sortByValue
(Map<Integer, Integer> map) storeFDStrings
(List<Integer> uniqueNewRefs) protected void
updateCIDOffsets
(OTFSubSetFile.Offsets offsets) protected void
updateFixedOffsets
(Map<String, CFFDataReader.DICTEntry> topDICT, OTFSubSetFile.Offsets offsets) private void
updateOffset
(byte[] out, int position, int length, int replacement) private void
updateOffset
(int position, int length, int replacement) protected void
updateOffsets
(OTFSubSetFile.Offsets offsets) private void
writeCharsetTable
(boolean cidFont) protected byte[]
writeCIDCount
(CFFDataReader.DICTEntry dictEntry) writeCIDDictsAndSubrs
(List<Integer> uniqueNewRefs) private int
writeFDArray
(List<Integer> subsetFDFonts, List<Integer> fontNameSIDs) protected int
writeFDArray
(List<Integer> uniqueNewRefs, List<Integer> privateDictOffsets, List<Integer> fontNameSIDs) protected void
protected int
writeIndex
(List<byte[]> dataArray) protected int
writeIndex
(List<byte[]> dataArray, int offSize) protected void
private byte[]
writeROSEntry
(CFFDataReader.DICTEntry dictEntry) private void
protected int
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 Details
-
subsetGlyphs
A map containing each glyph to be included in the subset with their existing and new GID's -
gidToSID
A map of the new GID to SID used to construct the charset table -
localIndexSubr
-
globalIndexSubr
-
subsetLocalIndexSubr
List of subroutines to write to the local / global indexes in the subset font -
subsetGlobalIndexSubr
-
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
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
A list of unique subroutines from the global / local subroutine indexes -
globalUniques
-
subsetLocalSubrCount
protected int subsetLocalSubrCountA store of the number of subroutines each global / local subroutine will store -
subsetGlobalSubrCount
protected int subsetGlobalSubrCount -
subsetCharStringsIndex
A list of char string data for each glyph to be stored in the subset font -
embeddedName
The embedded name to change in the name table -
stringIndexData
An array used to hold the string index data for the subset font -
cffReader
The CFF reader object used to read data and offsets from the original font file -
mbFont
The class used to represent this font -
NUM_STANDARD_STRINGS
public static final int NUM_STANDARD_STRINGSThe number of standard strings in CFF- See Also:
-
LOCAL_SUBROUTINE
private static final int LOCAL_SUBROUTINEThe operator used to identify a local subroutine reference- See Also:
-
GLOBAL_SUBROUTINE
private static final int GLOBAL_SUBROUTINEThe operator used to identify a global subroutine reference- See Also:
-
ACCENT_CMD
- See Also:
-
type2Parser
The parser used to parse type2 charstring
-
-
Constructor Details
-
OTFSubSetFile
- Throws:
IOException
-
-
Method Details
-
readFont
public void readFont(FontFileReader in, String embeddedName, MultiByteFont mbFont) throws IOException Description copied from class:OpenFont
Reads a font.- Overrides:
readFont
in classOpenFont
- Parameters:
in
- FontFileReader to read from- Throws:
IOException
- in case of an I/O problem
-
readFont
void readFont(FontFileReader in, String embeddedName, MultiByteFont mbFont, Map<Integer, Integer> usedGlyphs) throws IOExceptionReads 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:
IOException
- in case of an I/O problem
-
mapChars
- Throws:
IOException
-
sortByValue
-
createCFF
- Throws:
IOException
-
writeFDArray
private int writeFDArray(List<Integer> subsetFDFonts, List<Integer> fontNameSIDs) throws IOException - Throws:
IOException
-
isCharStringBeforeFD
private boolean isCharStringBeforeFD() -
storeFDStrings
- Throws:
IOException
-
writeTopDICT
- Throws:
IOException
-
writeROSEntry
- Throws:
IOException
-
writeCIDCount
- Throws:
IOException
-
writeTopDictStringEntry
- Throws:
IOException
-
writeStringIndex
- Throws:
IOException
-
createCharStringDataCID
- Throws:
IOException
-
writeFDSelect
protected void writeFDSelect() -
getFormat3Index
-
getUsedFDFonts
-
writeCIDDictsAndSubrs
- Throws:
IOException
-
resizeToFitOpLen
private byte[] resizeToFitOpLen(byte[] fdPrivateDictByteData, CFFDataReader.DICTEntry subrs) throws IOException - Throws:
IOException
-
writeFDArray
protected int writeFDArray(List<Integer> uniqueNewRefs, List<Integer> privateDictOffsets, List<Integer> fontNameSIDs) throws IOException - Throws:
IOException
-
createCharStringData
- Throws:
IOException
-
preScanForSubsetIndexSize
- Throws:
IOException
-
preScanForSubsetIndexSize
private void preScanForSubsetIndexSize(CFFDataReader.CFFIndexData indexSubr, List<Integer> uniques) throws IOException - Throws:
IOException
-
getSubrNumber
private int getSubrNumber(int numSubroutines, int operand) -
readCharStringData
- Throws:
IOException
-
getNewRefForReference
private int getNewRefForReference(int subrNumber, List<Integer> uniquesArray, CFFDataReader.CFFIndexData indexSubr, List<byte[]> subsetIndexSubr, int subrCount) throws IOException - Throws:
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 IOException - Throws:
IOException
-
createNewRef
public static byte[] createNewRef(int newRef, int[] operatorCode, int forceLength, boolean isDict) -
writeIndex
-
writeIndex
-
getOffSize
private int getOffSize(int totLength) -
writeCharsetTable
- Throws:
IOException
-
writePrivateDict
- Throws:
IOException
-
updateOffsets
- Throws:
IOException
-
updateFixedOffsets
protected void updateFixedOffsets(Map<String, CFFDataReader.DICTEntry> topDICT, OTFSubSetFile.Offsets offsets) throws IOException- Throws:
IOException
-
updateCIDOffsets
- Throws:
IOException
-
updateOffset
- Throws:
IOException
-
updateOffset
private void updateOffset(byte[] out, int position, int length, int replacement) -
getCFFReader
Returns the parsed CFF data for the original font.- Returns:
- The CFFDataReader contaiing the parsed data
-