Skip to content

Commit f50cd5c

Browse files
authored
ios: specify EC level/margin for generation (#644)
* ios: specify EC level/margin for generation * ios: add ZXIEncodeHints to bundle options
1 parent b8c3d1a commit f50cd5c

File tree

7 files changed

+129
-24
lines changed

7 files changed

+129
-24
lines changed

wrappers/ios/Sources/Wrapper/UmbrellaHeader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "Reader/ZXIPosition.h"
1111
#import "Reader/ZXIPoint.h"
1212
#import "Reader/ZXIDecodeHints.h"
13+
#import "Writer/ZXIEncodeHints.h"
1314
#import "Writer/ZXIBarcodeWriter.h"
1415
#import "ZXIErrors.h"
1516
#import "ZXIFormat.h"

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,41 @@
33
// SPDX-License-Identifier: Apache-2.0
44

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

88
NS_ASSUME_NONNULL_BEGIN
99

10+
const int AZTEC_ERROR_CORRECTION_0 = 0;
11+
const int AZTEC_ERROR_CORRECTION_12 = 1;
12+
const int AZTEC_ERROR_CORRECTION_25 = 2;
13+
const int AZTEC_ERROR_CORRECTION_37 = 3;
14+
const int AZTEC_ERROR_CORRECTION_50 = 4;
15+
const int AZTEC_ERROR_CORRECTION_62 = 5;
16+
const int AZTEC_ERROR_CORRECTION_75 = 6;
17+
const int AZTEC_ERROR_CORRECTION_87 = 7;
18+
const int AZTEC_ERROR_CORRECTION_100 = 8;
19+
const int QR_ERROR_CORRECTION_LOW = 2;
20+
const int QR_ERROR_CORRECTION_MEDIUM = 4;
21+
const int QR_ERROR_CORRECTION_QUARTILE = 6;
22+
const int QR_ERROR_CORRECTION_HIGH = 8;
23+
const int PDF417_ERROR_CORRECTION_0 = 0;
24+
const int PDF417_ERROR_CORRECTION_1 = 1;
25+
const int PDF417_ERROR_CORRECTION_2 = 2;
26+
const int PDF417_ERROR_CORRECTION_3 = 3;
27+
const int PDF417_ERROR_CORRECTION_4 = 4;
28+
const int PDF417_ERROR_CORRECTION_5 = 5;
29+
const int PDF417_ERROR_CORRECTION_6 = 6;
30+
const int PDF417_ERROR_CORRECTION_7 = 7;
31+
const int PDF417_ERROR_CORRECTION_8 = 8;
32+
1033
@interface ZXIBarcodeWriter : NSObject
1134

1235
-(nullable CGImageRef)writeString:(NSString *)contents
13-
width:(int)width
14-
height:(int)height
15-
format:(ZXIFormat)format
36+
hints:(ZXIEncodeHints *)hints
1637
error:(NSError *__autoreleasing _Nullable *)error;
1738

1839
-(nullable CGImageRef)writeData:(NSData *)data
19-
width:(int)width
20-
height:(int)height
21-
format:(ZXIFormat)format
40+
hints:(ZXIEncodeHints *)hints
2241
error:(NSError *__autoreleasing _Nullable *)error;
2342

2443
@end

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#import <CoreGraphics/CoreGraphics.h>
66
#import "ZXIBarcodeWriter.h"
7+
#import "ZXIEncodeHints.h"
78
#import "MultiFormatWriter.h"
89
#import "BitMatrix.h"
910
#import "BitMatrixIO.h"
@@ -23,7 +24,7 @@
2324
std::wstring s;
2425
const unsigned char *bytes = (const unsigned char *) [data bytes];
2526
size_t len = [data length];
26-
for (int i = 0; i < len; ++i) {
27+
for (int i = 0; i < len; ++i) {
2728
s.push_back(bytes[i]);
2829
}
2930
return s;
@@ -32,39 +33,43 @@
3233
@implementation ZXIBarcodeWriter
3334

3435
-(CGImageRef)writeData:(NSData *)data
35-
width:(int)width
36-
height:(int)height
37-
format:(ZXIFormat)format
36+
hints:(ZXIEncodeHints *)hints
3837
error:(NSError *__autoreleasing _Nullable *)error {
3938
return [self encode: NSDataToStringW(data)
40-
width: width
41-
height: height
42-
format: format
4339
encoding: CharacterSet::BINARY
40+
format: hints.format
41+
width: hints.width
42+
height: hints.height
43+
margin: hints.margin
44+
ecLevel: hints.ecLevel
4445
error: error];
4546
}
4647

4748
-(CGImageRef)writeString:(NSString *)contents
48-
width:(int)width
49-
height:(int)height
50-
format:(ZXIFormat)format
49+
hints:(ZXIEncodeHints *)hints
5150
error:(NSError *__autoreleasing _Nullable *)error {
5251
return [self encode: NSStringToStringW(contents)
53-
width: width
54-
height: height
55-
format: format
5652
encoding: CharacterSet::UTF8
53+
format: hints.format
54+
width: hints.width
55+
height: hints.height
56+
margin: hints.margin
57+
ecLevel: hints.ecLevel
5758
error: error];
5859
}
5960

6061
-(CGImageRef)encode:(std::wstring)content
62+
encoding:(CharacterSet)encoding
63+
format:(ZXIFormat)format
6164
width:(int)width
6265
height:(int)height
63-
format:(ZXIFormat)format
64-
encoding:(CharacterSet)encoding
66+
margin:(int)margin
67+
ecLevel:(int)ecLevel
6568
error:(NSError *__autoreleasing _Nullable *)error {
6669
MultiFormatWriter writer { BarcodeFormatFromZXIFormat(format) };
6770
writer.setEncoding(encoding);
71+
writer.setMargin(margin);
72+
writer.setEccLevel(ecLevel);
6873
// Catch exception for invalid formats
6974
try {
7075
BitMatrix bitMatrix = writer.encode(content, width, height);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2023 KURZ Digital Solutions GmbH
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#import <Foundation/Foundation.h>
6+
#import "ZXIFormat.h"
7+
8+
NS_ASSUME_NONNULL_BEGIN
9+
10+
@interface ZXIEncodeHints : NSObject
11+
@property(nonatomic) ZXIFormat format;
12+
@property(nonatomic) int width;
13+
@property(nonatomic) int height;
14+
@property(nonatomic) int ecLevel;
15+
@property(nonatomic) int margin;
16+
17+
- (instancetype)initWithFormat:(ZXIFormat)format;
18+
19+
- (instancetype)initWithFormat:(ZXIFormat)format
20+
width:(int)width
21+
height:(int)height
22+
ecLevel:(int)ecLevel
23+
margin:(int)margin;
24+
@end
25+
26+
NS_ASSUME_NONNULL_END
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2023 KURZ Digital Solutions GmbH
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#import "ZXIEncodeHints.h"
6+
7+
@implementation ZXIEncodeHints
8+
9+
- (instancetype)initWithFormat:(ZXIFormat)format {
10+
self = [super init];
11+
self.format = format;
12+
self.width = 0;
13+
self.height = 0;
14+
self.ecLevel = -1;
15+
self.margin = -1;
16+
return self;
17+
}
18+
19+
- (instancetype)initWithFormat:(ZXIFormat)format
20+
width:(int)width
21+
height:(int)height
22+
ecLevel:(int)ecLevel
23+
margin:(int)margin {
24+
self = [super init];
25+
self.format = format;
26+
self.width = width;
27+
self.height = height;
28+
self.ecLevel = ecLevel;
29+
self.margin = margin;
30+
return self;
31+
}
32+
33+
-(void)setFormat:(ZXIFormat)format {
34+
self.format = format;
35+
}
36+
37+
-(void)setWidth:(int)width {
38+
self.width = width;
39+
}
40+
41+
-(void)setHeight:(int)height {
42+
self.height = height;
43+
}
44+
45+
-(void)setEcLevel:(int)ecLevel {
46+
self.ecLevel = ecLevel;
47+
}
48+
49+
-(void)setMargin:(int)margin {
50+
self.margin = margin;
51+
}
52+
53+
@end

wrappers/ios/demo/demo/WriteViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +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)
1718
guard let text = sender.text,
18-
let image = try? ZXIBarcodeWriter().write(text, width: 200, height: 200, format: .QR_CODE)
19+
let image = try? ZXIBarcodeWriter().write(text, hints: hints)
1920
else {
2021
return
2122
}

zxing-cpp.podspec

Lines changed: 1 addition & 1 deletion
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,ZXIDecodeHints}.h',
35-
'wrappers/ios/Sources/Wrapper/Writer/ZXIBarcodeWriter.h',
35+
'wrappers/ios/Sources/Wrapper/Writer/{ZXIBarcodeWriter,ZXIEncodeHints}.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)
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