From f24243e01f0e8bc0e1aec2c8c263c8215561e099 Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Wed, 9 May 2018 10:41:40 +0000 Subject: [PATCH] FOP-2792: Add boundingbox for OTF git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1831245 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/fop/fonts/truetype/OTFFile.java | 12 ++++++++++++ .../apache/fop/fonts/truetype/OTFFileTestCase.java | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFFile.java b/fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFFile.java index 2f52fa791..683fd51b1 100644 --- a/fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFFile.java +++ b/fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFFile.java @@ -20,6 +20,7 @@ package org.apache.fop.fonts.truetype; import java.io.IOException; +import java.util.List; import org.apache.fontbox.cff.CFFDataInput; import org.apache.fontbox.cff.CFFFont; @@ -50,6 +51,17 @@ public class OTFFile extends OpenFont { @Override protected void updateBBoxAndOffset() throws IOException { + Object bbox = fileFont.getTopDict().get("FontBBox"); + if (bbox != null) { + List bboxList = (List) bbox; + int[] bboxInt = new int[4]; + for (int i = 0; i < bboxInt.length; i++) { + bboxInt[i] = (Integer) bboxList.get(i); + } + for (OFMtxEntry o : mtxTab) { + o.setBoundingBox(bboxInt); + } + } } private static class Mapping { diff --git a/fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFFileTestCase.java b/fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFFileTestCase.java index 39b6fd50f..1f64f1baa 100644 --- a/fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFFileTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFFileTestCase.java @@ -19,6 +19,7 @@ package org.apache.fop.fonts.truetype; +import java.awt.Rectangle; import java.io.FileInputStream; import java.io.InputStream; @@ -82,4 +83,9 @@ public class OTFFileTestCase { assertEquals(carolynaWidths[i], alexBrush.getWidths()[gids[i]]); } } + + @Test + public void testBoundingBoxes() { + assertEquals(sourceSansProBold.getBoundingBoxes()[0], new Rectangle(-231, -384, 1454, 1358)); + } } -- 2.39.5