From 14a03f40b1bb16b0925079ed34bef4467a2f2286 Mon Sep 17 00:00:00 2001 From: srowen Date: Wed, 1 Sep 2010 10:26:37 +0000 Subject: [PATCH] Issue 537, don't return UPC-A for EAN-13 starting with 0 when UPC-A isn't allowed git-svn-id: https://zxing.googlecode.com/svn/trunk@1572 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../google/zxing/oned/MultiFormatUPCEANReader.java | 14 ++++++++++---- .../google/zxing/oned/EAN13BlackBox1TestCase.java | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java b/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java index 4524f3e3e..e561f5980 100644 --- a/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java +++ b/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java @@ -85,10 +85,16 @@ public final class MultiFormatUPCEANReader extends OneDReader { // a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read // UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A // result if appropriate. - if (result.getBarcodeFormat().equals(BarcodeFormat.EAN_13) && - result.getText().charAt(0) == '0') { - return new Result(result.getText().substring(1), null, result.getResultPoints(), - BarcodeFormat.UPC_A); + // + // But, don't return UPC-A if UPC-A was not a requested format! + boolean ean13MayBeUPCA = + BarcodeFormat.EAN_13.equals(result.getBarcodeFormat()) && + result.getText().charAt(0) == '0'; + Vector possibleFormats = hints == null ? null : (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS); + boolean canReturnUPCA = possibleFormats == null || possibleFormats.contains(BarcodeFormat.UPC_A); + + if (ean13MayBeUPCA && canReturnUPCA) { + return new Result(result.getText().substring(1), null, result.getResultPoints(), BarcodeFormat.UPC_A); } return result; } diff --git a/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java b/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java index 00f1e3ba9..a8fc37df5 100644 --- a/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java @@ -27,7 +27,7 @@ public final class EAN13BlackBox1TestCase extends AbstractBlackBoxTestCase { public EAN13BlackBox1TestCase() { super("test/data/blackbox/ean13-1", new MultiFormatReader(), BarcodeFormat.EAN_13); - addTest(29, 32, 0.0f); + addTest(30, 32, 0.0f); addTest(27, 32, 180.0f); }