- java.lang.Object
-
- com.itextpdf.text.pdf.CFFFont
-
- com.itextpdf.text.pdf.CFFFontSubset
-
public class CFFFontSubset extends CFFFont
This Class subsets a CFF Type Font. The subset is preformed for CID fonts and NON CID fonts. The Charstring is subsetted for both types. For CID fonts only the FDArray which are used are embedded. The Lsubroutines of the FDArrays used are subsetted as well. The Subroutine subset supports both Type1 and Type2 formatting although only tested on Type2 Format. For Non CID the Lsubroutines are subsetted. On both types the Gsubroutines is subsetted. A font which was not of CID type is transformed into CID as a part of the subset process. The CID synthetic creation was written by Sivan Toledo (sivan@math.tau.ac.il)- Author:
- Oren Manor (manorore@post.tau.ac.il) and Ygal Blum (blumygal@post.tau.ac.il)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.itextpdf.text.pdf.CFFFont
CFFFont.DictNumberItem, CFFFont.DictOffsetItem, CFFFont.Font, CFFFont.IndexBaseItem, CFFFont.IndexMarkerItem, CFFFont.IndexOffsetItem, CFFFont.Item, CFFFont.MarkerItem, CFFFont.OffsetItem, CFFFont.RangeItem, CFFFont.StringItem, CFFFont.SubrMarkerItem, CFFFont.UInt16Item, CFFFont.UInt24Item, CFFFont.UInt32Item, CFFFont.UInt8Item
-
-
Field Summary
-
Fields inherited from class com.itextpdf.text.pdf.CFFFont
arg_count, args, buf, fonts, gsubrIndexOffset, gsubrOffsets, key, nameIndexOffset, nameOffsets, stringIndexOffset, stringOffsets, topdictIndexOffset, topdictOffsets
-
-
Constructor Summary
Constructors Constructor Description CFFFontSubset(RandomAccessFileOrArray rf, java.util.HashMap GlyphsUsed)C'tor for CFFFontSubset
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected byte[]AssembleIndex(int[] NewOffsets, byte[] NewObjects)Function creates the new index, inserting the count,offsetsize,offset array and object array.protected voidBuildFDArrayUsed(int Font)Function reads the FDSelect and builds the FDArrayUsed HashMap According to the glyphs usedprotected voidBuildFDSubrsOffsets(int Font, int FD)The function finds for the FD array processed the local subr offset and its offset array.protected voidBuildGSubrsUsed(int Font)Function scans the Glsubr used ArrayList to find recursive calls to Gsubrs and adds to Hashmap & ArrayListprotected voidBuildIndexHeader(int Count, int Offsize, int First)Function Build the header of an indexprotected voidBuildNewCharString(int FontIndex)Function uses BuildNewIndex to create the new index of the subset charstringsprotected byte[]BuildNewFile(int Font)The function builds the new output stream according to the subset processprotected byte[]BuildNewIndex(int[] Offsets, java.util.HashMap Used, byte OperatorForUnusedEntries)Function builds the new offset array, object array and assembles the index.protected voidBuildNewLGSubrs(int Font)Function builds the new local & global subsrs indices.protected voidBuildSubrUsed(int Font, int FD, int SubrOffset, int[] SubrsOffsets, java.util.HashMap hSubr, java.util.ArrayList lSubr)Function uses ReadAsubr on the glyph used to build the LSubr & Gsubr HashMap.protected intCalcBias(int Offset, int Font)Function calcs bias according to the CharString type and the count of the subrsprotected intCalcHints(int begin, int end, int LBias, int GBias, int[] LSubrsOffsets)The function reads the subroutine and returns the number of the hint in it.protected voidCopyHeader()Function Copies the header from the original fileto the output listprotected intcountEntireIndexRange(int indexOffset)Function computes the size of an indexprotected voidCreateCharset(CFFFont.OffsetItem charsetRef, int nglyphs)Function creates new CharSet for non-CID fonts.protected voidCreateFDArray(CFFFont.OffsetItem fdarrayRef, CFFFont.OffsetItem privateRef, int Font)Function creates new FDArray for non-CID fonts.protected voidCreateFDSelect(CFFFont.OffsetItem fdselectRef, int nglyphs)Function creates new FDSelect for non-CID fonts.protected voidCreateKeys(CFFFont.OffsetItem fdarrayRef, CFFFont.OffsetItem fdselectRef, CFFFont.OffsetItem charsetRef, CFFFont.OffsetItem charstringsRef)Function adds the keys into the TopDictprotected voidCreateNewStringIndex(int Font)Function takes the original string item and adds the new strings to accommodate the CID rulesprotected voidEmptyStack()Empty the Type2 Stackprotected voidHandelStack()Function Checks how the current operator effects the run time stack after being run An operator may increase or decrease the stack sizeprotected voidPopStack()Pop one element from the stackbyte[]Process(java.lang.String fontName)The Process function extracts one font out of the CFF file and returns a subset version of the original.protected voidPushStack()Add an item to the stackprotected voidReadASubr(int begin, int end, int GBias, int LBias, java.util.HashMap hSubr, java.util.ArrayList lSubr, int[] LSubrsOffsets)The function reads a subrs (glyph info) between begin and end.protected voidReadCommand()The function reads the next command after the file pointer is setprotected voidReadFDArray(int Font)Read the FDArray count, offsize and Offset arrayprotected voidreadFDSelect(int Font)Read the FDSelect of the font and compute the array and its lengthprotected intStackOpp()Function checks the key and return the change to the stack after the operator-
Methods inherited from class com.itextpdf.text.pdf.CFFFont
exists, getCID, getDictItem, getEntireIndexRange, getNames, getString, isCID
-
-
-
-
Constructor Detail
-
CFFFontSubset
public CFFFontSubset(RandomAccessFileOrArray rf, java.util.HashMap GlyphsUsed)
C'tor for CFFFontSubset- Parameters:
rf- - The font fileGlyphsUsed- - a HashMap that contains the glyph used in the subset
-
-
Method Detail
-
readFDSelect
protected void readFDSelect(int Font)
Read the FDSelect of the font and compute the array and its length- Parameters:
Font- The index of the font being processed
-
BuildFDArrayUsed
protected void BuildFDArrayUsed(int Font)
Function reads the FDSelect and builds the FDArrayUsed HashMap According to the glyphs used- Parameters:
Font- the Number of font being processed
-
ReadFDArray
protected void ReadFDArray(int Font)
Read the FDArray count, offsize and Offset array- Parameters:
Font-
-
Process
public byte[] Process(java.lang.String fontName) throws java.io.IOExceptionThe Process function extracts one font out of the CFF file and returns a subset version of the original.- Parameters:
fontName- - The name of the font to be taken out of the CFF- Returns:
- The new font stream
- Throws:
java.io.IOException
-
CalcBias
protected int CalcBias(int Offset, int Font)Function calcs bias according to the CharString type and the count of the subrs- Parameters:
Offset- The offset to the relevant subrs indexFont- the font- Returns:
- The calculated Bias
-
BuildNewCharString
protected void BuildNewCharString(int FontIndex) throws java.io.IOExceptionFunction uses BuildNewIndex to create the new index of the subset charstrings- Parameters:
FontIndex- the font- Throws:
java.io.IOException
-
BuildNewLGSubrs
protected void BuildNewLGSubrs(int Font) throws java.io.IOExceptionFunction builds the new local & global subsrs indices. IF CID then All of the FD Array lsubrs will be subsetted.- Parameters:
Font- the font- Throws:
java.io.IOException
-
BuildFDSubrsOffsets
protected void BuildFDSubrsOffsets(int Font, int FD)The function finds for the FD array processed the local subr offset and its offset array.- Parameters:
Font- the fontFD- The FDARRAY processed
-
BuildSubrUsed
protected void BuildSubrUsed(int Font, int FD, int SubrOffset, int[] SubrsOffsets, java.util.HashMap hSubr, java.util.ArrayList lSubr)Function uses ReadAsubr on the glyph used to build the LSubr & Gsubr HashMap. The HashMap (of the lsubr only) is then scanned recursively for Lsubr & Gsubrs calls.- Parameters:
Font- the fontFD- FD array processed. 0 indicates function was called by non CID fontSubrOffset- the offset to the subr index to calc the biasSubrsOffsets- the offset array of the subr indexhSubr- HashMap of the subrs usedlSubr- ArrayList of the subrs used
-
BuildGSubrsUsed
protected void BuildGSubrsUsed(int Font)
Function scans the Glsubr used ArrayList to find recursive calls to Gsubrs and adds to Hashmap & ArrayList- Parameters:
Font- the font
-
ReadASubr
protected void ReadASubr(int begin, int end, int GBias, int LBias, java.util.HashMap hSubr, java.util.ArrayList lSubr, int[] LSubrsOffsets)The function reads a subrs (glyph info) between begin and end. Adds calls to a Lsubr to the hSubr and lSubrs. Adds calls to a Gsubr to the hGSubr and lGSubrs.- Parameters:
begin- the start point of the subrend- the end point of the subrGBias- the bias of the Global SubrsLBias- the bias of the Local SubrshSubr- the HashMap for the lSubrslSubr- the ArrayList for the lSubrs
-
HandelStack
protected void HandelStack()
Function Checks how the current operator effects the run time stack after being run An operator may increase or decrease the stack size
-
StackOpp
protected int StackOpp()
Function checks the key and return the change to the stack after the operator- Returns:
- The change in the stack. 2-> flush the stack
-
EmptyStack
protected void EmptyStack()
Empty the Type2 Stack
-
PopStack
protected void PopStack()
Pop one element from the stack
-
PushStack
protected void PushStack()
Add an item to the stack
-
ReadCommand
protected void ReadCommand()
The function reads the next command after the file pointer is set
-
CalcHints
protected int CalcHints(int begin, int end, int LBias, int GBias, int[] LSubrsOffsets)The function reads the subroutine and returns the number of the hint in it. If a call to another subroutine is found the function calls recursively.- Parameters:
begin- the start point of the subrend- the end point of the subrLBias- the bias of the Local SubrsGBias- the bias of the Global SubrsLSubrsOffsets- The Offsets array of the subroutines- Returns:
- The number of hints in the subroutine read.
-
BuildNewIndex
protected byte[] BuildNewIndex(int[] Offsets, java.util.HashMap Used, byte OperatorForUnusedEntries) throws java.io.IOExceptionFunction builds the new offset array, object array and assembles the index. used for creating the glyph and subrs subsetted index- Parameters:
Offsets- the offset array of the original indexUsed- the hashmap of the used objectsOperatorForUnusedEntries- the operator inserted into the data stream for unused entries- Returns:
- the new index subset version
- Throws:
java.io.IOException
-
AssembleIndex
protected byte[] AssembleIndex(int[] NewOffsets, byte[] NewObjects)Function creates the new index, inserting the count,offsetsize,offset array and object array.- Parameters:
NewOffsets- the subsetted offset arrayNewObjects- the subsetted object array- Returns:
- the new index created
-
BuildNewFile
protected byte[] BuildNewFile(int Font)
The function builds the new output stream according to the subset process- Parameters:
Font- the font- Returns:
- the subsetted font stream
-
CopyHeader
protected void CopyHeader()
Function Copies the header from the original fileto the output list
-
BuildIndexHeader
protected void BuildIndexHeader(int Count, int Offsize, int First)Function Build the header of an index- Parameters:
Count- the count field of the indexOffsize- the offsize field of the indexFirst- the first offset of the index
-
CreateKeys
protected void CreateKeys(CFFFont.OffsetItem fdarrayRef, CFFFont.OffsetItem fdselectRef, CFFFont.OffsetItem charsetRef, CFFFont.OffsetItem charstringsRef)
Function adds the keys into the TopDict- Parameters:
fdarrayRef- OffsetItem for the FDArrayfdselectRef- OffsetItem for the FDSelectcharsetRef- OffsetItem for the CharSetcharstringsRef- OffsetItem for the CharString
-
CreateNewStringIndex
protected void CreateNewStringIndex(int Font)
Function takes the original string item and adds the new strings to accommodate the CID rules- Parameters:
Font- the font
-
CreateFDSelect
protected void CreateFDSelect(CFFFont.OffsetItem fdselectRef, int nglyphs)
Function creates new FDSelect for non-CID fonts. The FDSelect built uses a single range for all glyphs- Parameters:
fdselectRef- OffsetItem for the FDSelectnglyphs- the number of glyphs in the font
-
CreateCharset
protected void CreateCharset(CFFFont.OffsetItem charsetRef, int nglyphs)
Function creates new CharSet for non-CID fonts. The CharSet built uses a single range for all glyphs- Parameters:
charsetRef- OffsetItem for the CharSetnglyphs- the number of glyphs in the font
-
CreateFDArray
protected void CreateFDArray(CFFFont.OffsetItem fdarrayRef, CFFFont.OffsetItem privateRef, int Font)
Function creates new FDArray for non-CID fonts. The FDArray built has only the "Private" operator that points to the font's original private dict- Parameters:
fdarrayRef- OffsetItem for the FDArrayprivateRef- OffsetItem for the Private DictFont- the font
-
countEntireIndexRange
protected int countEntireIndexRange(int indexOffset)
Function computes the size of an index- Parameters:
indexOffset- The offset for the computed index- Returns:
- The size of the index
-
-