pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1755805 - in /pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger: PDFDebugger.java pagepane/DebugPageDrawer.java pagepane/DebugTextOverlay.java pagepane/PagePane.java
Date Wed, 10 Aug 2016 19:26:47 GMT
Author: jahewson
Date: Wed Aug 10 19:26:47 2016
New Revision: 1755805

URL: http://svn.apache.org/viewvc?rev=1755805&view=rev
Log:
PDFBOX-2941: show beads and use thin stroke width

Modified:
    pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
    pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/DebugPageDrawer.java
    pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/DebugTextOverlay.java
    pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java

Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java?rev=1755805&r1=1755804&r2=1755805&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java (original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java Wed Aug
10 19:26:47 2016
@@ -157,6 +157,7 @@ public class PDFDebugger extends JFrame
     // view menu
     private JMenuItem viewModeItem;
     public static JCheckBoxMenuItem showTextStripper;
+    public static JCheckBoxMenuItem showTextStripperBeads;
     public static JCheckBoxMenuItem showFontBBox;
     public static JCheckBoxMenuItem showGlyphBounds;
     
@@ -573,9 +574,13 @@ public class PDFDebugger extends JFrame
 
         viewMenu.addSeparator();
         
-        showTextStripper = new JCheckBoxMenuItem("Show TextStripper Bounds");
+        showTextStripper = new JCheckBoxMenuItem("Show TextStripper TextPositions");
         showTextStripper.setEnabled(false);
         viewMenu.add(showTextStripper);
+
+        showTextStripperBeads = new JCheckBoxMenuItem("Show TextStripper Beads");
+        showTextStripperBeads.setEnabled(false);
+        viewMenu.add(showTextStripperBeads);
         
         showFontBBox = new JCheckBoxMenuItem("Show Approximate Text Bounds");
         showFontBBox.setEnabled(false);

Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/DebugPageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/DebugPageDrawer.java?rev=1755805&r1=1755804&r2=1755805&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/DebugPageDrawer.java
(original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/DebugPageDrawer.java
Wed Aug 10 19:26:47 2016
@@ -106,8 +106,8 @@ final class DebugPageDrawer extends Page
 
             // draw
             graphics.setClip(graphics.getDeviceConfiguration().getBounds());
-            graphics.setColor(new Color(88, 152, 82)); // green
-            graphics.setStroke(new BasicStroke(1f));
+            graphics.setColor(Color.cyan);
+            graphics.setStroke(new BasicStroke(.5f));
             graphics.draw(bbox);
 
             // restore

Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/DebugTextOverlay.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/DebugTextOverlay.java?rev=1755805&r1=1755804&r2=1755805&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/DebugTextOverlay.java
(original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/DebugTextOverlay.java
Wed Aug 10 19:26:47 2016
@@ -16,9 +16,12 @@
 
 package org.apache.pdfbox.debugger.pagepane;
 
+import java.awt.BasicStroke;
 import java.awt.Color;
 import java.awt.Graphics2D;
+import java.awt.Shape;
 import java.awt.geom.AffineTransform;
+import java.awt.geom.GeneralPath;
 import java.awt.geom.Rectangle2D;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -31,8 +34,10 @@ import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.font.PDFont;
 import org.apache.pdfbox.pdmodel.font.PDType3Font;
+import org.apache.pdfbox.pdmodel.interactive.pagenavigation.PDThreadBead;
 import org.apache.pdfbox.text.PDFTextStripper;
 import org.apache.pdfbox.text.TextPosition;
+import org.apache.pdfbox.util.Matrix;
 
 /**
  * Draws an overlay showing the locations of text found by PDFTextStripper and another heuristic.
@@ -47,6 +52,7 @@ final class DebugTextOverlay
     private int pageIndex;
     private float scale;
     private boolean showTextStripper;
+    private boolean showTextStripperBeads;
     private boolean showFontBBox;
         
     private class DebugTextStripper extends PDFTextStripper
@@ -70,11 +76,28 @@ final class DebugTextOverlay
             // scale and rotate
             transform(graphics, page, scale);
 
+            // set stroke width
+            graphics.setStroke(new BasicStroke(0.5f));
+            
             setStartPage(pageIndex + 1);
             setEndPage(pageIndex + 1);
 
             Writer dummy = new OutputStreamWriter(new ByteArrayOutputStream());
             writeText(document, dummy);
+
+            if (DebugTextOverlay.this.showTextStripperBeads)
+            {
+                // beads in green
+                List<PDThreadBead> pageArticles = page.getThreadBeads();
+                for (PDThreadBead bead : pageArticles)
+                {
+                    PDRectangle r = bead.getRectangle();
+                    GeneralPath p = r.transform(Matrix.getTranslateInstance(-cropBox.getLowerLeftX(),
cropBox.getLowerLeftY()));
+                    Shape s = flip.createTransformedShape(p);
+                    graphics.setColor(Color.green);
+                    graphics.draw(s);
+                }
+            }
         }
 
         // scale rotate translate
@@ -162,12 +185,14 @@ final class DebugTextOverlay
     }
 
     public DebugTextOverlay(PDDocument document, int pageIndex, float scale,
-                            boolean showTextStripper, boolean showFontBBox)
+                            boolean showTextStripper, boolean showTextStripperBeads,
+                            boolean showFontBBox)
     {
         this.document = document;
         this.pageIndex = pageIndex;
         this.scale = scale;
         this.showTextStripper = showTextStripper;
+        this.showTextStripperBeads = showTextStripperBeads;
         this.showFontBBox = showFontBBox;
     }
     

Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java?rev=1755805&r1=1755804&r2=1755805&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
(original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Wed Aug 10 19:26:47 2016
@@ -96,7 +96,7 @@ public class PagePane implements ActionL
         zoomMenu.changeZoomSelection(zoomMenu.getPageZoomScale());
         // render in a background thread: rendering is read-only, so this should be ok, despite
         // the fact that PDDocument is not officially thread safe
-        new RenderWorker(zoomMenu.getPageZoomScale(), 0, false, false, false).execute();
+        new RenderWorker(zoomMenu.getPageZoomScale(), 0, false, false, false, false).execute();
     }
 
     /**
@@ -116,12 +116,14 @@ public class PagePane implements ActionL
         if (ZoomMenu.isZoomMenu(actionCommand) ||
             RotationMenu.isRotationMenu(actionCommand) ||
             actionEvent.getSource() == PDFDebugger.showTextStripper ||
+            actionEvent.getSource() == PDFDebugger.showTextStripperBeads ||
             actionEvent.getSource() == PDFDebugger.showFontBBox ||
             actionEvent.getSource() == PDFDebugger.showGlyphBounds)
         {
             new RenderWorker(ZoomMenu.getZoomScale(),
                              RotationMenu.getRotationDegrees(),
                              PDFDebugger.showTextStripper.isSelected(),
+                             PDFDebugger.showTextStripperBeads.isSelected(),
                              PDFDebugger.showFontBBox.isSelected(),
                              PDFDebugger.showGlyphBounds.isSelected()
                             ).execute();
@@ -143,6 +145,9 @@ public class PagePane implements ActionL
         PDFDebugger.showTextStripper.setEnabled(true);
         PDFDebugger.showTextStripper.addActionListener(this);
 
+        PDFDebugger.showTextStripperBeads.setEnabled(true);
+        PDFDebugger.showTextStripperBeads.addActionListener(this);
+
         PDFDebugger.showFontBBox.setEnabled(true);
         PDFDebugger.showFontBBox.addActionListener(this);
 
@@ -155,6 +160,11 @@ public class PagePane implements ActionL
     {
         zoomMenu.setEnableMenu(false);
         rotationMenu.setEnableMenu(false);
+        
+        PDFDebugger.showTextStripper.setEnabled(false);
+        PDFDebugger.showTextStripperBeads.setEnabled(false);
+        PDFDebugger.showFontBBox.setEnabled(false);
+        PDFDebugger.showGlyphBounds.setEnabled(false);
     }
 
     @Override
@@ -240,15 +250,18 @@ public class PagePane implements ActionL
         private final float scale;
         private final int rotation;
         private boolean showTextStripper;
+        private boolean showTextStripperBeads;
         private boolean showFontBBox;
         private boolean showGlyphBounds;
         
         private RenderWorker(float scale, int rotation, boolean showTextStripper,
-                             boolean showFontBBox, boolean showGlyphBounds)
+                             boolean showTextStripperBeads, boolean showFontBBox,
+                             boolean showGlyphBounds)
         {
             this.scale = scale;
             this.rotation = rotation;
             this.showTextStripper = showTextStripper;
+            this.showTextStripperBeads = showTextStripperBeads;
             this.showFontBBox = showFontBBox;
             this.showGlyphBounds = showGlyphBounds;
         }
@@ -271,7 +284,8 @@ public class PagePane implements ActionL
             
             // debug overlays
             DebugTextOverlay debugText = new DebugTextOverlay(document, pageIndex, scale,

-                                                              showTextStripper, showFontBBox);
+                                                              showTextStripper, showTextStripperBeads,
+                                                              showFontBBox);
             Graphics2D g = image.createGraphics();
             debugText.renderTo(g);
             g.dispose();



Mime
View raw message