From 012a8c0ce7945baeb517b552dc697865baf4c950 Mon Sep 17 00:00:00 2001 From: srowen Date: Wed, 2 Apr 2008 13:40:29 +0000 Subject: [PATCH] Fixed same ResultPoint bug in Code 128 and Code 39 reader; added convenient toString() to Result and GenericResultPoint; added arg checking for Result constructor too git-svn-id: https://zxing.googlecode.com/svn/trunk@336 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- core/src/com/google/zxing/Result.java | 11 +++++++++++ .../com/google/zxing/common/GenericResultPoint.java | 10 ++++++++++ core/src/com/google/zxing/oned/Code128Reader.java | 6 ++++-- core/src/com/google/zxing/oned/Code39Reader.java | 6 ++++-- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/core/src/com/google/zxing/Result.java b/core/src/com/google/zxing/Result.java index a32067378..3173af3d2 100644 --- a/core/src/com/google/zxing/Result.java +++ b/core/src/com/google/zxing/Result.java @@ -35,6 +35,9 @@ public final class Result { byte[] rawBytes, ResultPoint[] resultPoints, BarcodeFormat format) { + if (text == null && rawBytes == null) { + throw new IllegalArgumentException("Text and bytes are null"); + } this.text = text; this.rawBytes = rawBytes; this.resultPoints = resultPoints; @@ -87,4 +90,12 @@ public final class Result { resultMetadata.put(type, value); } + public String toString() { + if (text == null) { + return "[" + rawBytes.length + " bytes]"; + } else { + return text; + } + } + } diff --git a/core/src/com/google/zxing/common/GenericResultPoint.java b/core/src/com/google/zxing/common/GenericResultPoint.java index 800f773ff..c72e7b29b 100644 --- a/core/src/com/google/zxing/common/GenericResultPoint.java +++ b/core/src/com/google/zxing/common/GenericResultPoint.java @@ -42,4 +42,14 @@ public final class GenericResultPoint implements ResultPoint { return posY; } + public String toString() { + StringBuffer result = new StringBuffer(); + result.append('('); + result.append(posX); + result.append(','); + result.append(posY); + result.append(')'); + return result.toString(); + } + } \ No newline at end of file diff --git a/core/src/com/google/zxing/oned/Code128Reader.java b/core/src/com/google/zxing/oned/Code128Reader.java index 46d1bd789..7a59bbd9a 100644 --- a/core/src/com/google/zxing/oned/Code128Reader.java +++ b/core/src/com/google/zxing/oned/Code128Reader.java @@ -405,12 +405,14 @@ public final class Code128Reader extends AbstractOneDReader { } String resultString = result.toString(); + float left = (float) (startPatternInfo[1] + startPatternInfo[0]) / 2.0f; + float right = (float) (nextStart + lastStart) / 2.0f; return new Result( resultString, null, new ResultPoint[]{ - new GenericResultPoint((float) (startPatternInfo[1] - startPatternInfo[0]) / 2.0f, (float) rowNumber), - new GenericResultPoint((float) (nextStart - lastStart) / 2.0f, (float) rowNumber)}, + new GenericResultPoint(left, (float) rowNumber), + new GenericResultPoint(right, (float) rowNumber)}, BarcodeFormat.CODE_128); } diff --git a/core/src/com/google/zxing/oned/Code39Reader.java b/core/src/com/google/zxing/oned/Code39Reader.java index 6ab9510bf..0d27ad793 100644 --- a/core/src/com/google/zxing/oned/Code39Reader.java +++ b/core/src/com/google/zxing/oned/Code39Reader.java @@ -138,12 +138,14 @@ public final class Code39Reader extends AbstractOneDReader { if (extendedMode) { resultString = decodeExtended(resultString); } + float left = (float) (start[1] + start[0]) / 2.0f; + float right = (float) (nextStart + lastStart) / 2.0f; return new Result( resultString, null, new ResultPoint[]{ - new GenericResultPoint((float) (start[1] - start[0]) / 2.0f, (float) rowNumber), - new GenericResultPoint((float) (nextStart - lastStart) / 2.0f, (float) rowNumber)}, + new GenericResultPoint(left, (float) rowNumber), + new GenericResultPoint(right, (float) rowNumber)}, BarcodeFormat.CODE_39); }