diff --git a/core/src/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java b/core/src/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java index afc9828bc..33bdcd542 100644 --- a/core/src/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java +++ b/core/src/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java @@ -149,8 +149,8 @@ final class DecodedBitStreamParser { } else { switch (code) { case TEXT_COMPACTION_MODE_LATCH: - codeIndex--; - end = true; + // reinitialize text compaction mode to alpha sub mode + textCompactionData[index++] = TEXT_COMPACTION_MODE_LATCH; break; case BYTE_COMPACTION_MODE_LATCH: codeIndex--; @@ -232,9 +232,7 @@ final class DecodedBitStreamParser { subMode = Mode.PUNCT_SHIFT; } else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { result.append((char) byteCompactionData[i]); - // the pdf417 specs say we have to return to the last latched - // sub-mode. But I checked different encoder implementations and - // all of them return to alpha sub-mode after Shift-to-Byte + } else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { subMode = Mode.ALPHA; } } @@ -263,6 +261,8 @@ final class DecodedBitStreamParser { // sub-mode. But I checked different encoder implementations and // all of them return to alpha sub-mode after Shift-to-Byte subMode = Mode.ALPHA; + } else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { + subMode = Mode.ALPHA; } } break; @@ -286,9 +286,7 @@ final class DecodedBitStreamParser { subMode = Mode.PUNCT_SHIFT; } else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { result.append((char) byteCompactionData[i]); - // the pdf417 specs say we have to return to the last latched - // sub-mode. But I checked different encoder implementations and - // all of them return to alpha sub-mode after Shift-to-Byte + } else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { subMode = Mode.ALPHA; } } @@ -303,9 +301,7 @@ final class DecodedBitStreamParser { subMode = Mode.ALPHA; } else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { result.append((char) byteCompactionData[i]); - // the pdf417 specs say we have to return to the last latched - // sub-mode. But I checked different encoder implementations and - // all of them return to alpha sub-mode after Shift-to-Byte + } else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { subMode = Mode.ALPHA; } } @@ -319,6 +315,8 @@ final class DecodedBitStreamParser { } else { if (subModeCh == 26) { ch = ' '; + } else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { + subMode = Mode.ALPHA; } else { // is this even possible? } @@ -341,6 +339,8 @@ final class DecodedBitStreamParser { // sub-mode. But I checked different encoder implementations and // all of them return to alpha sub-mode after Shift-to-Byte subMode = Mode.ALPHA; + } else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { + subMode = Mode.ALPHA; } } break; diff --git a/core/test/data/blackbox/pdf417/09.bin b/core/test/data/blackbox/pdf417/09.bin new file mode 100644 index 000000000..7633e3a11 --- /dev/null +++ b/core/test/data/blackbox/pdf417/09.bin @@ -0,0 +1 @@ +!‚Ÿ !Eô 5/D? ?šFZ c'‚ÿ mAÉ  #F \ No newline at end of file diff --git a/core/test/data/blackbox/pdf417/09.png b/core/test/data/blackbox/pdf417/09.png new file mode 100644 index 000000000..7bd09430c Binary files /dev/null and b/core/test/data/blackbox/pdf417/09.png differ diff --git a/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java b/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java index 9bbd9c753..d61de339d 100644 --- a/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java +++ b/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java @@ -54,6 +54,8 @@ import java.util.Properties; */ public abstract class AbstractBlackBoxTestCase extends Assert { + private static final Charset UTF8 = Charset.forName("UTF-8"); + private static final Charset ISO88591 = Charset.forName("ISO-8859-1"); private static final FilenameFilter IMAGE_NAME_FILTER = new FilenameFilter() { @Override public boolean accept(File dir, String name) { @@ -140,7 +142,14 @@ public abstract class AbstractBlackBoxTestCase extends Assert { String testImageFileName = testImage.getName(); String fileBaseName = testImageFileName.substring(0, testImageFileName.indexOf('.')); File expectedTextFile = new File(testBase, fileBaseName + ".txt"); - String expectedText = readFileAsString(expectedTextFile); + String expectedText; + if (expectedTextFile.exists()) { + expectedText = readFileAsString(expectedTextFile, UTF8); + } else { + expectedTextFile = new File(testBase, fileBaseName + ".bin"); + assertTrue(expectedTextFile.exists()); + expectedText = readFileAsString(expectedTextFile, ISO88591); + } File expectedMetadataFile = new File(testBase, fileBaseName + ".metadata.txt"); Properties expectedMetadata = new Properties(); @@ -283,9 +292,9 @@ public abstract class AbstractBlackBoxTestCase extends Assert { return true; } - private static String readFileAsString(File file) throws IOException { + private static String readFileAsString(File file, Charset charset) throws IOException { StringBuilder result = new StringBuilder((int) file.length()); - InputStreamReader reader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF8")); + InputStreamReader reader = new InputStreamReader(new FileInputStream(file), charset); try { char[] buffer = new char[256]; int charsRead; diff --git a/core/test/src/com/google/zxing/pdf417/PDF417BlackBox1TestCase.java b/core/test/src/com/google/zxing/pdf417/PDF417BlackBox1TestCase.java index 7acfcbfe0..70fcb41be 100644 --- a/core/test/src/com/google/zxing/pdf417/PDF417BlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/pdf417/PDF417BlackBox1TestCase.java @@ -29,8 +29,8 @@ public final class PDF417BlackBox1TestCase extends AbstractBlackBoxTestCase { public PDF417BlackBox1TestCase() { super("test/data/blackbox/pdf417", new MultiFormatReader(), BarcodeFormat.PDF_417); - addTest(4, 4, 0.0f); - addTest(4, 4, 180.0f); + addTest(5, 5, 0.0f); + addTest(5, 5, 180.0f); } } \ No newline at end of file