Issue 1193 more small PDF417 fixes and a new test

git-svn-id: https://zxing.googlecode.com/svn/trunk@2213 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-03-02 23:20:02 +00:00
parent a88da9d002
commit 240424bec0
5 changed files with 26 additions and 16 deletions

View file

@ -149,8 +149,8 @@ final class DecodedBitStreamParser {
} else { } else {
switch (code) { switch (code) {
case TEXT_COMPACTION_MODE_LATCH: case TEXT_COMPACTION_MODE_LATCH:
codeIndex--; // reinitialize text compaction mode to alpha sub mode
end = true; textCompactionData[index++] = TEXT_COMPACTION_MODE_LATCH;
break; break;
case BYTE_COMPACTION_MODE_LATCH: case BYTE_COMPACTION_MODE_LATCH:
codeIndex--; codeIndex--;
@ -232,9 +232,7 @@ final class DecodedBitStreamParser {
subMode = Mode.PUNCT_SHIFT; subMode = Mode.PUNCT_SHIFT;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { } else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
result.append((char) byteCompactionData[i]); result.append((char) byteCompactionData[i]);
// the pdf417 specs say we have to return to the last latched } else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
// sub-mode. But I checked different encoder implementations and
// all of them return to alpha sub-mode after Shift-to-Byte
subMode = Mode.ALPHA; subMode = Mode.ALPHA;
} }
} }
@ -263,6 +261,8 @@ final class DecodedBitStreamParser {
// sub-mode. But I checked different encoder implementations and // sub-mode. But I checked different encoder implementations and
// all of them return to alpha sub-mode after Shift-to-Byte // all of them return to alpha sub-mode after Shift-to-Byte
subMode = Mode.ALPHA; subMode = Mode.ALPHA;
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
subMode = Mode.ALPHA;
} }
} }
break; break;
@ -286,9 +286,7 @@ final class DecodedBitStreamParser {
subMode = Mode.PUNCT_SHIFT; subMode = Mode.PUNCT_SHIFT;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { } else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
result.append((char) byteCompactionData[i]); result.append((char) byteCompactionData[i]);
// the pdf417 specs say we have to return to the last latched } else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
// sub-mode. But I checked different encoder implementations and
// all of them return to alpha sub-mode after Shift-to-Byte
subMode = Mode.ALPHA; subMode = Mode.ALPHA;
} }
} }
@ -303,9 +301,7 @@ final class DecodedBitStreamParser {
subMode = Mode.ALPHA; subMode = Mode.ALPHA;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { } else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
result.append((char) byteCompactionData[i]); result.append((char) byteCompactionData[i]);
// the pdf417 specs say we have to return to the last latched } else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
// sub-mode. But I checked different encoder implementations and
// all of them return to alpha sub-mode after Shift-to-Byte
subMode = Mode.ALPHA; subMode = Mode.ALPHA;
} }
} }
@ -319,6 +315,8 @@ final class DecodedBitStreamParser {
} else { } else {
if (subModeCh == 26) { if (subModeCh == 26) {
ch = ' '; ch = ' ';
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
subMode = Mode.ALPHA;
} else { } else {
// is this even possible? // is this even possible?
} }
@ -341,6 +339,8 @@ final class DecodedBitStreamParser {
// sub-mode. But I checked different encoder implementations and // sub-mode. But I checked different encoder implementations and
// all of them return to alpha sub-mode after Shift-to-Byte // all of them return to alpha sub-mode after Shift-to-Byte
subMode = Mode.ALPHA; subMode = Mode.ALPHA;
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
subMode = Mode.ALPHA;
} }
} }
break; break;

View file

@ -0,0 +1 @@
!<21><> !E<> 5/D? ?<3F>FZ c'<27><> mA<> <09>#F

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

View file

@ -54,6 +54,8 @@ import java.util.Properties;
*/ */
public abstract class AbstractBlackBoxTestCase extends Assert { 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() { private static final FilenameFilter IMAGE_NAME_FILTER = new FilenameFilter() {
@Override @Override
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
@ -140,7 +142,14 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
String testImageFileName = testImage.getName(); String testImageFileName = testImage.getName();
String fileBaseName = testImageFileName.substring(0, testImageFileName.indexOf('.')); String fileBaseName = testImageFileName.substring(0, testImageFileName.indexOf('.'));
File expectedTextFile = new File(testBase, fileBaseName + ".txt"); 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"); File expectedMetadataFile = new File(testBase, fileBaseName + ".metadata.txt");
Properties expectedMetadata = new Properties(); Properties expectedMetadata = new Properties();
@ -283,9 +292,9 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
return true; 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()); 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 { try {
char[] buffer = new char[256]; char[] buffer = new char[256];
int charsRead; int charsRead;

View file

@ -29,8 +29,8 @@ public final class PDF417BlackBox1TestCase extends AbstractBlackBoxTestCase {
public PDF417BlackBox1TestCase() { public PDF417BlackBox1TestCase() {
super("test/data/blackbox/pdf417", new MultiFormatReader(), BarcodeFormat.PDF_417); super("test/data/blackbox/pdf417", new MultiFormatReader(), BarcodeFormat.PDF_417);
addTest(4, 4, 0.0f); addTest(5, 5, 0.0f);
addTest(4, 4, 180.0f); addTest(5, 5, 180.0f);
} }
} }