pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1827078 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font: PDCIDFont.java PDCIDFontType0.java PDFont.java PDFontDescriptor.java PDSimpleFont.java PDTrueTypeFont.java PDType1CFont.java PDType1Font.java PDType3Font.java
Date Sat, 17 Mar 2018 12:13:41 GMT
Author: msahyoun
Date: Sat Mar 17 12:13:40 2018
New Revision: 1827078

URL: http://svn.apache.org/viewvc?rev=1827078&view=rev
Log:
PDFBOX-4134: use Float.compare, move common code to superclass

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontDescriptor.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java?rev=1827078&r1=1827077&r2=1827078&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java Sat Mar
17 12:13:40 2018
@@ -223,7 +223,7 @@ public abstract class PDCIDFont implemen
      */
     private float getDefaultWidth()
     {
-        if (defaultWidth == 0)
+        if (Float.compare(defaultWidth, 0) == 0)
         {
             COSBase base = dict.getDictionaryObject(COSName.DW);
             if (base instanceof COSNumber)
@@ -315,7 +315,7 @@ public abstract class PDCIDFont implemen
     // todo: this method is highly suspicious, the average glyph width is not usually a good
metric
     public float getAverageFontWidth()
     {
-        if (averageWidth == 0)
+        if (Float.compare(averageWidth, 0) == 0)
         {
             float totalWidths = 0.0f;
             int characterCount = 0;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java?rev=1827078&r1=1827077&r2=1827078&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java Sat
Mar 17 12:13:40 2018
@@ -218,10 +218,13 @@ public class PDCIDFontType0 extends PDCI
     {
         if (getFontDescriptor() != null) {
             PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
-            if (bbox.getLowerLeftX() != 0 || bbox.getLowerLeftY() != 0 ||
-                bbox.getUpperRightX() != 0 || bbox.getUpperRightY() != 0) {
+            if (bbox != null && (Float.compare(bbox.getLowerLeftX(),0) != 0 ||
+                Float.compare(bbox.getLowerLeftY(),0) != 0 ||
+                Float.compare(bbox.getUpperRightX(),0) != 0 ||
+                Float.compare(bbox.getUpperRightY(),0) != 0))
+            {
                 return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
-                                       bbox.getUpperRightX(), bbox.getUpperRightY());
+                                          bbox.getUpperRightX(), bbox.getUpperRightY());
             }
         }
         if (cidFont != null)

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java?rev=1827078&r1=1827077&r2=1827078&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java Sat Mar 17
12:13:40 2018
@@ -376,7 +376,7 @@ public abstract class PDFont implements
     public float getAverageFontWidth()
     {
         float average;
-        if (avgFontWidth != 0.0f)
+        if (Float.compare(avgFontWidth, 0.0f) != 0.0f)
         {
             average = avgFontWidth;
         }
@@ -524,7 +524,7 @@ public abstract class PDFont implements
      */
     public float getSpaceWidth()
     {
-        if (fontWidthOfSpace == -1f)
+        if (Float.compare(fontWidthOfSpace, -1f) == 0)
         {
             COSBase toUnicode = dict.getDictionaryObject(COSName.TO_UNICODE);
             try

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontDescriptor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontDescriptor.java?rev=1827078&r1=1827077&r2=1827078&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontDescriptor.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontDescriptor.java
Sat Mar 17 12:13:40 2018
@@ -540,7 +540,7 @@ public final class PDFontDescriptor impl
      */
     public float getCapHeight()
     {
-        if(capHeight==Float.NEGATIVE_INFINITY)
+        if(Float.compare(capHeight, Float.NEGATIVE_INFINITY) == 0)
         {
             /* We observed a negative value being returned with
              * the Scheherazade font. PDFBOX-429 was logged for this.
@@ -570,7 +570,7 @@ public final class PDFontDescriptor impl
      */
     public float getXHeight()
     {
-        if(xHeight==Float.NEGATIVE_INFINITY)
+        if(Float.compare(xHeight, Float.NEGATIVE_INFINITY) == 0)
         {
             /* We observed a negative value being returned with
              * the Scheherazade font. PDFBOX-429 was logged for this.

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java?rev=1827078&r1=1827077&r2=1827078&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java Sat
Mar 17 12:13:40 2018
@@ -27,6 +27,7 @@ import org.apache.fontbox.FontBoxFont;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.font.encoding.DictionaryEncoding;
 import org.apache.pdfbox.pdmodel.font.encoding.Encoding;
 import org.apache.pdfbox.pdmodel.font.encoding.GlyphList;
@@ -384,6 +385,16 @@ public abstract class PDSimpleFont exten
         return super.isStandard14();
     }
 
+    protected boolean isNonZeroBoundingBox (PDRectangle bbox)
+    {
+        return bbox != null && (
+            Float.compare(bbox.getLowerLeftX(), 0) != 0 ||
+            Float.compare(bbox.getLowerLeftY(), 0) != 0 ||
+            Float.compare(bbox.getUpperRightX(), 0) != 0 ||
+            Float.compare(bbox.getUpperRightY(), 0) != 0
+        );
+    }
+
     /**
      * Returns the path for the character with the given name. For some fonts, GIDs may be
used
      * instead of names when calling this method.

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java?rev=1827078&r1=1827077&r2=1827078&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java Sat
Mar 17 12:13:40 2018
@@ -329,7 +329,7 @@ public class PDTrueTypeFont extends PDSi
         int gid = codeToGID(code);
         float width = ttf.getAdvanceWidth(gid);
         float unitsPerEM = ttf.getUnitsPerEm();
-        if (unitsPerEM != 1000)
+        if (Float.compare(unitsPerEM, 1000) != 0)
         {
             width *= 1000f / unitsPerEM;
         }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java?rev=1827078&r1=1827077&r2=1827078&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java Sat
Mar 17 12:13:40 2018
@@ -212,9 +212,7 @@ public class PDType1CFont extends PDSimp
     {
         if (getFontDescriptor() != null) {
             PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
-            if (bbox != null
-                    && (bbox.getLowerLeftX() != 0 || bbox.getLowerLeftY() != 0
-                    || bbox.getUpperRightX() != 0 || bbox.getUpperRightY() != 0))
+            if (isNonZeroBoundingBox(bbox))
             {
                 return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
                                        bbox.getUpperRightX(), bbox.getUpperRightY());

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java?rev=1827078&r1=1827077&r2=1827078&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java Sat
Mar 17 12:13:40 2018
@@ -557,9 +557,7 @@ public class PDType1Font extends PDSimpl
     {
         if (getFontDescriptor() != null) {
             PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
-            if (bbox != null &&
-                    (bbox.getLowerLeftX() != 0 || bbox.getLowerLeftY() != 0 ||
-                     bbox.getUpperRightX() != 0 || bbox.getUpperRightY() != 0))
+            if (isNonZeroBoundingBox(bbox))
             {
                 return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
                                        bbox.getUpperRightX(), bbox.getUpperRightY());

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java?rev=1827078&r1=1827077&r2=1827078&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java Sat
Mar 17 12:13:40 2018
@@ -176,15 +176,15 @@ public class PDType3Font extends PDSimpl
             {
                 retval = bbox.getHeight() / 2;
             }
-            if (retval == 0)
+            if (Float.compare(retval, 0) == 0)
             {
                 retval = desc.getCapHeight();
             }
-            if (retval == 0)
+            if (Float.compare(retval, 0) == 0)
             {
                 retval = desc.getAscent();
             }
-            if (retval == 0)
+            if (Float.compare(retval, 0) == 0)
             {
                 retval = desc.getXHeight();
                 if (retval > 0)
@@ -281,8 +281,7 @@ public class PDType3Font extends PDSimpl
     private BoundingBox generateBoundingBox()
     {
         PDRectangle rect = getFontBBox();
-        if (rect.getLowerLeftX() == 0 && rect.getLowerLeftY() == 0
-                && rect.getUpperRightX() == 0 && rect.getUpperRightY() ==
0)
+        if (!isNonZeroBoundingBox(rect))
         {
             // Plan B: get the max bounding box of the glyphs
             COSDictionary cp = getCharProcs();



Mime
View raw message