Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ios: expose all native result items in wrapper #649

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,27 @@
#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 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()
@property (nonatomic, strong) CIContext* ciContext;
@end
Expand Down Expand Up @@ -115,16 +131,21 @@ + (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()
gtin:getGTIN(result)]
];
}
return zxiResults;
}
Expand Down
22 changes: 22 additions & 0 deletions wrappers/ios/Sources/Wrapper/Reader/ZXIGTIN.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2022 KURZ Digital Solutions GmbH
//
// SPDX-License-Identifier: Apache-2.0


#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface ZXIGTIN : NSObject
@property(nonatomic, nonnull)NSString *country;
@property(nonatomic, nonnull)NSString *addOn;
markusfisch marked this conversation as resolved.
Show resolved Hide resolved
@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
20 changes: 20 additions & 0 deletions wrappers/ios/Sources/Wrapper/Reader/ZXIGTIN.mm
Original file line number Diff line number Diff line change
@@ -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
21 changes: 20 additions & 1 deletion wrappers/ios/Sources/Wrapper/Reader/ZXIResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import <Foundation/Foundation.h>
#import "ZXIFormat.h"
#import "ZXIPosition.h"
#import "ZXIGTIN.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -13,11 +14,29 @@ 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) 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
gtin:(ZXIGTIN *)gtin;
@end

NS_ASSUME_NONNULL_END
20 changes: 19 additions & 1 deletion wrappers/ios/Sources/Wrapper/Reader/ZXIResult.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,30 @@ @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
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.gtin = gtin;
return self;
}
@end
1 change: 1 addition & 0 deletions wrappers/ios/Sources/Wrapper/UmbrellaHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion zxing-cpp.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down