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 = {
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));
import java.util.List;
import java.util.Map;
+import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
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);
+ }
}