X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Foned%2FUPCEANExtensionSupport.java;h=15d15d3882c9d25c8d56469e6f1f24a3bed4b5a8;hp=3076941fd69ffe46cb35728d1cf4d4cd49b61389;hb=b527af627aa13d6ba6197b3dd957e91b2ba75705;hpb=9ceee6853d82d86e881fc3d6d7928ddd47df4cd0 diff --git a/core/src/com/google/zxing/oned/UPCEANExtensionSupport.java b/core/src/com/google/zxing/oned/UPCEANExtensionSupport.java index 3076941f..15d15d38 100644 --- a/core/src/com/google/zxing/oned/UPCEANExtensionSupport.java +++ b/core/src/com/google/zxing/oned/UPCEANExtensionSupport.java @@ -22,6 +22,7 @@ import com.google.zxing.BarcodeFormat; import com.google.zxing.NotFoundException; import com.google.zxing.Result; import com.google.zxing.ResultMetadataType; +import com.google.zxing.ResultPoint; import com.google.zxing.common.BitArray; final class UPCEANExtensionSupport { @@ -30,24 +31,29 @@ final class UPCEANExtensionSupport { private static final int[] CHECK_DIGIT_ENCODINGS = { 0x18, 0x14, 0x12, 0x11, 0x0C, 0x06, 0x03, 0x0A, 0x09, 0x05 }; - private static final int[][] SEPARATOR_PATTERNS = {{1,1}}; private final int[] decodeMiddleCounters = new int[4]; - private final int[] separatorCounters = new int[2]; private final StringBuffer decodeRowStringBuffer = new StringBuffer(); - Result decodeRow(BitArray row, int rowOffset) throws NotFoundException { + Result decodeRow(int rowNumber, BitArray row, int rowOffset) throws NotFoundException { int[] extensionStartRange = UPCEANReader.findGuardPattern(row, rowOffset, false, EXTENSION_START_PATTERN); StringBuffer result = decodeRowStringBuffer; result.setLength(0); - decodeMiddle(row, extensionStartRange, result); + int end = decodeMiddle(row, extensionStartRange, result); String resultString = result.toString(); Hashtable extensionData = parseExtensionString(resultString); - Result extensionResult = new Result(resultString, null, null, BarcodeFormat.UPC_EAN_EXTENSION); + Result extensionResult = + new Result(resultString, + null, + new ResultPoint[] { + new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, (float) rowNumber), + new ResultPoint((float) end, (float) rowNumber), + }, + BarcodeFormat.UPC_EAN_EXTENSION); if (extensionData != null) { extensionResult.putAllMetadata(extensionData); } @@ -60,9 +66,6 @@ final class UPCEANExtensionSupport { counters[1] = 0; counters[2] = 0; counters[3] = 0; - int[] separatorCounters = this.separatorCounters; - separatorCounters[0] = 0; - separatorCounters[1] = 0; int end = row.getSize(); int rowOffset = startRange[1]; @@ -77,20 +80,14 @@ final class UPCEANExtensionSupport { if (bestMatch >= 10) { lgPatternFound |= 1 << (4 - x); } - // Read off separator - /* - try { - UPCEANReader.decodeDigit(row, separatorCounters, rowOffset, SEPARATOR_PATTERNS); - rowOffset += separatorCounters[0] + separatorCounters[1]; - } catch (NotFoundException nfe) { - break; - } - */ - while (rowOffset < end && !row.get(rowOffset)) { - rowOffset++; - } - while (rowOffset < end && row.get(rowOffset)) { - rowOffset++; + if (x != 4) { + // Read off separator if not last + while (rowOffset < end && !row.get(rowOffset)) { + rowOffset++; + } + while (rowOffset < end && row.get(rowOffset)) { + rowOffset++; + } } } @@ -163,7 +160,7 @@ final class UPCEANExtensionSupport { } private static String parseExtension5String(String raw) { - String currency = null; + String currency; switch (raw.charAt(0)) { case '0': currency = "£"; @@ -172,18 +169,28 @@ final class UPCEANExtensionSupport { currency = "$"; break; case '9': - if ("99991".equals(raw)) { + // Reference: http://www.jollytech.com + if ("90000".equals(raw)) { + // No suggested retail price + return null; + } else if ("99991".equals(raw)) { + // Complementary return "0.00"; } else if ("99990".equals(raw)) { return "Used"; } + // Otherwise... unknown currency? + currency = ""; break; default: currency = ""; break; } int rawAmount = Integer.parseInt(raw.substring(1)); - return currency + (rawAmount / 100) + '.' + (rawAmount % 100); + String unitsString = String.valueOf(rawAmount / 100); + int hundredths = rawAmount % 100; + String hundredthsString = hundredths < 10 ? "0" + hundredths : String.valueOf(hundredths); + return currency + unitsString + '.' + hundredthsString; } }