From 575503a3fe9d7ad808a7f14091555e3cf13abdd3 Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Tue, 27 Sep 2022 07:04:02 +0000 Subject: [PATCH] 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 --- .../apache/fop/fonts/truetype/TTFFile.java | 9 +++----- .../fop/fonts/truetype/TTFFileTestCase.java | 22 +++++++++++++++++++ 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); + } } -- 2.39.5