pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1792082 - /pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java
Date Thu, 20 Apr 2017 16:41:44 GMT
Author: tilman
Date: Thu Apr 20 16:41:44 2017
New Revision: 1792082

URL: http://svn.apache.org/viewvc?rev=1792082&view=rev
Log:
PDFBOX-2852: simplify code, add javadoc

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java?rev=1792082&r1=1792081&r2=1792082&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java Thu Apr 20
16:41:44 2017
@@ -405,6 +405,10 @@ public class CMapParser
 
     /**
      * Returns an input stream containing the given "use" CMap.
+     *
+     * @param name Name of the given "use" CMap resource.
+     * @throws IOException if the CMap resource doesn't exist or if there is an error opening
its
+     * stream.
      */
     protected InputStream getExternalCMap(String name) throws IOException
     {
@@ -673,7 +677,7 @@ public class CMapParser
 
     private void increment(byte[] data, int position)
     {
-        if (position > 0 && (data[position] + 256) % 256 == 255)
+        if (position > 0 && (data[position] & 0xFF) == 255)
         {
             data[position] = 0;
             increment(data, position - 1);
@@ -686,51 +690,39 @@ public class CMapParser
 
     private int createIntFromBytes(byte[] bytes)
     {
-        int intValue = (bytes[0] + 256) % 256;
+        int intValue = bytes[0] & 0xFF;
         if (bytes.length == 2)
         {
             intValue <<= 8;
-            intValue += (bytes[1] + 256) % 256;
+            intValue += bytes[1] & 0xFF;
         }
         return intValue;
     }
 
     private String createStringFromBytes(byte[] bytes) throws IOException
     {
-        String retval;
-        if (bytes.length == 1)
-        {
-            retval = new String(bytes, Charsets.ISO_8859_1);
-        }
-        else
-        {
-            retval = new String(bytes, Charsets.UTF_16BE);
-        }
-        return retval;
+        return new String(bytes, bytes.length == 1 ? Charsets.ISO_8859_1 : Charsets.UTF_16BE);
     }
 
     private int compare(byte[] first, byte[] second)
     {
-        int retval = 1;
-        int firstLength = first.length;
-        for (int i = 0; i < firstLength; i++)
+        for (int i = 0; i < first.length; i++)
         {
             if (first[i] == second[i])
             {
                 continue;
             }
-            else if (((first[i] + 256) % 256) < ((second[i] + 256) % 256))
+
+            if ((first[i] & 0xFF) < (second[i] & 0xFF))
             {
-                retval = -1;
-                break;
+                return -1;
             }
             else
             {
-                retval = 1;
-                break;
+                return 1;
             }
         }
-        return retval;
+        return 0;
     }
 
     /**



Mime
View raw message