pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1824957 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/LegacyPDFStreamEngine.java
Date Wed, 21 Feb 2018 11:59:07 GMT
Author: msahyoun
Date: Wed Feb 21 11:59:07 2018
New Revision: 1824957

URL: http://svn.apache.org/viewvc?rev=1824957&view=rev
Log:
PDFBOX-4071: use Float.compare for float comparison, use try-with

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/LegacyPDFStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/LegacyPDFStreamEngine.java?rev=1824957&r1=1824956&r2=1824957&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/LegacyPDFStreamEngine.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/LegacyPDFStreamEngine.java Wed
Feb 21 11:59:07 2018
@@ -111,8 +111,10 @@ class LegacyPDFStreamEngine extends PDFS
 
         // load additional glyph list for Unicode mapping
         String path = "org/apache/pdfbox/resources/glyphlist/additional.txt";
-        InputStream input = GlyphList.class.getClassLoader().getResourceAsStream(path);
-        glyphList = new GlyphList(GlyphList.getAdobeGlyphList(), input);
+        try (InputStream input = GlyphList.class.getClassLoader().getResourceAsStream(path))
+        {
+            glyphList = new GlyphList(GlyphList.getAdobeGlyphList(), input);
+        }
     }
 
     /**
@@ -127,7 +129,7 @@ class LegacyPDFStreamEngine extends PDFS
         this.pageRotation = page.getRotation();
         this.pageSize = page.getCropBox();
         
-        if (pageSize.getLowerLeftX() == 0 && pageSize.getLowerLeftY() == 0)
+        if (Float.compare(pageSize.getLowerLeftX(), 0) == 0 && Float.compare(pageSize.getLowerLeftY(),
0) == 0)
         {
             translateMatrix = null;
         }
@@ -174,7 +176,7 @@ class LegacyPDFStreamEngine extends PDFS
         if (fontDescriptor != null)
         {
             float capHeight = fontDescriptor.getCapHeight();
-            if (capHeight != 0 && (capHeight < glyphHeight || glyphHeight == 0))
+            if (Float.compare(capHeight, 0) != 0 && (capHeight < glyphHeight ||
Float.compare(glyphHeight, 0) == 0))
             {
                 glyphHeight = capHeight;
             }
@@ -269,13 +271,13 @@ class LegacyPDFStreamEngine extends PDFS
             LOG.warn(exception, exception);
         }
 
-        if (spaceWidthText == 0)
+        if (Float.compare(spaceWidthText, 0) == 0)
         {
             spaceWidthText = font.getAverageFontWidth() * glyphSpaceToTextSpaceFactor;
             // the average space width appears to be higher than necessary so make it smaller
             spaceWidthText *= .80f;
         }
-        if (spaceWidthText == 0)
+        if (Float.compare(spaceWidthText, 0) == 0)
         {
             spaceWidthText = 1.0f; // if could not find font, use a generic value
         }



Mime
View raw message