protected byte[] BuildNewIndex(int[] Offsets,Dictionary<int,int[]> Used,byte OperatorForUnusedEntries)
{
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(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 begining 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);
}