Skip to content

Commit

Permalink
Port cb0b508: Copy all global subroutines to GSubr INDEX.
Browse files Browse the repository at this point in the history
DEV-1885
  • Loading branch information
ars18wrw committed Aug 15, 2017
1 parent 133eabb commit 04f38fc
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion itext/src/main/java/com/itextpdf/text/pdf/CFFFontSubset.java
Expand Up @@ -484,7 +484,7 @@ else if (fonts[Font].privateSubrs>=0)
// Builds the New Local Subrs index
NewSubrsIndexNonCID = BuildNewIndex(fonts[Font].SubrsOffsets,hSubrsUsedNonCID,RETURN_OP);
//Builds the New Global Subrs index
NewGSubrsIndex = BuildNewIndex(gsubrOffsets,hGSubrsUsed,RETURN_OP);
NewGSubrsIndex = BuildNewIndexAndCopyAllGSubrs(gsubrOffsets, RETURN_OP);
}

/**
Expand Down Expand Up @@ -980,6 +980,54 @@ protected byte[] BuildNewIndex(int[] Offsets,HashMap<Integer, int[]> Used,byte O
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
*
* @param Offsets the offset array of the original index
* @param OperatorForUnusedEntries the operator inserted into the data stream for unused entries
* @return the new index subset version
* @throws java.io.IOException
*/
protected byte[] BuildNewIndexAndCopyAllGSubrs(int[] Offsets, byte OperatorForUnusedEntries) throws java.io.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 - 1; ++i) {
NewOffsets[i] = Offset;
Offset += Offsets[i + 1] - Offsets[i];
}
// Else the same offset is kept in i+1.
NewOffsets[Offsets.length - 1] = Offset;
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 creates the new index, inserting the count,offsetsize,offset array
* and object array.
Expand Down

0 comments on commit 04f38fc

Please sign in to comment.