mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Specify allowed EAN extensions as a hint.
This commit is contained in:
parent
9d4b8b9565
commit
1baa8f3311
|
@ -88,6 +88,15 @@ public enum DecodeHintType {
|
|||
*/
|
||||
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.
|
||||
;
|
||||
|
||||
|
|
|
@ -194,15 +194,33 @@ public abstract class UPCEANReader extends OneDReader {
|
|||
new ResultPoint(right, (float) rowNumber)},
|
||||
format);
|
||||
|
||||
int extensionLength = 0;
|
||||
|
||||
try {
|
||||
Result extensionResult = extensionReader.decodeRow(rowNumber, row, endRange[1]);
|
||||
decodeResult.putMetadata(ResultMetadataType.UPC_EAN_EXTENSION, extensionResult.getText());
|
||||
decodeResult.putAllMetadata(extensionResult.getResultMetadata());
|
||||
decodeResult.addResultPoints(extensionResult.getResultPoints());
|
||||
extensionLength = extensionResult.getText().length();
|
||||
} catch (ReaderException re) {
|
||||
// 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) {
|
||||
String countryID = eanManSupport.lookupCountryIdentifier(resultString);
|
||||
if (countryID != null) {
|
||||
|
|
Loading…
Reference in a new issue