-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
153 additions
and
15 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// QRCodeEyeShapeTeardrop.swift | ||
// | ||
// Copyright © 2024 Darren Ford. All rights reserved. | ||
// | ||
// MIT license | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | ||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or substantial | ||
// portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS | ||
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// | ||
|
||
import CoreGraphics | ||
import Foundation | ||
|
||
public extension QRCode.EyeShape { | ||
/// A 'Teardrop' style eye design | ||
@objc(QRCodeEyeShapeTeardrop) class Teardrop: NSObject, QRCodeEyeShapeGenerator { | ||
@objc public static let Name = "teardrop" | ||
@objc public static var Title: String { "Teardrop" } | ||
@objc public static func Create(_ settings: [String: Any]?) -> QRCodeEyeShapeGenerator { | ||
return QRCode.EyeShape.Teardrop() | ||
} | ||
|
||
@objc public func settings() -> [String: Any] { return [:] } | ||
@objc public func supportsSettingValue(forKey key: String) -> Bool { false } | ||
@objc public func setSettingValue(_ value: Any?, forKey key: String) -> Bool { false } | ||
|
||
/// Make a copy of the object | ||
@objc public func copyShape() -> QRCodeEyeShapeGenerator { | ||
return Self.Create(self.settings()) | ||
} | ||
|
||
public func eyePath() -> CGPath { | ||
let eyeShapePath = CGMutablePath() | ||
eyeShapePath.move(to: CGPoint(x: 45, y: 70)) | ||
eyeShapePath.curve(to: CGPoint(x: 20, y: 45), controlPoint1: CGPoint(x: 31.19, y: 70), controlPoint2: CGPoint(x: 20, y: 58.81)) | ||
eyeShapePath.line(to: CGPoint(x: 20, y: 20)) | ||
eyeShapePath.line(to: CGPoint(x: 45, y: 20)) | ||
eyeShapePath.curve(to: CGPoint(x: 70, y: 45), controlPoint1: CGPoint(x: 58.81, y: 20), controlPoint2: CGPoint(x: 70, y: 31.19)) | ||
eyeShapePath.curve(to: CGPoint(x: 45, y: 70), controlPoint1: CGPoint(x: 70, y: 58.81), controlPoint2: CGPoint(x: 58.81, y: 70)) | ||
eyeShapePath.close() | ||
eyeShapePath.move(to: CGPoint(x: 80, y: 45)) | ||
eyeShapePath.curve(to: CGPoint(x: 45, y: 10), controlPoint1: CGPoint(x: 80, y: 25.67), controlPoint2: CGPoint(x: 64.33, y: 10)) | ||
eyeShapePath.line(to: CGPoint(x: 10, y: 10)) | ||
eyeShapePath.line(to: CGPoint(x: 10, y: 45)) | ||
eyeShapePath.curve(to: CGPoint(x: 45, y: 80), controlPoint1: CGPoint(x: 10, y: 64.33), controlPoint2: CGPoint(x: 25.67, y: 80)) | ||
eyeShapePath.curve(to: CGPoint(x: 80, y: 45), controlPoint1: CGPoint(x: 64.33, y: 80), controlPoint2: CGPoint(x: 80, y: 64.33)) | ||
eyeShapePath.close() | ||
return eyeShapePath | ||
} | ||
|
||
public func eyeBackgroundPath() -> CGPath { | ||
let eyeBackgroundPath = CGMutablePath() | ||
eyeBackgroundPath.move(to: CGPoint(x: 90, y: 45)) | ||
eyeBackgroundPath.curve(to: CGPoint(x: 45, y: 0), controlPoint1: CGPoint(x: 90, y: 20.15), controlPoint2: CGPoint(x: 69.85, y: 0)) | ||
eyeBackgroundPath.line(to: CGPoint(x: 0, y: 0)) | ||
eyeBackgroundPath.line(to: CGPoint(x: 0, y: 45)) | ||
eyeBackgroundPath.curve(to: CGPoint(x: 45, y: 90), controlPoint1: CGPoint(x: 0, y: 69.85), controlPoint2: CGPoint(x: 20.15, y: 90)) | ||
eyeBackgroundPath.curve(to: CGPoint(x: 90, y: 45), controlPoint1: CGPoint(x: 69.85, y: 90), controlPoint2: CGPoint(x: 90, y: 69.85)) | ||
eyeBackgroundPath.close() | ||
return eyeBackgroundPath | ||
} | ||
|
||
private static let _defaultPupil = QRCode.PupilShape.Teardrop() | ||
public func defaultPupil() -> QRCodePupilShapeGenerator { Self._defaultPupil } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Sources/QRCode/styles/pupil/QRCodePupilShapeTeardrop.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// QRCodePupilShapeTeardrop.swift | ||
// | ||
// Copyright © 2024 Darren Ford. All rights reserved. | ||
// | ||
// MIT license | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | ||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or substantial | ||
// portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS | ||
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// | ||
|
||
import CoreGraphics | ||
import Foundation | ||
|
||
// MARK: - Pupil shape | ||
|
||
public extension QRCode.PupilShape { | ||
/// A 'Teardrop' style pupil design | ||
@objc(QRCodePupilShapeTeardrop) class Teardrop: NSObject, QRCodePupilShapeGenerator { | ||
@objc public static var Name: String { "teardrop" } | ||
/// The generator title | ||
@objc public static var Title: String { "Teardrop" } | ||
@objc public static func Create(_ settings: [String : Any]?) -> QRCodePupilShapeGenerator { | ||
Teardrop() | ||
} | ||
|
||
/// Make a copy of the object | ||
@objc public func copyShape() -> QRCodePupilShapeGenerator { Teardrop() } | ||
|
||
@objc public func settings() -> [String : Any] { [:] } | ||
@objc public func supportsSettingValue(forKey key: String) -> Bool { false } | ||
@objc public func setSettingValue(_ value: Any?, forKey key: String) -> Bool { false } | ||
|
||
/// The pupil centered in the 90x90 square | ||
@objc public func pupilPath() -> CGPath { | ||
let pupilPath = CGMutablePath() | ||
pupilPath.move(to: CGPoint(x: 60, y: 45)) | ||
pupilPath.curve(to: CGPoint(x: 45, y: 30), controlPoint1: CGPoint(x: 60, y: 36.72), controlPoint2: CGPoint(x: 53.28, y: 30)) | ||
pupilPath.line(to: CGPoint(x: 30, y: 30)) | ||
pupilPath.line(to: CGPoint(x: 30, y: 45)) | ||
pupilPath.curve(to: CGPoint(x: 45, y: 60), controlPoint1: CGPoint(x: 30, y: 53.28), controlPoint2: CGPoint(x: 36.72, y: 60)) | ||
pupilPath.curve(to: CGPoint(x: 60, y: 45), controlPoint1: CGPoint(x: 53.28, y: 60), controlPoint2: CGPoint(x: 60, y: 53.28)) | ||
pupilPath.close() | ||
return pupilPath | ||
} | ||
} | ||
} |