From 78c42636167d6dca93559998ee59ef9e84646543 Mon Sep 17 00:00:00 2001 From: Chris Wood Date: Wed, 3 Jan 2024 20:00:42 +0000 Subject: [PATCH] Telepen numeric support --- examples/webpack+js/index.html | 1 + examples/webpack+js/index.js | 2 +- src/decode_hints.rs | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/webpack+js/index.html b/examples/webpack+js/index.html index b1b98fb..e208a94 100644 --- a/examples/webpack+js/index.html +++ b/examples/webpack+js/index.html @@ -31,6 +31,7 @@

RXing - Decode Barcodes

+ diff --git a/examples/webpack+js/index.js b/examples/webpack+js/index.js index ef3d039..4a259b9 100644 --- a/examples/webpack+js/index.js +++ b/examples/webpack+js/index.js @@ -1,7 +1,7 @@ import { convert_js_image_to_luma, decode_barcode_with_hints, DecodeHintDictionary, DecodeHintTypes, BarcodeFormat } from "rxing-wasm"; const text_hints = ["Other", "PossibleFormats", "CharacterSet", "AllowedLengths", "AllowedEanExtensions"]; -const bool_hints = ["PureBarcode", "TryHarder", "AssumeCode39CheckDigit", "ReturnCodabarStartEnd", "AssumeGs1", "AlsoInverted"] +const bool_hints = ["PureBarcode", "TryHarder", "AssumeCode39CheckDigit", "ReturnCodabarStartEnd", "AssumeGs1", "AlsoInverted", "TelepenAsNumeric"] const scan_btn = document.getElementById('scan_btn'); const input = document.getElementById('image_file_input'); diff --git a/src/decode_hints.rs b/src/decode_hints.rs index dc2eba9..8ae5018 100644 --- a/src/decode_hints.rs +++ b/src/decode_hints.rs @@ -76,6 +76,12 @@ pub enum DecodeHintTypes { * second time with an inverted image. Doesn't matter what it maps to; use {@link Boolean#TRUE}. */ AlsoInverted, + + + /** + * Translate the ASCII values parsed by the Telepen reader into the Telepen Numeric form; use {@link Boolean#TRUE}. + */ + TelepenAsNumeric, } impl From for rxing::DecodeHintType { @@ -99,6 +105,7 @@ impl From for rxing::DecodeHintType { } DecodeHintTypes::AllowedEanExtensions => rxing::DecodeHintType::ALLOWED_EAN_EXTENSIONS, DecodeHintTypes::AlsoInverted => rxing::DecodeHintType::ALSO_INVERTED, + DecodeHintTypes::TelepenAsNumeric => rxing::DecodeHintType::TELEPEN_AS_NUMERIC, } } } @@ -237,6 +244,13 @@ impl DecodeHintDictionary { rxing::DecodeHintValue::AlsoInverted(also_inverted), ); } + DecodeHintTypes::TelepenAsNumeric => { + let Ok(telepen_as_numeric) = value.parse() else { + return false; + }; + self.0 + .insert(hint.into(), rxing::DecodeHintValue::TelepenAsNumeric(telepen_as_numeric)); + } } true }