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 2015/11/18 17:51:13 UTC

svn commit: r1715020 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java

Author: tilman
Date: Wed Nov 18 16:51:13 2015
New Revision: 1715020

URL: http://svn.apache.org/viewvc?rev=1715020&view=rev
Log:
PDFBOX-3110: split large method

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java?rev=1715020&r1=1715019&r2=1715020&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java Wed Nov 18 16:51:13 2015
@@ -351,39 +351,7 @@ public class PDFTextStripper extends PDF
             int numberOfArticleSections = 1;
             if (shouldSeparateByBeads)
             {
-                beadRectangles = new ArrayList<PDRectangle>();
-                for (PDThreadBead bead : page.getThreadBeads())
-                {
-                    if (bead == null)
-                    {
-                        // can't skip, because of null entry handling in processTextPosition()
-                        beadRectangles.add(null);
-                        continue;
-                    }
-                        
-                    PDRectangle rect = bead.getRectangle();
-                    
-                    // bead rectangle is in PDF coordinates (y=0 is bottom), 
-                    // glyphs are in image coordinates (y=0 is top),
-                    // so we must flip
-                    PDRectangle mediaBox = page.getMediaBox();
-                    float upperRightY = mediaBox.getUpperRightY() - rect.getLowerLeftY();
-                    float lowerLeftY = mediaBox.getUpperRightY() - rect.getUpperRightY();
-                    rect.setLowerLeftY(lowerLeftY);
-                    rect.setUpperRightY(upperRightY);
-
-                    // adjust for cropbox
-                    PDRectangle cropBox = page.getCropBox();
-                    if (cropBox.getLowerLeftX() != 0 || cropBox.getLowerLeftY() != 0)
-                    {
-                        rect.setLowerLeftX(rect.getLowerLeftX() - cropBox.getLowerLeftX());
-                        rect.setLowerLeftY(rect.getLowerLeftY() - cropBox.getLowerLeftY());
-                        rect.setUpperRightX(rect.getUpperRightX() - cropBox.getLowerLeftX());
-                        rect.setUpperRightY(rect.getUpperRightY() - cropBox.getLowerLeftY());
-                    }
-                    
-                    beadRectangles.add(rect);
-                }
+                fillBeadRectangles(page);
                 numberOfArticleSections += beadRectangles.size() * 2;
             }
             int originalSize = charactersByArticle.size();
@@ -406,6 +374,43 @@ public class PDFTextStripper extends PDF
         }
     }
 
+    private void fillBeadRectangles(PDPage page)
+    {
+        beadRectangles = new ArrayList<PDRectangle>();
+        for (PDThreadBead bead : page.getThreadBeads())
+        {
+            if (bead == null)
+            {
+                // can't skip, because of null entry handling in processTextPosition()
+                beadRectangles.add(null);
+                continue;
+            }
+            
+            PDRectangle rect = bead.getRectangle();
+            
+            // bead rectangle is in PDF coordinates (y=0 is bottom),
+            // glyphs are in image coordinates (y=0 is top),
+            // so we must flip
+            PDRectangle mediaBox = page.getMediaBox();
+            float upperRightY = mediaBox.getUpperRightY() - rect.getLowerLeftY();
+            float lowerLeftY = mediaBox.getUpperRightY() - rect.getUpperRightY();
+            rect.setLowerLeftY(lowerLeftY);
+            rect.setUpperRightY(upperRightY);
+            
+            // adjust for cropbox
+            PDRectangle cropBox = page.getCropBox();
+            if (cropBox.getLowerLeftX() != 0 || cropBox.getLowerLeftY() != 0)
+            {
+                rect.setLowerLeftX(rect.getLowerLeftX() - cropBox.getLowerLeftX());
+                rect.setLowerLeftY(rect.getLowerLeftY() - cropBox.getLowerLeftY());
+                rect.setUpperRightX(rect.getUpperRightX() - cropBox.getLowerLeftX());
+                rect.setUpperRightY(rect.getUpperRightY() - cropBox.getLowerLeftY());
+            }
+            
+            beadRectangles.add(rect);
+        }
+    }
+
     /**
      * Start a new article, which is typically defined as a column on a single page (also referred to as a bead). This
      * assumes that the primary direction of text is left to right. Default implementation is to do nothing. Subclasses