Skip to content

Commit

Permalink
Merge pull request #145 from pvieito/master
Browse files Browse the repository at this point in the history
Added Mac Catalyst support
  • Loading branch information
yeahdongcn authored Sep 25, 2021
2 parents 86d8b1a + cb7cd1f commit 241de72
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions Source/RSCode128Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Source/RSCode39Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions Source/RSCode39Mod43Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Source/RSCode93Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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*"

Expand Down
1 change: 1 addition & 0 deletions Source/RSCodeDataMatrixGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import UIKit

@available(macCatalyst 14.0, *)
class RSCodeDataMatrixGenerator: RSAbstractCodeGenerator {

}
8 changes: 5 additions & 3 deletions Source/RSCodeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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}
Expand Down Expand Up @@ -55,6 +56,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
Expand Down Expand Up @@ -112,7 +114,7 @@ open class RSAbstractCodeGenerator : RSCodeGenerator {
height = Int(targetSize.height / targetSize.width * CGFloat(width))
}
let size = CGSize(width: CGFloat(width), height: CGFloat(height))
UIGraphicsBeginImageContextWithOptions(size, false, 0)
UIGraphicsBeginImageContextWithOptions(size, false, 1)
if let context = UIGraphicsGetCurrentContext() {
context.setShouldAntialias(false)

Expand Down Expand Up @@ -247,7 +249,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
Expand Down Expand Up @@ -298,7 +300,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))
Expand Down
2 changes: 2 additions & 0 deletions Source/RSCodeReaderViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
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()
Expand Down
5 changes: 5 additions & 0 deletions Source/RSEANGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -100,25 +101,29 @@ 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
return super.isValid(contents) && contents.substring(0, length: 3) == "978"
}
}

@available(macCatalyst 14.0, *)
class RSISSN13Generator: RSEAN13Generator {
override func isValid(_ contents: String) -> Bool {
// http://www.appsbarcode.com/ISSN.php
Expand Down
1 change: 1 addition & 0 deletions Source/RSExtendedCode39Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
1 change: 1 addition & 0 deletions Source/RSITF14Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Source/RSITFGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions Source/RSUPCEGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions Source/RSUnifiedCodeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import UIKit
import AVFoundation

@available(macCatalyst 14.0, *)
open class RSUnifiedCodeGenerator: RSCodeGenerator {

open var isBuiltInCode128GeneratorSelected = false
Expand Down Expand Up @@ -89,4 +90,5 @@ open class RSUnifiedCodeGenerator: RSCodeGenerator {
}
}

@available(macCatalyst 14.0, *)
let UnifiedCodeGeneratorSharedInstance = RSUnifiedCodeGenerator()
5 changes: 5 additions & 0 deletions Source/RSUnifiedCodeValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation
import AVFoundation

@available(macCatalyst 14.0, *)
open class RSUnifiedCodeValidator {
open class var shared: RSUnifiedCodeValidator {
return UnifiedCodeValidatorSharedInstance
Expand Down Expand Up @@ -37,8 +38,10 @@ open class RSUnifiedCodeValidator {
codeGenerator = RSCode93Generator()
case AVMetadataObject.ObjectType.code128.rawValue:
codeGenerator = RSCode128Generator()
/** TODO: Uncomment this once DataMatrix generator is implemented.
case AVMetadataObject.ObjectType.dataMatrix.rawValue:
codeGenerator = RSCodeDataMatrixGenerator()
*/
case RSBarcodesTypeISBN13Code:
codeGenerator = RSISBN13Generator()
case RSBarcodesTypeISSN13Code:
Expand All @@ -52,4 +55,6 @@ open class RSUnifiedCodeValidator {
return codeGenerator!.isValid(contents)
}
}

@available(macCatalyst 14.0, *)
let UnifiedCodeValidatorSharedInstance = RSUnifiedCodeValidator()

0 comments on commit 241de72

Please sign in to comment.