protected byte [ ] BuildNewIndex ( int [ ] Offsets , HashMap Used , byte OperatorForUnusedEntries ) throws IOException { int unusedCount = 0 ; int Offset = 0 ; int [ ] NewOffsets = new int [ Offsets . length ] ; // Build the Offsets Array for the Subset for ( int i = 0 ; i < Offsets . length ; ++ i ) { NewOffsets [ i ] = Offset ; // If the object in the offset is also present in the used // HashMap then increment the offset var by its size if ( Used . containsKey ( Integer . valueOf ( i ) ) ) { Offset += Offsets [ i + 1 ] - Offsets [ i ] ; } else { // Else the same offset is kept in i+1. unusedCount ++ ; } } // Offset var determines the size of the object array byte [ ] NewObjects = new byte [ Offset + unusedCount ] ; // Build the new Object array int unusedOffset = 0 ; for ( int i = 0 ; i < Offsets . length - 1 ; ++ i ) { int start = NewOffsets [ i ] ; int end = NewOffsets [ i + 1 ] ; NewOffsets [ i ] = start + unusedOffset ; // If start != End then the Object is used // So, we will copy the object data from the font file if ( start != end ) { // All offsets are Global Offsets relative to the beginning of the font file. // Jump the file pointer to the start address to read from. buf . seek ( Offsets [ i ] ) ; // Read from the buffer and write into the array at start. buf . readFully ( NewObjects , start + unusedOffset , end - start ) ; } else { NewObjects [ start + unusedOffset ] = OperatorForUnusedEntries ; unusedOffset ++ ; } } NewOffsets [ Offsets . length - 1 ] += unusedOffset ; // Use AssembleIndex to build the index from the offset & object arrays return AssembleIndex ( NewOffsets , NewObjects ) ; }
Function builds the new offset array object array and assembles the index . used for creating the glyph and subrs subsetted index