Save This Page
Home » iText-src-2.1.3 » com.lowagie » text » pdf » [javadoc | source]
com.lowagie.text.pdf
public class: CFFFontSubset [javadoc | source]
java.lang.Object
   com.lowagie.text.pdf.CFFFont
      com.lowagie.text.pdf.CFFFontSubset
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)
Field Summary
static final  String[] SubrsFunctions    The Strings in this array represent Type1/Type2 operator names 
static final  String[] SubrsEscapeFuncs    The Strings in this array represent Type1/Type2 escape operator names 
 HashMap GlyphsUsed    A HashMap containing the glyphs used in the text after being converted to glyph number by the CMap 
 ArrayList glyphsInList    The GlyphsUsed keys as an ArrayList 
 HashMap FDArrayUsed    A HashMap for keeping the FDArrays being used by the font 
 HashMap[] hSubrsUsed    A HashMaps array for keeping the subroutines used in each FontDict 
 ArrayList[] lSubrsUsed    The SubroutinesUsed HashMaps as ArrayLists 
 HashMap hGSubrsUsed    A HashMap for keeping the Global subroutines used in the font 
 ArrayList lGSubrsUsed    The Global SubroutinesUsed HashMaps as ArrayLists 
 HashMap hSubrsUsedNonCID    A HashMap for keeping the subroutines used in a non-cid font 
 ArrayList lSubrsUsedNonCID    The SubroutinesUsed HashMap as ArrayList 
 byte[][] NewLSubrsIndex    An array of the new Indexes for the local Subr. One index for each FontDict 
 byte[] NewSubrsIndexNonCID    The new subroutines index for a non-cid font 
 byte[] NewGSubrsIndex    The new global subroutines index of the font 
 byte[] NewCharStringsIndex    The new CharString of the font 
 int GBias    The bias for the global subroutines 
 LinkedList OutputList    The linked list for generating the new font stream 
 int NumOfHints    Number of arguments to the stem operators in a subroutine calculated recursively 
Fields inherited from com.lowagie.text.pdf.CFFFont:
operatorNames,  standardStrings,  nextIndexOffset,  key,  args,  arg_count,  buf,  nameIndexOffset,  topdictIndexOffset,  stringIndexOffset,  gsubrIndexOffset,  nameOffsets,  topdictOffsets,  stringOffsets,  gsubrOffsets,  fonts
Constructor:
 public CFFFontSubset(RandomAccessFileOrArray rf,
    HashMap GlyphsUsed) 
    C'tor for CFFFontSubset
    Parameters:
    rf - - The font file
    GlyphsUsed - - a HashMap that contains the glyph used in the subset
