diff --git a/src/main/java/org/verapdf/pd/font/CIDToGIDMapping.java b/src/main/java/org/verapdf/pd/font/CIDToGIDMapping.java index 90940d67..f8b32001 100644 --- a/src/main/java/org/verapdf/pd/font/CIDToGIDMapping.java +++ b/src/main/java/org/verapdf/pd/font/CIDToGIDMapping.java @@ -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; @@ -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 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 mappingList = readMapping(stream); + mapping = new int[mappingList.size()]; + for (int i = 0; i < mappingList.size(); ++i) { + mapping[i] = mappingList.get(i); } } - private static List readEndOfMapping(ASInputStream stream, int b) throws IOException { + private static List readMapping(ASInputStream stream) throws IOException { List res = new ArrayList<>(); + int b = stream.read(); while (b != -1) { int num = b; num <<= 8;