You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2014/12/21 16:37:10 UTC
svn commit: r1647158 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java
Author: lehmi
Date: Sun Dec 21 15:37:10 2014
New Revision: 1647158
URL: http://svn.apache.org/r1647158
Log:
PDFBOX-1874: adjust precision to avoid false results when comparing floats as proposed by Yuri Burrows
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java?rev=1647158&r1=1647157&r2=1647158&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java Sun Dec 21 15:37:10 2014
@@ -1487,14 +1487,18 @@ public class PDFTextStripper extends PDF
{
float yGap = Math.abs(position.getTextPosition().getYDirAdj() -
lastPosition.getTextPosition().getYDirAdj());
+ float newYVal = multiplyFloat(getDropThreshold(), maxHeightForLine);
// do we need to flip this for rtl?
float xGap = position.getTextPosition().getXDirAdj() -
lastLineStartPosition.getTextPosition().getXDirAdj();
- if (yGap > getDropThreshold()*maxHeightForLine)
+ float newXVal = multiplyFloat(getIndentThreshold(), position.getTextPosition().getWidthOfSpace());
+ float positionWidth = multiplyFloat(0.25f, position.getTextPosition().getWidth());
+
+ if (yGap > newYVal)
{
result = true;
}
- else if (xGap > getIndentThreshold()*position.getTextPosition().getWidthOfSpace())
+ else if (xGap > newXVal)
{
// text is indented, but try to screen for hanging indent
if (!lastLineStartPosition.isParagraphStart())
@@ -1514,7 +1518,7 @@ public class PDFTextStripper extends PDF
result = true;
}
}
- else if (Math.abs(xGap) < 0.25 * position.getTextPosition().getWidth())
+ else if (Math.abs(xGap) < positionWidth)
{
// current horizontal position is within 1/4 a char of the last
// linestart. We'll treat them as lined up.
@@ -1544,6 +1548,12 @@ public class PDFTextStripper extends PDF
}
}
+ private float multiplyFloat(float value1, float value2)
+ {
+ // multiply 2 floats and truncate the resulting value to 3 decimal places
+ // to avoid wrong results when comparing with another float
+ return Math.round(value1 * value2 * 1000) / 1000f;
+ }
/**
* writes the paragraph separator string to the output.
* @throws IOException if something went wrong