aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2022-09-27 07:04:02 +0000
committerSimon Steiner <ssteiner@apache.org>2022-09-27 07:04:02 +0000
commit575503a3fe9d7ad808a7f14091555e3cf13abdd3 (patch)
tree20a00c983fc78172dff2578c3ae2fa2e680e76ca
parent06812639c573b6973553d188f78e1ac57ccfa864 (diff)
downloadxmlgraphics-fop-575503a3fe9d7ad808a7f14091555e3cf13abdd3.tar.gz
xmlgraphics-fop-575503a3fe9d7ad808a7f14091555e3cf13abdd3.zip
FOP-3093: Stop reading ttf if we hit last offset
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1904293 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--fop-core/src/main/java/org/apache/fop/fonts/truetype/TTFFile.java9
-rw-r--r--fop-core/src/test/java/org/apache/fop/fonts/truetype/TTFFileTestCase.java22
2 files changed, 25 insertions, 6 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/fonts/truetype/TTFFile.java b/fop-core/src/main/java/org/apache/fop/fonts/truetype/TTFFile.java
index 4b0e3d628..ff5147f12 100644
--- a/fop-core/src/main/java/org/apache/fop/fonts/truetype/TTFFile.java
+++ b/fop-core/src/main/java/org/apache/fop/fonts/truetype/TTFFile.java
@@ -139,6 +139,9 @@ public class TTFFile extends OpenFont {
for (int i = 0; i < numberOfGlyphs; i++) {
if ((i + 1) >= mtxTab.length
|| mtxTab[i].getOffset() != mtxTab[i + 1].getOffset()) {
+ if (lastLoca != 0 && lastLoca == mtxTab[i].getOffset()) {
+ break;
+ }
fontFile.seekSet(n + mtxTab[i].getOffset());
fontFile.skip(2);
final int[] bbox = {
@@ -148,15 +151,9 @@ public class TTFFile extends OpenFont {
fontFile.readTTFShort()};
mtxTab[i].setBoundingBox(bbox);
} else {
- /**@todo Verify that this is correct, looks like a copy/paste bug (jm)*/
final int bbox0 = mtxTab[0].getBoundingBox()[0];
final int[] bbox = {bbox0, bbox0, bbox0, bbox0};
mtxTab[i].setBoundingBox(bbox);
- /* Original code
- mtxTab[i].bbox[0] = mtxTab[0].bbox[0];
- mtxTab[i].bbox[1] = mtxTab[0].bbox[0];
- mtxTab[i].bbox[2] = mtxTab[0].bbox[0];
- mtxTab[i].bbox[3] = mtxTab[0].bbox[0]; */
}
if (log.isTraceEnabled()) {
log.trace(mtxTab[i].toString(this));
diff --git a/fop-core/src/test/java/org/apache/fop/fonts/truetype/TTFFileTestCase.java b/fop-core/src/test/java/org/apache/fop/fonts/truetype/TTFFileTestCase.java
index c2d84482f..061353abb 100644
--- a/fop-core/src/test/java/org/apache/fop/fonts/truetype/TTFFileTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/fonts/truetype/TTFFileTestCase.java
@@ -29,6 +29,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -595,4 +596,25 @@ public class TTFFileTestCase {
ttfFile.mtxTab[0] = new OFMtxEntry();
ttfFile.readPostScript();
}
+
+ @Test
+ public void testStopReadAtLastOffset() throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream(bos);
+ dos.writeShort(0);
+ dos.writeShort(4);
+ dos.writeShort(4);
+ dos.writeLong(0);
+ TTFFile ttfFile = new TTFFile();
+ ttfFile.dirTabs = new HashMap<>();
+ ttfFile.dirTabs.put(OFTableName.LOCA, new OFDirTabEntry());
+ ttfFile.dirTabs.put(OFTableName.GLYF, new OFDirTabEntry());
+ ttfFile.fontFile = new FontFileReader(new ByteArrayInputStream(bos.toByteArray()));
+ ttfFile.numberOfGlyphs = 2;
+ ttfFile.mtxTab = new OFMtxEntry[2];
+ ttfFile.mtxTab[0] = new OFMtxEntry();
+ ttfFile.mtxTab[1] = new OFMtxEntry();
+ ttfFile.updateBBoxAndOffset();
+ Assert.assertEquals(ttfFile.mtxTab[0].getBoundingBox()[0], 4);
+ }
}