X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Foned%2FMultiFormatUPCEANReader.java;h=e561f59806e8f0578efe6b545ed1a2ba9d3fd41c;hp=4524f3e3e8cb765ff7bd9558bb4ae0d008a1b78b;hb=15c31851811509205c843513211574f3b80db110;hpb=cc9f94ab92df39bcadd2aaf1b579dd9a65ea2be3 diff --git a/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java b/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java index 4524f3e3..e561f598 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; }