From 027e1bc3c09089fc690c6da32d3c0e1d255416fd Mon Sep 17 00:00:00 2001 From: Markus Fisch Date: Mon, 30 Oct 2023 15:37:43 +0100 Subject: [PATCH 1/3] ios: expose all native result items in wrapper So ecLevel, version and all the other fields can be accessed from iOS apps too. --- .../Wrapper/Reader/ZXIBarcodeReader.mm | 52 ++++++++++++++++--- wrappers/ios/Sources/Wrapper/Reader/ZXIGTIN.h | 22 ++++++++ .../ios/Sources/Wrapper/Reader/ZXIGTIN.mm | 20 +++++++ .../ios/Sources/Wrapper/Reader/ZXIResult.h | 23 +++++++- .../ios/Sources/Wrapper/Reader/ZXIResult.mm | 22 +++++++- wrappers/ios/Sources/Wrapper/UmbrellaHeader.h | 1 + zxing-cpp.podspec | 2 +- 7 files changed, 132 insertions(+), 10 deletions(-) create mode 100644 wrappers/ios/Sources/Wrapper/Reader/ZXIGTIN.h create mode 100644 wrappers/ios/Sources/Wrapper/Reader/ZXIGTIN.mm diff --git a/wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm b/wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm index 1e32566378..122c1e6e52 100644 --- a/wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm +++ b/wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm @@ -6,11 +6,43 @@ #import "ReadBarcode.h" #import "ImageView.h" #import "Result.h" +#import "GTIN.h" #import "ZXIFormatHelper.h" #import "ZXIPosition+Helper.h" using namespace ZXing; +NSString *stringToNSString(const std::string &text) { + return [[NSString alloc]initWithBytes:text.data() length:text.size() encoding:NSUTF8StringEncoding]; +} + +ZXIGTIN *getGTIN(const Result &result) { + auto format = result.format(); + auto text = result.text(TextMode::Plain); + NSString *country; + NSString *addOn; + NSString *price; + NSString *issueNumber; + if ((BarcodeFormat::EAN13 | BarcodeFormat::EAN8 | BarcodeFormat::UPCA | + BarcodeFormat::UPCE).testFlag(format)) { + country = stringToNSString(GTIN::LookupCountryIdentifier(text, format)); + addOn = stringToNSString(GTIN::EanAddOn(result)); + price = stringToNSString(GTIN::Price(GTIN::EanAddOn(result))); + issueNumber = stringToNSString(GTIN::IssueNr(GTIN::EanAddOn(result))); + } else if (format == BarcodeFormat::ITF && text.length() == 14) { + country = stringToNSString(GTIN::LookupCountryIdentifier(text, format)); + addOn = stringToNSString(""); + price = stringToNSString(""); + issueNumber = stringToNSString(""); + } + return country + ? [[ZXIGTIN alloc]initWithCountry:country + addOn:addOn + price:price + issueNumber:issueNumber] + : nullptr; +} + @interface ZXIBarcodeReader() @property (nonatomic, strong) CIContext* ciContext; @end @@ -115,16 +147,22 @@ + (DecodeHints)DecodeHintsFromZXIOptions:(ZXIDecodeHints*)hints { NSMutableArray* zxiResults = [NSMutableArray array]; for (auto result: results) { - auto resultText = result.text(); - NSString *text = [[NSString alloc]initWithBytes:resultText.data() length:resultText.size() encoding:NSUTF8StringEncoding]; - - NSData *bytes = [[NSData alloc] initWithBytes:result.bytes().data() length:result.bytes().size()]; [zxiResults addObject: - [[ZXIResult alloc] init:text + [[ZXIResult alloc] init:stringToNSString(result.text()) format:ZXIFormatFromBarcodeFormat(result.format()) - bytes:bytes + bytes:[[NSData alloc] initWithBytes:result.bytes().data() length:result.bytes().size()] position:[[ZXIPosition alloc]initWithPosition: result.position()] - ]]; + orientation:result.orientation() + ecLevel:stringToNSString(result.ecLevel()) + symbologyIdentifier:stringToNSString(result.symbologyIdentifier()) + sequenceSize:result.sequenceSize() + sequenceIndex:result.sequenceIndex() + sequenceId:stringToNSString(result.sequenceId()) + readerInit:result.readerInit() + lineCount:result.lineCount() + version:stringToNSString(result.version()) + gtin:getGTIN(result)] + ]; } return zxiResults; } diff --git a/wrappers/ios/Sources/Wrapper/Reader/ZXIGTIN.h b/wrappers/ios/Sources/Wrapper/Reader/ZXIGTIN.h new file mode 100644 index 0000000000..0992d845ff --- /dev/null +++ b/wrappers/ios/Sources/Wrapper/Reader/ZXIGTIN.h @@ -0,0 +1,22 @@ +// Copyright 2022 KURZ Digital Solutions GmbH +// +// SPDX-License-Identifier: Apache-2.0 + + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface ZXIGTIN : NSObject +@property(nonatomic, nonnull)NSString *country; +@property(nonatomic, nonnull)NSString *addOn; +@property(nonatomic, nonnull)NSString *price; +@property(nonatomic, nonnull)NSString *issueNumber; + +- (instancetype)initWithCountry:(NSString *)country + addOn:(NSString *)addOn + price:(NSString *)price + issueNumber:(NSString *)issueNumber; +@end + +NS_ASSUME_NONNULL_END diff --git a/wrappers/ios/Sources/Wrapper/Reader/ZXIGTIN.mm b/wrappers/ios/Sources/Wrapper/Reader/ZXIGTIN.mm new file mode 100644 index 0000000000..c0d801d0b6 --- /dev/null +++ b/wrappers/ios/Sources/Wrapper/Reader/ZXIGTIN.mm @@ -0,0 +1,20 @@ +// Copyright 2022 KURZ Digital Solutions GmbH +// +// SPDX-License-Identifier: Apache-2.0 + + +#import "ZXIGTIN.h" + +@implementation ZXIGTIN +- (instancetype)initWithCountry:(NSString *)country + addOn:(NSString *)addOn + price:(NSString *)price + issueNumber:(NSString *)issueNumber { + self = [super init]; + self.country = country; + self.addOn = addOn; + self.price = price; + self.issueNumber = issueNumber; + return self; +} +@end diff --git a/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.h b/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.h index 83d8a4cffc..7027e5a52d 100644 --- a/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.h +++ b/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.h @@ -5,6 +5,7 @@ #import #import "ZXIFormat.h" #import "ZXIPosition.h" +#import "ZXIGTIN.h" NS_ASSUME_NONNULL_BEGIN @@ -13,11 +14,31 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, strong) NSData *bytes; @property(nonatomic, strong) ZXIPosition *position; @property(nonatomic) ZXIFormat format; +@property(nonatomic) NSInteger orientation; +@property(nonatomic, strong) NSString *ecLevel; +@property(nonatomic, strong) NSString *symbologyIdentifier; +@property(nonatomic) NSInteger sequenceSize; +@property(nonatomic) NSInteger sequenceIndex; +@property(nonatomic, strong) NSString *sequenceId; +@property(nonatomic) BOOL readerInit; +@property(nonatomic) NSInteger lineCount; +@property(nonatomic, strong) NSString *version; +@property(nonatomic, strong) ZXIGTIN *gtin; - (instancetype)init:(NSString *)text format:(ZXIFormat)format bytes:(NSData *)bytes - position:(ZXIPosition *)position; + position:(ZXIPosition *)position + orientation:(NSInteger)orientation + ecLevel:(NSString *)ecLevel + symbologyIdentifier:(NSString *)symbologyIdentifier + sequenceSize:(NSInteger)sequenceSize + sequenceIndex:(NSInteger)sequenceIndex + sequenceId:(NSString *)sequenceId + readerInit:(BOOL)readerInit + lineCount:(NSInteger)lineCount + version:(NSString *)version + gtin:(ZXIGTIN *)gtin; @end NS_ASSUME_NONNULL_END diff --git a/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.mm b/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.mm index b84267d2a0..75377497d1 100644 --- a/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.mm +++ b/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.mm @@ -8,12 +8,32 @@ @implementation ZXIResult - (instancetype)init:(NSString *)text format:(ZXIFormat)format bytes:(NSData *)bytes - position:(ZXIPosition *)position { + position:(ZXIPosition *)position + orientation:(NSInteger)orientation + ecLevel:(NSString *)ecLevel + symbologyIdentifier:(NSString *)symbologyIdentifier + sequenceSize:(NSInteger)sequenceSize + sequenceIndex:(NSInteger)sequenceIndex + sequenceId:(NSString *)sequenceId + readerInit:(BOOL)readerInit + lineCount:(NSInteger)lineCount + version:(NSString *)version + gtin:(ZXIGTIN *)gtin { self = [super init]; self.text = text; self.format = format; self.bytes = bytes; self.position = position; + self.orientation = orientation; + self.ecLevel = ecLevel; + self.symbologyIdentifier = symbologyIdentifier; + self.sequenceSize = sequenceSize; + self.sequenceIndex = sequenceIndex; + self.sequenceId = sequenceId; + self.readerInit = readerInit; + self.lineCount = lineCount; + self.version = version; + self.gtin = gtin; return self; } @end diff --git a/wrappers/ios/Sources/Wrapper/UmbrellaHeader.h b/wrappers/ios/Sources/Wrapper/UmbrellaHeader.h index d76dc767c4..b14dc9b5df 100644 --- a/wrappers/ios/Sources/Wrapper/UmbrellaHeader.h +++ b/wrappers/ios/Sources/Wrapper/UmbrellaHeader.h @@ -9,6 +9,7 @@ #import "Reader/ZXIResult.h" #import "Reader/ZXIPosition.h" #import "Reader/ZXIPoint.h" +#import "Reader/ZXIGTIN.h" #import "Reader/ZXIDecodeHints.h" #import "Writer/ZXIEncodeHints.h" #import "Writer/ZXIBarcodeWriter.h" diff --git a/zxing-cpp.podspec b/zxing-cpp.podspec index 23da89b8b8..02997d19c0 100644 --- a/zxing-cpp.podspec +++ b/zxing-cpp.podspec @@ -31,7 +31,7 @@ Pod::Spec.new do |s| ss.dependency 'zxing-cpp/Core' ss.frameworks = 'CoreGraphics', 'CoreImage', 'CoreVideo' ss.source_files = 'wrappers/ios/Sources/Wrapper/**/*.{h,m,mm}' - ss.public_header_files = 'wrappers/ios/Sources/Wrapper/Reader/{ZXIBarcodeReader,ZXIResult,ZXIPosition,ZXIPoint,ZXIDecodeHints}.h', + ss.public_header_files = 'wrappers/ios/Sources/Wrapper/Reader/{ZXIBarcodeReader,ZXIResult,ZXIPosition,ZXIPoint,ZXIGTIN,ZXIDecodeHints}.h', 'wrappers/ios/Sources/Wrapper/Writer/{ZXIBarcodeWriter,ZXIEncodeHints}.h', 'wrappers/ios/Sources/Wrapper/{ZXIErrors,ZXIFormat}.h' ss.exclude_files = 'wrappers/ios/Sources/Wrapper/UmbrellaHeader.h' From dd75592f546e3671bf6ba29cf135257447932c64 Mon Sep 17 00:00:00 2001 From: Markus Fisch Date: Tue, 31 Oct 2023 10:17:22 +0100 Subject: [PATCH 2/3] ios: simplify composing GTIN info --- .../Wrapper/Reader/ZXIBarcodeReader.mm | 32 +++++-------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm b/wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm index 122c1e6e52..18be16d997 100644 --- a/wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm +++ b/wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm @@ -17,30 +17,14 @@ } ZXIGTIN *getGTIN(const Result &result) { - auto format = result.format(); - auto text = result.text(TextMode::Plain); - NSString *country; - NSString *addOn; - NSString *price; - NSString *issueNumber; - if ((BarcodeFormat::EAN13 | BarcodeFormat::EAN8 | BarcodeFormat::UPCA | - BarcodeFormat::UPCE).testFlag(format)) { - country = stringToNSString(GTIN::LookupCountryIdentifier(text, format)); - addOn = stringToNSString(GTIN::EanAddOn(result)); - price = stringToNSString(GTIN::Price(GTIN::EanAddOn(result))); - issueNumber = stringToNSString(GTIN::IssueNr(GTIN::EanAddOn(result))); - } else if (format == BarcodeFormat::ITF && text.length() == 14) { - country = stringToNSString(GTIN::LookupCountryIdentifier(text, format)); - addOn = stringToNSString(""); - price = stringToNSString(""); - issueNumber = stringToNSString(""); - } - return country - ? [[ZXIGTIN alloc]initWithCountry:country - addOn:addOn - price:price - issueNumber:issueNumber] - : nullptr; + auto country = GTIN::LookupCountryIdentifier(result.text(TextMode::Plain), result.format()); + auto addOn = GTIN::EanAddOn(result); + return country.empty() + ? nullptr + : [[ZXIGTIN alloc]initWithCountry:stringToNSString(country) + addOn:stringToNSString(addOn) + price:stringToNSString(GTIN::Price(addOn)) + issueNumber:stringToNSString(GTIN::IssueNr(addOn))]; } @interface ZXIBarcodeReader() From 18c3fef00ad657605a301e06489b74415d978fe2 Mon Sep 17 00:00:00 2001 From: Markus Fisch Date: Tue, 31 Oct 2023 10:21:44 +0100 Subject: [PATCH 3/3] ios: remove version from ZXIResult Will be deprecated soon. --- wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm | 1 - wrappers/ios/Sources/Wrapper/Reader/ZXIResult.h | 2 -- wrappers/ios/Sources/Wrapper/Reader/ZXIResult.mm | 2 -- 3 files changed, 5 deletions(-) diff --git a/wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm b/wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm index 18be16d997..c13b150e8c 100644 --- a/wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm +++ b/wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm @@ -144,7 +144,6 @@ + (DecodeHints)DecodeHintsFromZXIOptions:(ZXIDecodeHints*)hints { sequenceId:stringToNSString(result.sequenceId()) readerInit:result.readerInit() lineCount:result.lineCount() - version:stringToNSString(result.version()) gtin:getGTIN(result)] ]; } diff --git a/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.h b/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.h index 7027e5a52d..9c4c4e8a36 100644 --- a/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.h +++ b/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.h @@ -22,7 +22,6 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, strong) NSString *sequenceId; @property(nonatomic) BOOL readerInit; @property(nonatomic) NSInteger lineCount; -@property(nonatomic, strong) NSString *version; @property(nonatomic, strong) ZXIGTIN *gtin; - (instancetype)init:(NSString *)text @@ -37,7 +36,6 @@ NS_ASSUME_NONNULL_BEGIN sequenceId:(NSString *)sequenceId readerInit:(BOOL)readerInit lineCount:(NSInteger)lineCount - version:(NSString *)version gtin:(ZXIGTIN *)gtin; @end diff --git a/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.mm b/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.mm index 75377497d1..6a80a77d28 100644 --- a/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.mm +++ b/wrappers/ios/Sources/Wrapper/Reader/ZXIResult.mm @@ -17,7 +17,6 @@ - (instancetype)init:(NSString *)text sequenceId:(NSString *)sequenceId readerInit:(BOOL)readerInit lineCount:(NSInteger)lineCount - version:(NSString *)version gtin:(ZXIGTIN *)gtin { self = [super init]; self.text = text; @@ -32,7 +31,6 @@ - (instancetype)init:(NSString *)text self.sequenceId = sequenceId; self.readerInit = readerInit; self.lineCount = lineCount; - self.version = version; self.gtin = gtin; return self; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy