From 06a1c9386f9a288c74e40153997d156c7d268734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Jose=CC=81=20Pereira=20Vieito?= Date: Fri, 28 May 2021 16:26:38 +0200 Subject: [PATCH 1/7] Added Mac Catalyst support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apple has marked much of the AVFoundation API as available on “Mac Catalyst 14.0+” so some available annotation are required --- Source/RSCode128Generator.swift | 1 + Source/RSCode39Generator.swift | 1 + Source/RSCode39Mod43Generator.swift | 1 + Source/RSCode93Generator.swift | 1 + Source/RSCodeDataMatrixGenerator.swift | 1 + Source/RSCodeGenerator.swift | 2 ++ Source/RSCodeReaderViewController.swift | 1 + Source/RSEANGenerator.swift | 5 +++++ Source/RSExtendedCode39Generator.swift | 1 + Source/RSITF14Generator.swift | 1 + Source/RSITFGenerator.swift | 1 + Source/RSUPCEGenerator.swift | 1 + Source/RSUnifiedCodeGenerator.swift | 2 ++ Source/RSUnifiedCodeValidator.swift | 3 +++ 14 files changed, 22 insertions(+) diff --git a/Source/RSCode128Generator.swift b/Source/RSCode128Generator.swift index 8283557..2652f29 100644 --- a/Source/RSCode128Generator.swift +++ b/Source/RSCode128Generator.swift @@ -15,6 +15,7 @@ public enum RSCode128GeneratorCodeTable: Int { // http://www.barcodeisland.com/code128.phtml // http://courses.cs.washington.edu/courses/cse370/01au/minirproject/BarcodeBattlers/barcodes.html +@available(macCatalyst 14.0, *) open class RSCode128Generator: RSAbstractCodeGenerator, RSCheckDigitGenerator { class RSCode128GeneratorAutoCodeTable { var startCodeTable = RSCode128GeneratorCodeTable.auto diff --git a/Source/RSCode39Generator.swift b/Source/RSCode39Generator.swift index 152ef6d..a26bfe0 100644 --- a/Source/RSCode39Generator.swift +++ b/Source/RSCode39Generator.swift @@ -12,6 +12,7 @@ let CODE39_ALPHABET_STRING = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*" // http://www.barcodesymbols.com/code39.htm // http://www.barcodeisland.com/code39.phtml +@available(macCatalyst 14.0, *) open class RSCode39Generator: RSAbstractCodeGenerator { let CODE39_CHARACTER_ENCODINGS = [ "1010011011010", diff --git a/Source/RSCode39Mod43Generator.swift b/Source/RSCode39Mod43Generator.swift index effd8d8..c362234 100644 --- a/Source/RSCode39Mod43Generator.swift +++ b/Source/RSCode39Mod43Generator.swift @@ -10,6 +10,7 @@ import UIKit // http://www.barcodesymbols.com/code39.htm // http://www.barcodeisland.com/code39.phtml +@available(macCatalyst 14.0, *) open class RSCode39Mod43Generator: RSCode39Generator, RSCheckDigitGenerator { // MARK: RSAbstractCodeGenerator diff --git a/Source/RSCode93Generator.swift b/Source/RSCode93Generator.swift index 8fa4ed3..f916af0 100644 --- a/Source/RSCode93Generator.swift +++ b/Source/RSCode93Generator.swift @@ -9,6 +9,7 @@ import UIKit // http://www.barcodeisland.com/code93.phtml +@available(macCatalyst 14.0, *) open class RSCode93Generator: RSAbstractCodeGenerator, RSCheckDigitGenerator { let CODE93_ALPHABET_STRING = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd*" diff --git a/Source/RSCodeDataMatrixGenerator.swift b/Source/RSCodeDataMatrixGenerator.swift index 8c768b7..98aafa4 100644 --- a/Source/RSCodeDataMatrixGenerator.swift +++ b/Source/RSCodeDataMatrixGenerator.swift @@ -8,6 +8,7 @@ import UIKit +@available(macCatalyst 14.0, *) class RSCodeDataMatrixGenerator: RSAbstractCodeGenerator { } diff --git a/Source/RSCodeGenerator.swift b/Source/RSCodeGenerator.swift index 795ee3a..a0bbd9c 100644 --- a/Source/RSCodeGenerator.swift +++ b/Source/RSCodeGenerator.swift @@ -23,6 +23,7 @@ public enum InputCorrectionLevel: String { } // Code generators are required to provide these two functions. +@available(macCatalyst 14.0, *) public protocol RSCodeGenerator { /** The fill (background) color of the generated barcode. */ var fillColor: UIColor {get set} @@ -54,6 +55,7 @@ public protocol RSCheckDigitGenerator { } // Abstract code generator, provides default functions for validations and generations. +@available(macCatalyst 14.0, *) open class RSAbstractCodeGenerator : RSCodeGenerator { open var fillColor: UIColor = UIColor.white diff --git a/Source/RSCodeReaderViewController.swift b/Source/RSCodeReaderViewController.swift index 8e5e3e0..c1eba18 100755 --- a/Source/RSCodeReaderViewController.swift +++ b/Source/RSCodeReaderViewController.swift @@ -9,6 +9,7 @@ import AVFoundation import UIKit +@available(macCatalyst 14.0, *) open class RSCodeReaderViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate { @objc open var device = AVCaptureDevice.default(for: AVMediaType.video) @objc open var output = AVCaptureMetadataOutput() diff --git a/Source/RSEANGenerator.swift b/Source/RSEANGenerator.swift index 0531938..e72412d 100644 --- a/Source/RSEANGenerator.swift +++ b/Source/RSEANGenerator.swift @@ -12,6 +12,7 @@ public let RSBarcodesTypeISBN13Code = "com.pdq.rsbarcodes.isbn13" public let RSBarcodesTypeISSN13Code = "com.pdq.rsbarcodes.issn13" // http://blog.sina.com.cn/s/blog_4015406e0100bsqk.html +@available(macCatalyst 14.0, *) open class RSEANGenerator: RSAbstractCodeGenerator { var length = 0 // 'O' for odd and 'E' for even @@ -100,18 +101,21 @@ open class RSEANGenerator: RSAbstractCodeGenerator { } } +@available(macCatalyst 14.0, *) class RSEAN8Generator: RSEANGenerator { init() { super.init(length: 8) } } +@available(macCatalyst 14.0, *) class RSEAN13Generator: RSEANGenerator { init() { super.init(length: 13) } } +@available(macCatalyst 14.0, *) class RSISBN13Generator: RSEAN13Generator { override func isValid(_ contents: String) -> Bool { // http://www.appsbarcode.com/ISBN.php @@ -119,6 +123,7 @@ class RSISBN13Generator: RSEAN13Generator { } } +@available(macCatalyst 14.0, *) class RSISSN13Generator: RSEAN13Generator { override func isValid(_ contents: String) -> Bool { // http://www.appsbarcode.com/ISSN.php diff --git a/Source/RSExtendedCode39Generator.swift b/Source/RSExtendedCode39Generator.swift index a4334ad..c347bfb 100644 --- a/Source/RSExtendedCode39Generator.swift +++ b/Source/RSExtendedCode39Generator.swift @@ -12,6 +12,7 @@ public let RSBarcodesTypeExtendedCode39Code = "com.pdq.rsbarcodes.code39.ext" // http://www.barcodesymbols.com/code39.htm // http://www.barcodeisland.com/code39.phtml +@available(macCatalyst 14.0, *) open class RSExtendedCode39Generator: RSCode39Generator { func encodeContents(_ contents: String) -> String { var encodedContents = "" diff --git a/Source/RSITF14Generator.swift b/Source/RSITF14Generator.swift index 5d229b2..774f064 100644 --- a/Source/RSITF14Generator.swift +++ b/Source/RSITF14Generator.swift @@ -10,6 +10,7 @@ import UIKit // http://www.gs1au.org/assets/documents/info/user_manuals/barcode_technical_details/ITF_14_Barcode_Structure.pdf // http://www.barcodeisland.com/int2of5.phtml +@available(macCatalyst 14.0, *) open class RSITF14Generator: RSITFGenerator { override open func isValid(_ contents: String) -> Bool { return super.isValid(contents) && contents.length() == 14 diff --git a/Source/RSITFGenerator.swift b/Source/RSITFGenerator.swift index 0939620..ce623b0 100644 --- a/Source/RSITFGenerator.swift +++ b/Source/RSITFGenerator.swift @@ -9,6 +9,7 @@ import UIKit // http://www.barcodeisland.com/int2of5.phtml +@available(macCatalyst 14.0, *) open class RSITFGenerator: RSAbstractCodeGenerator { let ITF_CHARACTER_ENCODINGS = [ "00110", diff --git a/Source/RSUPCEGenerator.swift b/Source/RSUPCEGenerator.swift index 7761331..0672039 100644 --- a/Source/RSUPCEGenerator.swift +++ b/Source/RSUPCEGenerator.swift @@ -12,6 +12,7 @@ import UIKit // http://mdn.morovia.com/kb/UPCE-Specification-10634.html // http://mdn.morovia.com/kb/UPCA-Specification-10632.html // http://www.barcodeisland.com/upce.phtml +@available(macCatalyst 14.0, *) open class RSUPCEGenerator: RSAbstractCodeGenerator, RSCheckDigitGenerator { let UPCE_ODD_ENCODINGS = [ "0001101", diff --git a/Source/RSUnifiedCodeGenerator.swift b/Source/RSUnifiedCodeGenerator.swift index 1cda36e..bb18b63 100644 --- a/Source/RSUnifiedCodeGenerator.swift +++ b/Source/RSUnifiedCodeGenerator.swift @@ -10,6 +10,7 @@ import Foundation import UIKit import AVFoundation +@available(macCatalyst 14.0, *) open class RSUnifiedCodeGenerator: RSCodeGenerator { open var isBuiltInCode128GeneratorSelected = false @@ -89,4 +90,5 @@ open class RSUnifiedCodeGenerator: RSCodeGenerator { } } +@available(macCatalyst 14.0, *) let UnifiedCodeGeneratorSharedInstance = RSUnifiedCodeGenerator() diff --git a/Source/RSUnifiedCodeValidator.swift b/Source/RSUnifiedCodeValidator.swift index 8a03585..044b6aa 100644 --- a/Source/RSUnifiedCodeValidator.swift +++ b/Source/RSUnifiedCodeValidator.swift @@ -9,6 +9,7 @@ import Foundation import AVFoundation +@available(macCatalyst 14.0, *) open class RSUnifiedCodeValidator { open class var shared: RSUnifiedCodeValidator { return UnifiedCodeValidatorSharedInstance @@ -52,4 +53,6 @@ open class RSUnifiedCodeValidator { return codeGenerator!.isValid(contents) } } + +@available(macCatalyst 14.0, *) let UnifiedCodeValidatorSharedInstance = RSUnifiedCodeValidator() From cfc3194c9635fb8a797e4729a4d9aa6cf3afae54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Jos=C3=A9=20Pereira=20Vieito?= Date: Fri, 28 May 2021 18:37:10 +0200 Subject: [PATCH 2/7] Added support for specifying the resizing scale --- Source/RSCodeGenerator.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/RSCodeGenerator.swift b/Source/RSCodeGenerator.swift index a0bbd9c..e184ca7 100644 --- a/Source/RSCodeGenerator.swift +++ b/Source/RSCodeGenerator.swift @@ -244,7 +244,7 @@ open class RSAbstractCodeGenerator : RSCodeGenerator { return target } - open class func resizeImage(_ source:UIImage, targetSize:CGSize, contentMode:UIView.ContentMode) -> UIImage? { + open class func resizeImage(_ source:UIImage, targetSize:CGSize, contentMode:UIView.ContentMode, scale:CGFloat? = nil) -> UIImage? { var x: CGFloat = 0 var y: CGFloat = 0 var width = targetSize.width @@ -295,7 +295,7 @@ open class RSAbstractCodeGenerator : RSCodeGenerator { } } - UIGraphicsBeginImageContextWithOptions(targetSize, false, 0) + UIGraphicsBeginImageContextWithOptions(targetSize, false, scale ?? 0) guard let context = UIGraphicsGetCurrentContext() else { return nil } context.interpolationQuality = CGInterpolationQuality.none source.draw(in: CGRect(x: x, y: y, width: width, height: height)) From be74c22a42cfe71ff0d819178c6ec1acd195e3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Jos=C3=A9=20Pereira=20Vieito?= Date: Fri, 28 May 2021 18:58:31 +0200 Subject: [PATCH 3/7] Set the initial rendering scale to 1 The initial barcode rendering scale should be set 1.0 to ensure the same barcode base image is generated in all devices (currently devices with scale x2 and x3 generate slightly different barcodes). --- Source/RSCodeGenerator.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/RSCodeGenerator.swift b/Source/RSCodeGenerator.swift index e184ca7..c45abe9 100644 --- a/Source/RSCodeGenerator.swift +++ b/Source/RSCodeGenerator.swift @@ -109,7 +109,7 @@ open class RSAbstractCodeGenerator : RSCodeGenerator { // Height = 28 let width = length + 4 let size = CGSize(width: CGFloat(width), height: 28) - UIGraphicsBeginImageContextWithOptions(size, false, 0) + UIGraphicsBeginImageContextWithOptions(size, false, 1) if let context = UIGraphicsGetCurrentContext() { context.setShouldAntialias(false) From 2efecc4c3fe76f4589bf4b4c55b0a9cca20d684f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Jos=C3=A9=20Pereira=20Vieito?= Date: Fri, 28 May 2021 19:05:42 +0200 Subject: [PATCH 4/7] DataMatrix validator should return false as it is not currently implemented --- Source/RSUnifiedCodeValidator.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/RSUnifiedCodeValidator.swift b/Source/RSUnifiedCodeValidator.swift index 044b6aa..2663afb 100644 --- a/Source/RSUnifiedCodeValidator.swift +++ b/Source/RSUnifiedCodeValidator.swift @@ -38,8 +38,8 @@ open class RSUnifiedCodeValidator { codeGenerator = RSCode93Generator() case AVMetadataObject.ObjectType.code128.rawValue: codeGenerator = RSCode128Generator() - case AVMetadataObject.ObjectType.dataMatrix.rawValue: - codeGenerator = RSCodeDataMatrixGenerator() + // case AVMetadataObject.ObjectType.dataMatrix.rawValue: + // codeGenerator = RSCodeDataMatrixGenerator() case RSBarcodesTypeISBN13Code: codeGenerator = RSISBN13Generator() case RSBarcodesTypeISSN13Code: From efb7ed1f3aede071783c23106c0f2f8971ad5ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Jose=CC=81=20Pereira=20Vieito?= Date: Sun, 1 Aug 2021 20:27:24 +0200 Subject: [PATCH 5/7] Added support for Xcode 13 --- Source/RSCodeReaderViewController.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/RSCodeReaderViewController.swift b/Source/RSCodeReaderViewController.swift index c1eba18..0b7af86 100755 --- a/Source/RSCodeReaderViewController.swift +++ b/Source/RSCodeReaderViewController.swift @@ -10,6 +10,7 @@ import AVFoundation import UIKit @available(macCatalyst 14.0, *) +@available(iOSApplicationExtension, unavailable) open class RSCodeReaderViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate { @objc open var device = AVCaptureDevice.default(for: AVMediaType.video) @objc open var output = AVCaptureMetadataOutput() From 0d51830c69abb663f859e95c252a56f25035efb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=99=93=E5=86=AC?= Date: Sat, 25 Sep 2021 13:20:48 +0800 Subject: [PATCH 6/7] Add some comments for RSCodeDataMatrixGenerator --- Source/RSUnifiedCodeValidator.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/RSUnifiedCodeValidator.swift b/Source/RSUnifiedCodeValidator.swift index 2663afb..32f35b6 100644 --- a/Source/RSUnifiedCodeValidator.swift +++ b/Source/RSUnifiedCodeValidator.swift @@ -38,8 +38,10 @@ open class RSUnifiedCodeValidator { codeGenerator = RSCode93Generator() case AVMetadataObject.ObjectType.code128.rawValue: codeGenerator = RSCode128Generator() - // case AVMetadataObject.ObjectType.dataMatrix.rawValue: - // codeGenerator = RSCodeDataMatrixGenerator() + /** TODO: Uncomment this once DataMatrix generator is implemented. + case AVMetadataObject.ObjectType.dataMatrix.rawValue: + codeGenerator = RSCodeDataMatrixGenerator() + */ case RSBarcodesTypeISBN13Code: codeGenerator = RSISBN13Generator() case RSBarcodesTypeISSN13Code: From cb7cd1feb13543b9577dac5717f901c803ffb9db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=99=93=E5=86=AC?= Date: Sat, 25 Sep 2021 13:46:07 +0800 Subject: [PATCH 7/7] Update sample qr string value --- .../RSBarcodesSample/BarcodeDisplayViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RSBarcodesSample/RSBarcodesSample/BarcodeDisplayViewController.swift b/RSBarcodesSample/RSBarcodesSample/BarcodeDisplayViewController.swift index af1c6a9..3868205 100755 --- a/RSBarcodesSample/RSBarcodesSample/BarcodeDisplayViewController.swift +++ b/RSBarcodesSample/RSBarcodesSample/BarcodeDisplayViewController.swift @@ -16,7 +16,7 @@ import RSBarcodes class BarcodeDisplayViewController: UIViewController { @IBOutlet weak var imageDisplayed: UIImageView! - var contents: String = "https://github.com/VMwareFusion/nautilus" + var contents: String = "https://github.com/yeahdongcn/" override func viewDidLoad() { super.viewDidLoad()