mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Merge pull request #63 from embarkmobile/ean-extension
Specify allowed EAN extensions as a hint
This commit is contained in:
commit
347813c971
|
@ -88,6 +88,15 @@ public enum DecodeHintType {
|
||||||
*/
|
*/
|
||||||
NEED_RESULT_POINT_CALLBACK(ResultPointCallback.class),
|
NEED_RESULT_POINT_CALLBACK(ResultPointCallback.class),
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allowed extension lengths for EAN or UPC barcodes.
|
||||||
|
* Other formats will ignore this.
|
||||||
|
* Maps to an {@code int[]} of the allowed extension lengths, for example [2], [5], or [2, 5].
|
||||||
|
* If it is optional to have an extension, do not set this hint.
|
||||||
|
*/
|
||||||
|
ALLOWED_EAN_EXTENSIONS(int[].class);
|
||||||
|
|
||||||
// End of enumeration values.
|
// End of enumeration values.
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
@ -194,15 +194,33 @@ public abstract class UPCEANReader extends OneDReader {
|
||||||
new ResultPoint(right, (float) rowNumber)},
|
new ResultPoint(right, (float) rowNumber)},
|
||||||
format);
|
format);
|
||||||
|
|
||||||
|
int extensionLength = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Result extensionResult = extensionReader.decodeRow(rowNumber, row, endRange[1]);
|
Result extensionResult = extensionReader.decodeRow(rowNumber, row, endRange[1]);
|
||||||
decodeResult.putMetadata(ResultMetadataType.UPC_EAN_EXTENSION, extensionResult.getText());
|
decodeResult.putMetadata(ResultMetadataType.UPC_EAN_EXTENSION, extensionResult.getText());
|
||||||
decodeResult.putAllMetadata(extensionResult.getResultMetadata());
|
decodeResult.putAllMetadata(extensionResult.getResultMetadata());
|
||||||
decodeResult.addResultPoints(extensionResult.getResultPoints());
|
decodeResult.addResultPoints(extensionResult.getResultPoints());
|
||||||
|
extensionLength = extensionResult.getText().length();
|
||||||
} catch (ReaderException re) {
|
} catch (ReaderException re) {
|
||||||
// continue
|
// continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int[] allowedExtensions = hints == null ? null :
|
||||||
|
(int[])hints.get(DecodeHintType.ALLOWED_EAN_EXTENSIONS);
|
||||||
|
if(allowedExtensions != null) {
|
||||||
|
boolean valid = false;
|
||||||
|
for (int length : allowedExtensions) {
|
||||||
|
if(extensionLength == length) {
|
||||||
|
valid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!valid) {
|
||||||
|
throw NotFoundException.getNotFoundInstance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (format == BarcodeFormat.EAN_13 || format == BarcodeFormat.UPC_A) {
|
if (format == BarcodeFormat.EAN_13 || format == BarcodeFormat.UPC_A) {
|
||||||
String countryID = eanManSupport.lookupCountryIdentifier(resultString);
|
String countryID = eanManSupport.lookupCountryIdentifier(resultString);
|
||||||
if (countryID != null) {
|
if (countryID != null) {
|
||||||
|
|
Loading…
Reference in a new issue