Method from com.lowagie.text.pdf.CFFFontSubset Summary:
AssembleIndex,   BuildFDArrayUsed,   BuildFDSubrsOffsets,   BuildGSubrsUsed,   BuildIndexHeader,   BuildNewCharString,   BuildNewFile,   BuildNewIndex,   BuildNewLGSubrs,   BuildSubrUsed,   CalcBias,   CalcHints,   CalcSubrOffsetSize,   CopyHeader,   CountCharset,   CountRange,   CreateCharset,   CreateFDArray,   CreateFDSelect,   CreateKeys,   CreateNewStringIndex,   CreateNonCIDPrivate,   CreateNonCIDSubrs,   EmptyStack,   HandelStack,   PopStack,   Process,   PushStack,   ReadASubr,   ReadCommand,   ReadFDArray,   Reconstruct,   ReconstructFDArray,   ReconstructPrivateDict,   ReconstructPrivateSubrs,   StackOpp,   countEntireIndexRange,   readFDSelect
Methods from com.lowagie.text.pdf.CFFFont:
ReadEncoding,   exists,   getCID,   getCard16,   getCard8,   getDictItem,   getEntireIndexRange,   getIndex,   getInt,   getNames,   getOffset,   getPosition,   getShort,   getString,   isCID,   seek
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.lowagie.text.pdf.CFFFontSubset Detail:
 protected byte[] AssembleIndex(int[] NewOffsets,
    byte[] NewObjects) 
    Function creates the new index, inserting the count,offsetsize,offset array and object array.
 protected  void BuildFDArrayUsed(int Font) 
    Function reads the FDSelect and builds the FDArrayUsed HashMap According to the glyphs used
 protected  void BuildFDSubrsOffsets(int Font,
    int FD) 
    The function finds for the FD array processed the local subr offset and its offset array.
 protected  void BuildGSubrsUsed(int Font) 
    Function scans the Glsubr used ArrayList to find recursive calls to Gsubrs and adds to Hashmap & ArrayList
 protected  void BuildIndexHeader(int Count,
    int Offsize,
    int First) 
    Function Build the header of an index
 protected  void BuildNewCharString(int FontIndex) throws IOException 
    Function uses BuildNewIndex to create the new index of the subset charstrings
 protected byte[] BuildNewFile(int Font) 
    The function builds the new output stream according to the subset process
 protected byte[] BuildNewIndex(int[] Offsets,
    HashMap Used) throws IOException 
    Function builds the new offset array, object array and assembles the index. used for creating the glyph and subrs subsetted index
 protected  void BuildNewLGSubrs(int Font) throws IOException 
    Function builds the new local & global subsrs indices. IF CID then All of the FD Array lsubrs will be subsetted.
 protected  void BuildSubrUsed(int Font,
    int FD,
    int SubrOffset,
    int[] SubrsOffsets,
    HashMap hSubr,
    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.
 protected int CalcBias(int Offset,
    int Font) 
    Function calcs bias according to the CharString type and the count of the subrs
 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.
 int CalcSubrOffsetSize(int Offset,
    int Size) 
    Calculates how many byte it took to write the offset for the subrs in a specific private dict.
 protected  void CopyHeader() 
    Function Copies the header from the original fileto the output list
 int CountCharset(int Offset,
    int NumofGlyphs) 
    Calculates the length of the charset according to its format
 int CountRange(int NumofGlyphs,
    int Type) 
    Function calculates the number of ranges in the Charset
 protected  void CreateCharset(OffsetItem charsetRef,
    int nglyphs) 
    Function creates new CharSet for non-CID fonts. The CharSet built uses a single range for all glyphs
 protected  void CreateFDArray(OffsetItem fdarrayRef,
    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
 protected  void CreateFDSelect(OffsetItem fdselectRef,
    int nglyphs) 
    Function creates new FDSelect for non-CID fonts. The FDSelect built uses a single range for all glyphs
 protected  void CreateKeys(OffsetItem fdarrayRef,
    OffsetItem fdselectRef,
    OffsetItem charsetRef,
    OffsetItem charstringsRef) 
    Function adds the keys into the TopDict
 protected  void CreateNewStringIndex(int Font) 
    Function takes the original string item and adds the new strings to accommodate the CID rules
  void CreateNonCIDPrivate(int Font,
    OffsetItem Subr) 
    The function creates a private dict for a font that was not CID All the keys are copied as is except for the subrs key
  void CreateNonCIDSubrs(int Font,
    IndexBaseItem PrivateBase,
    OffsetItem Subrs) 
    the function marks the beginning of the subrs index and adds the subsetted subrs index to the output list.
 protected  void EmptyStack() 
    Empty the Type2 Stack
 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
 protected  void PopStack() 
    Pop one element from the stack
 public byte[] Process(String fontName) throws IOException 
    The Process function extracts one font out of the CFF file and returns a subset version of the original.
 protected  void PushStack() 
    Add an item to the stack
 protected  void ReadASubr(int begin,
    int end,
    int GBias,
    int LBias,
    HashMap hSubr,
    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.
 protected  void ReadCommand() 
    The function reads the next command after the file pointer is set
 protected  void ReadFDArray(int Font) 
    Read the FDArray count, offsize and Offset array
  void Reconstruct(int Font) 
    Function reconstructs the FDArray, PrivateDict and LSubr for CID fonts
  void ReconstructFDArray(int Font,
    OffsetItem[] fdPrivate) 
    Function subsets the FDArray and builds the new one with new offsets
  void ReconstructPrivateDict(int Font,
    OffsetItem[] fdPrivate,
    IndexBaseItem[] fdPrivateBase,
    OffsetItem[] fdSubrs) 
    Function Adds the new private dicts (only for the FDs used) to the list
  void ReconstructPrivateSubrs(int Font,
    IndexBaseItem[] fdPrivateBase,
    OffsetItem[] fdSubrs) 
    Function Adds the new LSubrs dicts (only for the FDs used) to the list
 protected int StackOpp() 
    Function checks the key and return the change to the stack after the operator
 protected int countEntireIndexRange(int indexOffset) 
    Function computes the size of an index
 protected  void readFDSelect(int Font) 
    Read the FDSelect of the font and compute the array and its length