Skip to content

Commit 9542f37

Browse files
committed
Add GenericArray for arrays with generic types.
1 parent a4d916e commit 9542f37

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

io/src/main/java/com/itextpdf/io/font/CFFFontSubset.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.itextpdf.io.IOException;
44
import com.itextpdf.io.source.RandomAccessFileOrArray;
5+
import com.itextpdf.io.util.GenericArray;
56

67
import java.util.ArrayList;
78
import java.util.HashMap;
@@ -68,11 +69,11 @@ public class CFFFontSubset extends CFFFont {
6869
/**
6970
* A Maps array for keeping the subroutines used in each FontDict
7071
*/
71-
Map<Integer, int[]>[] hSubrsUsed;
72+
GenericArray<HashMap<Integer, int[]>> hSubrsUsed;
7273
/**
7374
* The SubroutinesUsed Maps as lists
7475
*/
75-
List<Integer>[] lSubrsUsed;
76+
GenericArray<List<Integer>> lSubrsUsed;
7677
/**
7778
* A Map for keeping the Global subroutines used in the font
7879
*/
@@ -390,8 +391,8 @@ protected void BuildNewLGSubrs(int Font) throws java.io.IOException {
390391
if (fonts[Font].isCID) {
391392
// Init the Map-array and the list-array to hold the subrs used
392393
// in each private dict.
393-
hSubrsUsed = new HashMap[fonts[Font].fdprivateOffsets.length];
394-
lSubrsUsed = new ArrayList[fonts[Font].fdprivateOffsets.length];
394+
hSubrsUsed = new GenericArray<>(fonts[Font].fdprivateOffsets.length);
395+
lSubrsUsed = new GenericArray<>(fonts[Font].fdprivateOffsets.length);
395396
// A [][] which will store the byte array for each new FD Array lsubs index
396397
NewLSubrsIndex = new byte[fonts[Font].fdprivateOffsets.length][];
397398
// An array to hold the offset for each Lsubr index
@@ -405,18 +406,18 @@ protected void BuildNewLGSubrs(int Font) throws java.io.IOException {
405406
for (int j = 0; j < FDInList.size(); j++) {
406407
// The FDArray index, Map, List to work on
407408
int FD = FDInList.get(j);
408-
hSubrsUsed[FD] = new HashMap<>();
409-
lSubrsUsed[FD] = new ArrayList<>();
409+
hSubrsUsed.set(FD, new HashMap<Integer, int[]>());
410+
lSubrsUsed.set(FD, new ArrayList<Integer>());
410411
//Reads the private dicts looking for the subr operator and
411412
// store both the offset for the index and its offset array
412413
BuildFDSubrsOffsets(Font, FD);
413414
// Verify that FDPrivate has a LSubrs index
414415
if (fonts[Font].PrivateSubrsOffset[FD] >= 0) {
415416
//Scans the Charstring data storing the used Local and Global subroutines
416417
// by the glyphs. Scans the Subrs recursively.
417-
BuildSubrUsed(Font, FD, fonts[Font].PrivateSubrsOffset[FD], fonts[Font].PrivateSubrsOffsetsArray[FD], hSubrsUsed[FD], lSubrsUsed[FD]);
418+
BuildSubrUsed(Font, FD, fonts[Font].PrivateSubrsOffset[FD], fonts[Font].PrivateSubrsOffsetsArray[FD], hSubrsUsed.get(FD), lSubrsUsed.get(FD));
418419
// Builds the New Local Subrs index
419-
NewLSubrsIndex[FD] = BuildNewIndex(fonts[Font].PrivateSubrsOffsetsArray[FD], hSubrsUsed[FD], RETURN_OP);
420+
NewLSubrsIndex[FD] = BuildNewIndex(fonts[Font].PrivateSubrsOffsetsArray[FD], hSubrsUsed.get(FD), RETURN_OP);
420421
}
421422
}
422423
}
@@ -614,7 +615,7 @@ protected void ReadASubr(int begin, int end, int GBias, int LBias, Map<Integer,
614615
// If the subr isn't in the Map -> Put in
615616
if (!hGSubrsUsed.containsKey(Subr)) {
616617
hGSubrsUsed.put(Subr, null);
617-
boolean add = lGSubrsUsed.add(Integer.valueOf(Subr));
618+
lGSubrsUsed.add(Subr);
618619
}
619620
CalcHints(gsubrOffsets[Subr], gsubrOffsets[Subr + 1], LBias, GBias, LSubrsOffsets);
620621
seek(pos);
@@ -949,8 +950,10 @@ protected byte[] AssembleIndex(int[] NewOffsets, byte[] NewObjects) {
949950
// The counter for writing
950951
int Place = 0;
951952
// Write the count field
952-
NewIndex[Place++] = (byte) (Count >>> 8 & 0xff);
953-
NewIndex[Place++] = (byte) (Count >>> 0 & 0xff);
953+
// There is no sense in >>> for char
954+
// NewIndex[Place++] = (byte) (Count >>> 8 & 0xff);
955+
NewIndex[Place++] = (byte) (Count >> 8 & 0xff);
956+
NewIndex[Place++] = (byte) (Count & 0xff);
954957
// Write the offsize field
955958
NewIndex[Place++] = Offsize;
956959
// Write the offset array according to the offsize
@@ -1036,7 +1039,7 @@ protected byte[] BuildNewFile(int Font) {
10361039
) {
10371040
} else {
10381041
//OtherWise copy key "as is" to the output list
1039-
OutputList.add(new RangeItem(buf, p1, p2 - p1));
1042+
OutputList.addLast(new RangeItem(buf, p1, p2 - p1));
10401043
}
10411044
}
10421045
// Create the FDArray, FDSelect, Charset and CharStrings Keys
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.itextpdf.io.util;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class GenericArray<T> {
7+
8+
private List<T> array;
9+
10+
public GenericArray(int size) {
11+
array = new ArrayList<>(size);
12+
for (int i = 0; i < size; i++) {
13+
array.add(null);
14+
}
15+
}
16+
17+
public T get(int index) {
18+
return array.get(index);
19+
}
20+
21+
public T set(int index, T element) {
22+
return array.set(index, element);
23+
}
24+
}

0 commit comments

Comments
 (0)