You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2017/07/01 09:18:25 UTC
svn commit: r1800487 -
/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java
Author: tilman
Date: Sat Jul 1 09:18:25 2017
New Revision: 1800487
URL: http://svn.apache.org/viewvc?rev=1800487&view=rev
Log:
PDFBOX-3850: limit glyph bbox to font bbox
Modified:
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java?rev=1800487&r1=1800486&r2=1800487&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java Sat Jul 1 09:18:25 2017
@@ -131,7 +131,7 @@ public class DrawPrintTextLocations exte
}
}
- // this calculates the real individual glyph bounds
+ // this calculates the real (except for type 3 fonts) individual glyph bounds
private Shape calculateGlyphBounds(Matrix textRenderingMatrix, PDFont font, int code) throws IOException
{
GeneralPath path = null;
@@ -139,13 +139,22 @@ public class DrawPrintTextLocations exte
at.concatenate(font.getFontMatrix().createAffineTransform());
if (font instanceof PDType3Font)
{
+ // It is difficult to calculate the real individual glyph bounds for type 3 fonts
+ // because these are not vector fonts, the content stream could contain almost anything
+ // that is found in page content streams.
PDType3Font t3Font = (PDType3Font) font;
PDType3CharProc charProc = t3Font.getCharProc(code);
if (charProc != null)
{
+ BoundingBox fontBBox = t3Font.getBoundingBox();
PDRectangle glyphBBox = charProc.getGlyphBBox();
if (glyphBBox != null)
{
+ // PDFBOX-3850: glyph bbox could be larger than the font bbox
+ glyphBBox.setLowerLeftX(Math.max(fontBBox.getLowerLeftX(), glyphBBox.getLowerLeftX()));
+ glyphBBox.setLowerLeftY(Math.max(fontBBox.getLowerLeftY(), glyphBBox.getLowerLeftY()));
+ glyphBBox.setUpperRightX(Math.min(fontBBox.getUpperRightX(), glyphBBox.getUpperRightX()));
+ glyphBBox.setUpperRightY(Math.min(fontBBox.getUpperRightY(), glyphBBox.getUpperRightY()));
path = glyphBBox.toGeneralPath();
}
}