Skip to content

Commit a92b60d

Browse files
committed
Fonts, io refactoring for autoport.
1 parent 05c472c commit a92b60d

File tree

6 files changed

+30
-95
lines changed

6 files changed

+30
-95
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public String getCharacterSet() {
132132
*/
133133
@Override
134134
public boolean hasKernPairs() {
135-
return !kernPairs.isEmpty();
135+
return kernPairs.size() > 0;
136136
}
137137

138138
@Override

io/src/main/java/com/itextpdf/io/font/otf/Glyph.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,7 @@ public boolean equals(Object obj) {
231231
return false;
232232
}
233233
Glyph other = (Glyph) obj;
234-
if (chars == null) {
235-
if (other.chars != null) {
236-
return false;
237-
}
238-
} else if (!Arrays.equals(chars, other.chars)) {
239-
return false;
240-
}
241-
return code == other.code && width == other.width;
234+
return Arrays.equals(chars, other.chars) && code == other.code && width == other.width;
242235
}
243236

244237
public String toString() {
@@ -249,7 +242,7 @@ public String toString() {
249242
private static int codePoint(char[] a) {
250243
if (a != null) {
251244
if (a.length == 1 && Character.isValidCodePoint(a[0])) {
252-
return (int) a[0];
245+
return a[0];
253246
} else if (a.length == 2 && Character.isHighSurrogate(a[0]) && Character.isLowSurrogate(a[1])) {
254247
return Character.toCodePoint(a[0], a[1]);
255248
}

io/src/main/java/com/itextpdf/io/font/otf/Language.java

Lines changed: 0 additions & 67 deletions
This file was deleted.

io/src/main/java/com/itextpdf/io/font/otf/OpenTypeFontTableReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ protected int getGlyphWidth(int index) {
8888
}
8989
}
9090

91-
public Integer getGlyphToCharacter(int index) {
91+
public int getGlyphToCharacter(int index) {
9292
Glyph glyph = indexGlyphMap.get(index);
9393
if (glyph == null) {
94-
return null;
94+
return -1;
9595
} else {
9696
return glyph.getUnicode();
9797
}

io/src/main/java/com/itextpdf/io/image/BmpImageHelper.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ This file is part of the iText (R) project.
4747
import com.itextpdf.io.IOException;
4848
import com.itextpdf.io.font.PdfEncodings;
4949
import com.itextpdf.io.source.ByteArrayOutputStream;
50+
import com.itextpdf.io.source.RandomAccessFileOrArray;
51+
import com.itextpdf.io.source.RandomAccessSourceFactory;
52+
import com.itextpdf.io.util.StreamUtil;
5053

5154
import java.io.BufferedInputStream;
5255
import java.io.ByteArrayInputStream;
@@ -57,6 +60,10 @@ This file is part of the iText (R) project.
5760
public final class BmpImageHelper {
5861

5962
private static class BmpParameters {
63+
public BmpParameters(BmpImage image) {
64+
this.image = image;
65+
}
66+
6067
BmpImage image;
6168
int width;
6269
int height;
@@ -117,19 +124,14 @@ public static void processImage(Image image, ByteArrayOutputStream stream) {
117124
if (stream == null) {
118125
stream = new ByteArrayOutputStream();
119126
}
120-
BmpParameters bmp = new BmpParameters();
121-
bmp.image = (BmpImage)image;
122-
InputStream bmpStream = null;
127+
BmpParameters bmp = new BmpParameters((BmpImage)image);
128+
InputStream bmpStream;
123129
try {
124130
if (bmp.image.getUrl() != null) {
125-
bmpStream = bmp.image.getUrl().openStream();
126-
int read;
127-
byte[] bytes = new byte[4096];
128-
while ((read = bmpStream.read(bytes)) != -1) {
129-
stream.write(bytes, 0, read);
130-
}
131+
RandomAccessFileOrArray raf = new RandomAccessFileOrArray(new RandomAccessSourceFactory().createSource(bmp.image.getUrl()));
132+
StreamUtil.transferBytes(raf, stream);
133+
raf.close();
131134
image.imageSize = stream.toByteArray().length;
132-
bmpStream.close();
133135
bmpStream = new ByteArrayInputStream(stream.toByteArray());
134136
} else {
135137
bmpStream = new ByteArrayInputStream(bmp.image.getData());
@@ -143,12 +145,6 @@ public static void processImage(Image image, ByteArrayOutputStream stream) {
143145
}
144146
} catch (java.io.IOException e){
145147
throw new IOException(IOException.BmpImageException, e);
146-
} finally {
147-
if (bmpStream != null) {
148-
try {
149-
bmpStream.close();
150-
} catch (java.io.IOException ignored) { }
151-
}
152148
}
153149
updateStream(bmp, stream);
154150
}

io/src/main/java/com/itextpdf/io/util/StreamUtil.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ This file is part of the iText (R) project.
4747
import com.itextpdf.io.source.ByteBuffer;
4848
import com.itextpdf.io.source.ByteUtils;
4949
import com.itextpdf.io.source.OutputStream;
50+
import com.itextpdf.io.source.RandomAccessFileOrArray;
5051
import com.itextpdf.io.source.RandomAccessSource;
5152

5253
import java.io.ByteArrayOutputStream;
@@ -173,6 +174,18 @@ public static void transferBytes(InputStream input, java.io.OutputStream output)
173174
}
174175
}
175176

177+
public static void transferBytes(RandomAccessFileOrArray input, java.io.OutputStream output) throws java.io.IOException {
178+
byte[] buffer = new byte[transferSize];
179+
for (; ; ) {
180+
int len = input.read(buffer, 0, transferSize);
181+
if (len > 0) {
182+
output.write(buffer, 0, len);
183+
} else {
184+
break;
185+
}
186+
}
187+
}
188+
176189
/**
177190
* Reads the full content of a stream and returns them in a byte array
178191
*

0 commit comments

Comments
 (0)