Skip to content

Commit 68d0201

Browse files
committed
Port cb0b508: Copy all global subroutines to GSubr INDEX.
DEV-1885
1 parent 7f87d88 commit 68d0201

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

src/core/iTextSharp/text/pdf/CFFFontSubset.cs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ virtual protected void BuildNewLGSubrs(int Font)
477477
// Builds the New Local Subrs index
478478
NewSubrsIndexNonCID = BuildNewIndex(fonts[Font].SubrsOffsets,hSubrsUsedNonCID,RETURN_OP);
479479
//Builds the New Global Subrs index
480-
NewGSubrsIndex = BuildNewIndex(gsubrOffsets,hGSubrsUsed,RETURN_OP);
480+
NewGSubrsIndex = BuildNewIndexAndCopyAllGSubrs(gsubrOffsets,RETURN_OP);
481481
}
482482

483483
/**
@@ -972,6 +972,59 @@ virtual protected byte[] BuildNewIndex(int[] Offsets,Dictionary<int,int[]> Used,
972972
return AssembleIndex(NewOffsets,NewObjects);
973973
}
974974

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+
9751028
/**
9761029
* Function creates the new index, inserting the count,offsetsize,offset array
9771030
* and object array.

0 commit comments

Comments
 (0)