Skip to content

Commit

Permalink
Fix CIDToGIDMap parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Jul 16, 2024
1 parent 4125dae commit 46030ed
Showing 1 changed file with 6 additions and 27 deletions.
33 changes: 6 additions & 27 deletions src/main/java/org/verapdf/pd/font/CIDToGIDMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public CIDToGIDMapping(COSObject obj) throws IOException {
} else {
this.isIdentity = false;
try (ASInputStream stream = obj.getData(COSStream.FilterFlags.DECODE)) {
mapping = new
int[(obj.getIntegerKey(ASAtom.LENGTH).intValue() + 1) / 2];
parseCIDToGIDStream(stream);
}
return;
Expand Down Expand Up @@ -108,35 +106,16 @@ public int getMappingSize() {
}

private void parseCIDToGIDStream(ASInputStream stream) throws IOException {
int b = stream.read();
int i = 0;
while (b != -1) {
int res = b;
res <<= 8;
b = stream.read();
if (b != -1) {
res += b;
mapping[i++] = res;
b = stream.read();
} else {
mapping[i++] = res;
}
if(i == mapping.length) {
LOGGER.log(Level.FINE, "CIDToGID mapping has more items than specified in dict");
List<Integer> endOfMapping = readEndOfMapping(stream, b);
int[] newMapping = new int[mapping.length + endOfMapping.size()];
System.arraycopy(mapping, 0, newMapping, 0, mapping.length);
for(int j = mapping.length; j < newMapping.length; ++j) {
newMapping[j] = endOfMapping.get(j - mapping.length);
}
this.mapping = newMapping;
break;
}
List<Integer> mappingList = readMapping(stream);
mapping = new int[mappingList.size()];
for (int i = 0; i < mappingList.size(); ++i) {
mapping[i] = mappingList.get(i);
}
}

private static List<Integer> readEndOfMapping(ASInputStream stream, int b) throws IOException {
private static List<Integer> readMapping(ASInputStream stream) throws IOException {
List<Integer> res = new ArrayList<>();
int b = stream.read();
while (b != -1) {
int num = b;
num <<= 8;
Expand Down

0 comments on commit 46030ed

Please sign in to comment.