Author: tilman
Date: Thu Sep 22 19:35:27 2016
New Revision: 1761994

URL: http://svn.apache.org/viewvc?rev=1761994&view=rev
Log:
PDFBOX-3509: fix bug with rotated pages and pages with cropBox

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=1761994&r1=1761993&r2=1761994&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
 Thu Sep 22 19:35:27 2016
@@ -62,6 +62,7 @@ public class DrawPrintTextLocations exte
     private BufferedImage image;
     private AffineTransform flipAT;
     private AffineTransform rotateAT;
+    private AffineTransform transAT;
     private final String filename;
     static final int SCALE = 4;
     private Graphics2D g2d;
@@ -133,6 +134,7 @@ public class DrawPrintTextLocations exte
         {
             cyanShape = flipAT.createTransformedShape(cyanShape);
             cyanShape = rotateAT.createTransformedShape(cyanShape);
+            cyanShape = transAT.createTransformedShape(cyanShape);
 
             g2d.setColor(Color.CYAN);
             g2d.draw(cyanShape);
@@ -236,6 +238,9 @@ public class DrawPrintTextLocations exte
             rotateAT.rotate(Math.toRadians(rotation));
         }
 
+        // cropbox
+        transAT = 
AffineTransform.getTranslateInstance(-cropBox.getLowerLeftX(), 
cropBox.getLowerLeftY());
+
         g2d = image.createGraphics();
         g2d.setStroke(new BasicStroke(0.1f));
         g2d.scale(SCALE, SCALE);
@@ -252,9 +257,8 @@ public class DrawPrintTextLocations exte
         for (PDThreadBead bead : pageArticles)
         {
             PDRectangle r = bead.getRectangle();
-            GeneralPath p = 
r.transform(Matrix.getTranslateInstance(-cropBox.getLowerLeftX(), 
cropBox.getLowerLeftY()));
-
-            Shape s = flipAT.createTransformedShape(p);
+            Shape s = r.toGeneralPath().createTransformedShape(transAT);
+            s = flipAT.createTransformedShape(s);
             s = rotateAT.createTransformedShape(s);
             g2d.setColor(Color.green);
             g2d.draw(s);
@@ -290,8 +294,9 @@ public class DrawPrintTextLocations exte
                     (text.getYDirAdj() - text.getHeightDir()),
                     text.getWidthDirAdj(),
                     text.getHeightDir());
+            Shape sh = rotateAT.createTransformedShape(rect);
             g2d.setColor(Color.red);
-            g2d.draw(rect);
+            g2d.draw(sh);
 
             // in blue:
             // show rectangle with the real vertical bounds, based on the font 
bounding box y values


Reply via email to