]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Patch from bugzilla 5335 comment #17 applied, thanks to vincent.hennebert@anyware...
authorBertrand Delacretaz <bdelacretaz@apache.org>
Wed, 11 Oct 2006 09:06:01 +0000 (09:06 +0000)
committerBertrand Delacretaz <bdelacretaz@apache.org>
Wed, 11 Oct 2006 09:06:01 +0000 (09:06 +0000)
Fixes "Illegal entry in bfrange block in ToUnicode CMap" error, and a potential problem when the ToUnicode table contains more than 100 ranges.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@462741 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/pdf/PDFToUnicodeCMap.java

index 7f599a7a2488238b228f881c3a19f49cefce4a7b..32a9faa23563fca492bb61c4fd30b0d4162a6107 100644 (file)
@@ -104,7 +104,6 @@ public class PDFToUnicodeCMap extends PDFCMap {
      * @param charArray all the characters to map
      */
     protected void writeBFCharEntries(StringBuffer p, char[] charArray) {
-        int completedEntries = 0;
         int totalEntries = 0;
         for (int i = 0; i < charArray.length; i++) {
             if (!partOfRange(charArray, i)) {
@@ -115,32 +114,23 @@ public class PDFToUnicodeCMap extends PDFCMap {
             return;
         }
         int remainingEntries = totalEntries;
-        /* Limited to 100 entries in each section */
-        int entriesThisSection = Math.min(remainingEntries, 100);
-        int remainingEntriesThisSection = entriesThisSection;
-        p.append(entriesThisSection + " beginbfchar\n");
-        for (int i = 0; i < charArray.length; i++) {
-            if (partOfRange(charArray, i)) {
-                continue;
-            }
-            p.append("<" + padHexString(Integer.toHexString(i), 4)
-                    + "> ");
-            p.append("<" + padHexString(Integer.toHexString(charArray[i]), 4)
-                    + ">\n");
-            /* Compute the statistics. */
-            completedEntries++;
-            remainingEntries = totalEntries - completedEntries;
-            remainingEntriesThisSection--;
-            if (remainingEntriesThisSection < 1) {
-                if (remainingEntries > 0) {
-                    p.append("endbfchar\n");
-                    entriesThisSection = Math.min(remainingEntries, 100);
-                    remainingEntriesThisSection = entriesThisSection;
-                    p.append(entriesThisSection + " beginbfchar\n");
-                }
+        int charIndex = 0;
+        do {
+            /* Limited to 100 entries in each section */
+            int entriesThisSection = Math.min(remainingEntries, 100);
+            p.append(entriesThisSection + " beginbfchar\n");
+            for (int i = 0; i < entriesThisSection; i++) {
+               /* Go to the next char not in a range */
+               while (partOfRange(charArray, charIndex)) {
+                       charIndex++;
+               }
+                p.append("<" + padHexString(Integer.toHexString(charIndex), 4) + "> ");
+                p.append("<" + padHexString(Integer.toHexString(charArray[charIndex]), 4) + ">\n");
+                charIndex++;
             }
-        }
-        p.append("endbfchar\n");
+            remainingEntries -= entriesThisSection;
+            p.append("endbfchar\n");
+        } while (remainingEntries > 0);
     }
 
     /**
@@ -149,7 +139,6 @@ public class PDFToUnicodeCMap extends PDFCMap {
      * @param charArray all the characters to map
      */
     protected void writeBFRangeEntries(StringBuffer p, char[] charArray) {
-        int completedEntries = 0;
         int totalEntries = 0;
         for (int i = 0; i < charArray.length; i++) {
             if (startOfRange(charArray, i)) {
@@ -160,36 +149,26 @@ public class PDFToUnicodeCMap extends PDFCMap {
             return;
         }
         int remainingEntries = totalEntries;
-        int entriesThisSection = Math.min(remainingEntries, 100);
-        int remainingEntriesThisSection = entriesThisSection;
-        p.append(entriesThisSection + " beginbfrange\n");
-        for (int i = 0; i < charArray.length; i++) {
-            if (!startOfRange(charArray, i)) {
-                continue;
+        int charIndex = 0;
+        do {
+            /* Limited to 100 entries in each section */
+            int entriesThisSection = Math.min(remainingEntries, 100);
+            p.append(entriesThisSection + " beginbfrange\n");
+            for (int i = 0; i < entriesThisSection; i++) {
+               /* Go to the next start of a range */
+               while (!startOfRange(charArray, charIndex)) {
+                       charIndex++;
+               }
+                p.append("<" + padHexString(Integer.toHexString(charIndex), 4) + "> ");
+                p.append("<"
+                               + padHexString(Integer.toHexString(endOfRange(charArray, charIndex)), 4)
+                               + "> ");
+                p.append("<" + padHexString(Integer.toHexString(charArray[charIndex]), 4) + ">\n");
+                charIndex++;
             }
-            p.append("<"
-                    + padHexString(Integer.toHexString(i), 4)
-                    + "> ");
-            p.append("<"
-                    + padHexString(Integer.toHexString
-                            (endOfRange(charArray, i)), 4)
-                    + "> ");
-            p.append("<"
-                    + padHexString(Integer.toHexString(charArray[i]), 4)
-                    + ">\n");
-            /* Compute the statistics. */
-            completedEntries++;
-            remainingEntries = totalEntries - completedEntries;
-            if (remainingEntriesThisSection < 1) {
-                if (remainingEntries > 0) {
-                    p.append("endbfrange\n");
-                    entriesThisSection = Math.min(remainingEntries, 100);
-                    remainingEntriesThisSection = entriesThisSection;
-                    p.append(entriesThisSection + " beginbfrange\n");
-                }
-            }
-        }
-        p.append("endbfrange\n");
+            remainingEntries -= entriesThisSection;
+            p.append("endbfrange\n");
+        } while (remainingEntries > 0);
     }
 
     /**
@@ -200,14 +179,11 @@ public class PDFToUnicodeCMap extends PDFCMap {
      * @return The index to the element that is the end of the range.
      */
     private int endOfRange(char[] charArray, int startOfRange) {
-        int endOfRange = -1;
-        for (int i = startOfRange; i < charArray.length - 1 && endOfRange < 0;
-                i++) {
-            if (!sameRangeEntryAsNext(charArray, i)) {
-                endOfRange = i;
-            }
+        int i = startOfRange;
+        while (i < charArray.length - 1 && sameRangeEntryAsNext(charArray, i)) {
+               i++;
         }
-        return endOfRange;
+        return i;
     }
 
     /**