From dc7f036c5e0ee8ee8b51f5f4bb2940a77da2bffa Mon Sep 17 00:00:00 2001 From: Peter Hancock Date: Wed, 9 Jan 2013 09:51:11 +0000 Subject: JIRA#FOP-2180: TTFReader outputs bounding box information for glyphs. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1430752 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fonts/apps/TTFReader.java | 5 +++++ src/java/org/apache/fop/fonts/truetype/TTFFile.java | 15 +++++++++++++++ status.xml | 3 +++ 3 files changed, 23 insertions(+) diff --git a/src/java/org/apache/fop/fonts/apps/TTFReader.java b/src/java/org/apache/fop/fonts/apps/TTFReader.java index 25b9e3924..900417350 100644 --- a/src/java/org/apache/fop/fonts/apps/TTFReader.java +++ b/src/java/org/apache/fop/fonts/apps/TTFReader.java @@ -408,6 +408,11 @@ public class TTFReader extends AbstractFontReader { for (int i = 0; i < wx.length; i++) { Element wxel = doc.createElement("wx"); wxel.setAttribute("w", String.valueOf(wx[i])); + int[] bbox = ttf.getBBox(i); + wxel.setAttribute("xMin", String.valueOf(bbox[0])); + wxel.setAttribute("yMin", String.valueOf(bbox[1])); + wxel.setAttribute("xMax", String.valueOf(bbox[2])); + wxel.setAttribute("yMax", String.valueOf(bbox[3])); el.appendChild(wxel); } } diff --git a/src/java/org/apache/fop/fonts/truetype/TTFFile.java b/src/java/org/apache/fop/fonts/truetype/TTFFile.java index 878af1124..442407d6b 100644 --- a/src/java/org/apache/fop/fonts/truetype/TTFFile.java +++ b/src/java/org/apache/fop/fonts/truetype/TTFFile.java @@ -980,6 +980,21 @@ public class TTFFile { return wx; } + /** + * Returns an array (xMin, yMin, xMax, yMax) for a glyph. + * + * @param glyphIndex the index of the glyph + * @return int[] Array defining bounding box. + */ + public int[] getBBox(int glyphIndex) { + int[] bboxInTTFUnits = mtxTab[glyphIndex].getBoundingBox(); + int[] bbox = new int[4]; + for (int i = 0; i < 4; i++) { + bbox[i] = (int) convertTTFUnit2PDFUnit(bboxInTTFUnits[i]); + } + return bbox; + } + /** * Returns the width of a given character. * @param idx Index of the character diff --git a/status.xml b/status.xml index efbd518b2..309e48413 100644 --- a/status.xml +++ b/status.xml @@ -59,6 +59,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + TTFReader: Output bounding box information for glyphs. + Warn instead or error on invalid property values. -- cgit v1.2.3