@@ -477,7 +477,7 @@ virtual protected void BuildNewLGSubrs(int Font)
477
477
// Builds the New Local Subrs index
478
478
NewSubrsIndexNonCID = BuildNewIndex ( fonts [ Font ] . SubrsOffsets , hSubrsUsedNonCID , RETURN_OP ) ;
479
479
//Builds the New Global Subrs index
480
- NewGSubrsIndex = BuildNewIndex ( gsubrOffsets , hGSubrsUsed , RETURN_OP ) ;
480
+ NewGSubrsIndex = BuildNewIndexAndCopyAllGSubrs ( gsubrOffsets , RETURN_OP ) ;
481
481
}
482
482
483
483
/**
@@ -972,6 +972,59 @@ virtual protected byte[] BuildNewIndex(int[] Offsets,Dictionary<int,int[]> Used,
972
972
return AssembleIndex ( NewOffsets , NewObjects ) ;
973
973
}
974
974
975
+ /**
976
+ * Function builds the new offset array, object array and assembles the index.
977
+ * used for creating the glyph and subrs subsetted index
978
+ * @param Offsets the offset array of the original index
979
+ * @param OperatorForUnusedEntries the operator inserted into the data stream for unused entries
980
+ * @return the new index subset version
981
+ * @throws IOException
982
+ */
983
+ virtual protected byte [ ] BuildNewIndexAndCopyAllGSubrs ( int [ ] Offsets , byte OperatorForUnusedEntries )
984
+ {
985
+ int unusedCount = 0 ;
986
+ int Offset = 0 ;
987
+ int [ ] NewOffsets = new int [ Offsets . Length ] ;
988
+ // Build the Offsets Array for the Subset
989
+ for ( int i = 0 ; i < Offsets . Length - 1 ; ++ i )
990
+ {
991
+ NewOffsets [ i ] = Offset ;
992
+ Offset += Offsets [ i + 1 ] - Offsets [ i ] ;
993
+ }
994
+ // Else the same offset is kept in i+1
995
+ NewOffsets [ Offsets . Length - 1 ] = Offset ;
996
+ unusedCount ++ ;
997
+
998
+ // Offset var determines the size of the object array
999
+ byte [ ] NewObjects = new byte [ Offset + unusedCount ] ;
1000
+ // Build the new Object array
1001
+ int unusedOffset = 0 ;
1002
+ for ( int i = 0 ; i < Offsets . Length - 1 ; ++ i )
1003
+ {
1004
+ int start = NewOffsets [ i ] ;
1005
+ int end = NewOffsets [ i + 1 ] ;
1006
+ NewOffsets [ i ] = start + unusedOffset ;
1007
+ // If start != End then the Object is used
1008
+ // So, we will copy the object data from the font file
1009
+ if ( start != end )
1010
+ {
1011
+ // All offsets are Global Offsets relative to the begining of the font file.
1012
+ // Jump the file pointer to the start address to read from.
1013
+ buf . Seek ( Offsets [ i ] ) ;
1014
+ // Read from the buffer and write into the array at start.
1015
+ buf . ReadFully ( NewObjects , start + unusedOffset , end - start ) ;
1016
+ }
1017
+ else
1018
+ {
1019
+ NewObjects [ start + unusedOffset ] = OperatorForUnusedEntries ;
1020
+ unusedOffset ++ ;
1021
+ }
1022
+ }
1023
+ NewOffsets [ Offsets . Length - 1 ] += unusedOffset ;
1024
+ // Use AssembleIndex to build the index from the offset & object arrays
1025
+ return AssembleIndex ( NewOffsets , NewObjects ) ;
1026
+ }
1027
+
975
1028
/**
976
1029
* Function creates the new index, inserting the count,offsetsize,offset array
977
1030
* and object array.
0 commit comments