You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2018/03/17 15:49:02 UTC

svn commit: r1827091 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text: PDFTextStripper.java TextPosition.java

Author: msahyoun
Date: Sat Mar 17 15:49:01 2018
New Revision: 1827091

URL: http://svn.apache.org/viewvc?rev=1827091&view=rev
Log:
PDFBOX-4134: use Float.compare

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/TextPosition.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=1827091&r1=1827090&r2=1827091&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 Sat Mar 17 15:49:01 2018
@@ -388,7 +388,7 @@ public class PDFTextStripper extends Leg
             
             // adjust for cropbox
             PDRectangle cropBox = page.getCropBox();
-            if (cropBox.getLowerLeftX() != 0 || cropBox.getLowerLeftY() != 0)
+            if (Float.compare(cropBox.getLowerLeftX(), 0) != 0 || Float.compare(cropBox.getLowerLeftY(), 0) != 0)
             {
                 rect.setLowerLeftX(rect.getLowerLeftX() - cropBox.getLowerLeftX());
                 rect.setLowerLeftY(rect.getLowerLeftY() - cropBox.getLowerLeftY());
@@ -528,9 +528,9 @@ public class PDFTextStripper extends Leg
 
                 // Resets the average character width when we see a change in font
                 // or a change in the font size
-                if (lastPosition != null && (position.getFont() != lastPosition.getTextPosition()
-                        .getFont()
-                        || position.getFontSize() != lastPosition.getTextPosition().getFontSize()))
+                if (lastPosition != null &&
+                    (position.getFont() != lastPosition.getTextPosition().getFont() || 
+                     Float.compare(position.getFontSize(),lastPosition.getTextPosition().getFontSize()) != 0))
                 {
                     previousAveCharWidth = -1;
                 }
@@ -564,7 +564,7 @@ public class PDFTextStripper extends Leg
                 // space character with some margin.
                 float wordSpacing = position.getWidthOfSpace();
                 float deltaSpace;
-                if (wordSpacing == 0 || Float.isNaN(wordSpacing))
+                if (Float.compare(wordSpacing, 0) == 0 || Float.isNaN(wordSpacing))
                 {
                     deltaSpace = Float.MAX_VALUE;
                 }
@@ -598,7 +598,7 @@ public class PDFTextStripper extends Leg
                 // Compares the values obtained by the average method and the wordSpacing method
                 // and picks the smaller number.
                 float expectedStartOfNextWordX = EXPECTED_START_OF_NEXT_WORD_X_RESET_VALUE;
-                if (endOfLastTextX != END_OF_LAST_TEXT_X_RESET_VALUE)
+                if (Float.compare(endOfLastTextX, END_OF_LAST_TEXT_X_RESET_VALUE) != 0)
                 {
                     if (deltaCharWidth > deltaSpace)
                     {
@@ -639,7 +639,7 @@ public class PDFTextStripper extends Leg
                         minYTopForLine = MIN_Y_TOP_FOR_LINE_RESET_VALUE;
                     }
                     // test if our TextPosition starts after a new word would be expected to start
-                    if (expectedStartOfNextWordX != EXPECTED_START_OF_NEXT_WORD_X_RESET_VALUE
+                    if (Float.compare(expectedStartOfNextWordX, EXPECTED_START_OF_NEXT_WORD_X_RESET_VALUE) != 0
                             && expectedStartOfNextWordX < positionX &&
                             // only bother adding a space if the last character was not a space
                             lastPosition.getTextPosition().getUnicode() != null

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/TextPosition.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/TextPosition.java?rev=1827091&r1=1827090&r2=1827091&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/TextPosition.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/TextPosition.java Sat Mar 17 15:49:01 2018
@@ -248,19 +248,19 @@ public final class TextPosition
      */
     private float getXRot(float rotation)
     {
-        if (rotation == 0)
+        if (Float.compare(rotation, 0) == 0)
         {
             return textMatrix.getTranslateX();
         }
-        else if (rotation == 90)
+        else if (Float.compare(rotation, 90) == 0)
         {
             return textMatrix.getTranslateY();
         }
-        else if (rotation == 180)
+        else if (Float.compare(rotation, 180) == 0)
         {
             return pageWidth - textMatrix.getTranslateX();
         }
-        else if (rotation == 270)
+        else if (Float.compare(rotation, 270) == 0)
         {
             return pageHeight - textMatrix.getTranslateY();
         }
@@ -299,19 +299,19 @@ public final class TextPosition
      */
     private float getYLowerLeftRot(float rotation)
     {
-        if (rotation == 0)
+        if (Float.compare(rotation, 0) == 0)
         {
             return textMatrix.getTranslateY();
         }
-        else if (rotation == 90)
+        else if (Float.compare(rotation, 90) == 0)
         {
             return pageWidth - textMatrix.getTranslateX();
         }
-        else if (rotation == 180)
+        else if (Float.compare(rotation, 180) == 0)
         {
             return pageHeight - textMatrix.getTranslateY();
         }
-        else if (rotation == 270)
+        else if (Float.compare(rotation, 270) == 0)
         {
             return textMatrix.getTranslateX();
         }
@@ -339,7 +339,7 @@ public final class TextPosition
     {
         float dir = getDir();
         // some PDFBox code assumes that the 0,0 point is in upper left, not lower left
-        if (dir == 0 || dir == 180)
+        if (Float.compare(dir, 0) == 0 || Float.compare(dir, 180) == 0)
         {
             return pageHeight - getYLowerLeftRot(dir);
         }
@@ -357,7 +357,7 @@ public final class TextPosition
      */
     private float getWidthRot(float rotation)
     {
-        if (rotation == 90 || rotation == 270)
+        if (Float.compare(rotation, 90) == 0 || Float.compare(rotation, 270) == 0)
         {
             return Math.abs(endY - textMatrix.getTranslateY());
         }