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