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
15 changed files
with
133 additions
and
106 deletions.
There are no files selected for viewing
File renamed without changes.
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,23 @@ | ||
// | ||
// AssetScale.swift | ||
// Iconizer | ||
// https://github.com/raphaelhanneken/iconizer | ||
// | ||
|
||
import Foundation | ||
|
||
// swiftlint:disable identifier_name | ||
enum AssetScale: String { | ||
case x1 = "1x" | ||
case x2 = "2x" | ||
case x3 = "3x" | ||
|
||
var value: Int { | ||
switch self { | ||
case .x1: return 1 | ||
case .x2: return 2 | ||
case .x3: return 3 | ||
} | ||
} | ||
} | ||
// swiftlint:enable identifier_name |
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,55 @@ | ||
// | ||
// AssetSize.swift | ||
// Iconizer | ||
// https://github.com/raphaelhanneken/iconizer | ||
// | ||
|
||
import Foundation | ||
|
||
struct AssetSize { | ||
let string: String | ||
let width: Float | ||
let height: Float | ||
|
||
/** Parse string like 50x45 | ||
* or 50.5x25.5 | ||
* ! 50.5.5x60.5.6 will not work | ||
*/ | ||
init(size: String) throws { | ||
let regex = "^([\\d\\.]+)x([\\d\\.]+)$" | ||
if let expression = try? NSRegularExpression(pattern: regex) { | ||
let range = NSRange(size.startIndex..<size.endIndex, in: size) | ||
|
||
var widthResult: Float? | ||
var heightResult: Float? | ||
|
||
expression.enumerateMatches(in: size, options: [], range: range) { (match, _, stop) in | ||
defer { stop.pointee = true } | ||
guard let match = match else { return } | ||
|
||
if match.numberOfRanges == 3, | ||
let wRange = Range(match.range(at: 1), in: size), | ||
let hRange = Range(match.range(at: 2), in: size) { | ||
|
||
widthResult = Float(size[wRange]) | ||
heightResult = Float(size[hRange]) | ||
} | ||
} | ||
|
||
if let width = widthResult, let height = heightResult { | ||
self.string = size | ||
self.width = width | ||
self.height = height | ||
return | ||
} | ||
} | ||
|
||
throw AssetCatalogError.invalidFormat(format: .size) | ||
} | ||
|
||
func multiply(_ scale: AssetScale) -> NSSize { | ||
let width = Int(self.width * Float(scale.value)) | ||
let height = Int(self.height * Float(scale.value)) | ||
return NSSize(width: width, height: height) | ||
} | ||
} |
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
File renamed without changes.
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
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
Oops, something went wrong.