Skip to content

Commit cc05f37

Browse files
committed
ios: rename ZXIEncodeHints to ZXIWriterOptions
Also make the Writer interface consistent with the Reader by making options a property of the writer instead.
1 parent a500449 commit cc05f37

7 files changed

+32
-23
lines changed

wrappers/ios/Sources/Wrapper/UmbrellaHeader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#import "Reader/ZXIPoint.h"
1212
#import "Reader/ZXIGTIN.h"
1313
#import "Reader/ZXIReaderOptions.h"
14-
#import "Writer/ZXIEncodeHints.h"
14+
#import "Writer/ZXIWriterOptions.h"
1515
#import "Writer/ZXIBarcodeWriter.h"
1616
#import "ZXIErrors.h"
1717
#import "ZXIFormat.h"

wrappers/ios/Sources/Wrapper/Writer/ZXIBarcodeWriter.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
#import <Foundation/Foundation.h>
6-
#import "ZXIEncodeHints.h"
6+
#import "ZXIWriterOptions.h"
77

88
NS_ASSUME_NONNULL_BEGIN
99

1010
@interface ZXIBarcodeWriter : NSObject
11+
@property(nonatomic, strong) ZXIWriterOptions *options;
12+
13+
-(instancetype)initWithOptions:(ZXIWriterOptions*)options;
1114

1215
-(nullable CGImageRef)writeString:(NSString *)contents
13-
hints:(ZXIEncodeHints *)hints
1416
error:(NSError *__autoreleasing _Nullable *)error;
1517

1618
-(nullable CGImageRef)writeData:(NSData *)data
17-
hints:(ZXIEncodeHints *)hints
1819
error:(NSError *__autoreleasing _Nullable *)error;
1920

2021
@end

wrappers/ios/Sources/Wrapper/Writer/ZXIBarcodeWriter.mm

+21-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#import <CoreGraphics/CoreGraphics.h>
66
#import "ZXIBarcodeWriter.h"
7-
#import "ZXIEncodeHints.h"
7+
#import "ZXIWriterOptions.h"
88
#import "MultiFormatWriter.h"
99
#import "BitMatrix.h"
1010
#import "BitMatrixIO.h"
@@ -32,29 +32,37 @@
3232

3333
@implementation ZXIBarcodeWriter
3434

35+
- (instancetype)init {
36+
return [self initWithOptions: [[ZXIWriterOptions alloc] init]];
37+
}
38+
39+
- (instancetype)initWithOptions:(ZXIWriterOptions*)options{
40+
self = [super init];
41+
self.options = options;
42+
return self;
43+
}
44+
3545
-(CGImageRef)writeData:(NSData *)data
36-
hints:(ZXIEncodeHints *)hints
3746
error:(NSError *__autoreleasing _Nullable *)error {
3847
return [self encode: NSDataToStringW(data)
3948
encoding: CharacterSet::BINARY
40-
format: hints.format
41-
width: hints.width
42-
height: hints.height
43-
margin: hints.margin
44-
ecLevel: hints.ecLevel
49+
format: self.options.format
50+
width: self.options.width
51+
height: self.options.height
52+
margin: self.options.margin
53+
ecLevel: self.options.ecLevel
4554
error: error];
4655
}
4756

4857
-(CGImageRef)writeString:(NSString *)contents
49-
hints:(ZXIEncodeHints *)hints
5058
error:(NSError *__autoreleasing _Nullable *)error {
5159
return [self encode: NSStringToStringW(contents)
5260
encoding: CharacterSet::UTF8
53-
format: hints.format
54-
width: hints.width
55-
height: hints.height
56-
margin: hints.margin
57-
ecLevel: hints.ecLevel
61+
format: self.options.format
62+
width: self.options.width
63+
height: self.options.height
64+
margin: self.options.margin
65+
ecLevel: self.options.ecLevel
5866
error: error];
5967
}
6068

wrappers/ios/Sources/Wrapper/Writer/ZXIEncodeHints.h wrappers/ios/Sources/Wrapper/Writer/ZXIWriterOptions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern const int PDF417_ERROR_CORRECTION_6;
3030
extern const int PDF417_ERROR_CORRECTION_7;
3131
extern const int PDF417_ERROR_CORRECTION_8;
3232

33-
@interface ZXIEncodeHints : NSObject
33+
@interface ZXIWriterOptions : NSObject
3434
@property(nonatomic) ZXIFormat format;
3535
@property(nonatomic) int width;
3636
@property(nonatomic) int height;

wrappers/ios/Sources/Wrapper/Writer/ZXIEncodeHints.mm wrappers/ios/Sources/Wrapper/Writer/ZXIWriterOptions.mm

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// SPDX-License-Identifier: Apache-2.0
44

5-
#import "ZXIEncodeHints.h"
5+
#import "ZXIWriterOptions.h"
66

77
const int AZTEC_ERROR_CORRECTION_0 = 0;
88
const int AZTEC_ERROR_CORRECTION_12 = 1;
@@ -27,7 +27,7 @@
2727
const int PDF417_ERROR_CORRECTION_7 = 7;
2828
const int PDF417_ERROR_CORRECTION_8 = 8;
2929

30-
@implementation ZXIEncodeHints
30+
@implementation ZXIWriterOptions
3131

3232
- (instancetype)initWithFormat:(ZXIFormat)format {
3333
self = [super init];

wrappers/ios/demo/demo/WriteViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class WriteViewController: UIViewController {
1414
// MARK: - Actions
1515

1616
@IBAction func textFieldChanged(_ sender: UITextField) {
17-
let hints = ZXIEncodeHints(format: .QR_CODE, width: 200, height: 200, ecLevel: QR_ERROR_CORRECTION_LOW, margin: -1)
17+
let options = ZXIWriterOptions(format: .QR_CODE, width: 200, height: 200, ecLevel: QR_ERROR_CORRECTION_LOW, margin: -1)
1818
guard let text = sender.text,
19-
let image = try? ZXIBarcodeWriter().write(text, hints: hints)
19+
let image = try? ZXIBarcodeWriter(options: options).write(text)
2020
else {
2121
return
2222
}

zxing-cpp.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Pod::Spec.new do |s|
3232
ss.frameworks = 'CoreGraphics', 'CoreImage', 'CoreVideo'
3333
ss.source_files = 'wrappers/ios/Sources/Wrapper/**/*.{h,m,mm}'
3434
ss.public_header_files = 'wrappers/ios/Sources/Wrapper/Reader/{ZXIBarcodeReader,ZXIResult,ZXIPosition,ZXIPoint,ZXIGTIN,ZXIReaderOptions}.h',
35-
'wrappers/ios/Sources/Wrapper/Writer/{ZXIBarcodeWriter,ZXIEncodeHints}.h',
35+
'wrappers/ios/Sources/Wrapper/Writer/{ZXIBarcodeWriter,ZXIWriterOptions}.h',
3636
'wrappers/ios/Sources/Wrapper/{ZXIErrors,ZXIFormat}.h'
3737
ss.exclude_files = 'wrappers/ios/Sources/Wrapper/UmbrellaHeader.h'
3838
end

0 commit comments

Comments
 (0)