diff options
author | Bertrand Delacretaz <bdelacretaz@apache.org> | 2006-10-11 09:06:01 +0000 |
---|---|---|
committer | Bertrand Delacretaz <bdelacretaz@apache.org> | 2006-10-11 09:06:01 +0000 |
commit | 9a8cca06a4e21a810addbb70e18ef1d5cccd45c2 (patch) | |
tree | 19f7242e91b4156596ee60899581d636637d925b /src/java/org | |
parent | e43e5d73087f1d3e801fd05252f92b019a2fe343 (diff) | |
download | xmlgraphics-fop-9a8cca06a4e21a810addbb70e18ef1d5cccd45c2.tar.gz xmlgraphics-fop-9a8cca06a4e21a810addbb70e18ef1d5cccd45c2.zip |
Patch from bugzilla 5335 comment #17 applied, thanks to vincent.hennebert@anyware-tech.com.
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
Diffstat (limited to 'src/java/org')
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFToUnicodeCMap.java | 102 |
1 files changed, 39 insertions, 63 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFToUnicodeCMap.java b/src/java/org/apache/fop/pdf/PDFToUnicodeCMap.java index 7f599a7a2..32a9faa23 100644 --- a/src/java/org/apache/fop/pdf/PDFToUnicodeCMap.java +++ b/src/java/org/apache/fop/pdf/PDFToUnicodeCMap.java @@ -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; } /** |