Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
63 lines
1.7 KiB
Swift
63 lines
1.7 KiB
Swift
//
|
|
// FontName.swift
|
|
//
|
|
//
|
|
// Created by Thibaut Schmitt on 29/08/2022.
|
|
//
|
|
|
|
import Foundation
|
|
import ToolCore
|
|
|
|
// swiftlint:disable no_grouping_extension
|
|
|
|
struct FontName: Hashable {
|
|
|
|
let postscriptName: String
|
|
let filename: String
|
|
let fileExtension: String
|
|
}
|
|
|
|
extension FontName {
|
|
|
|
var fontNameSanitize: String {
|
|
postscriptName.removeCharacters(from: "[]+-_")
|
|
}
|
|
|
|
func getProperty(
|
|
isStatic: Bool,
|
|
isSwiftUI: Bool,
|
|
visibility: ExtensionVisibility
|
|
) -> String {
|
|
switch (isSwiftUI, isStatic) {
|
|
case (true, true):
|
|
// SwiftUI, Static => let
|
|
"""
|
|
\(visibility) static let \(fontNameSanitize): ((_ size: CGFloat) -> Font) = { size in
|
|
Font.custom(FontName.\(fontNameSanitize).rawValue, size: size)
|
|
}
|
|
"""
|
|
case (true, false):
|
|
// SwiftUI, Not Static => func
|
|
"""
|
|
\(visibility) func \(fontNameSanitize)(withSize size: CGFloat) -> Font {
|
|
Font.custom(FontName.\(fontNameSanitize).rawValue, size: size)
|
|
}
|
|
"""
|
|
case (false, true):
|
|
// UIKit, Static => let
|
|
"""
|
|
\(visibility) static let \(fontNameSanitize): ((_ size: CGFloat) -> UIFont) = { size in
|
|
UIFont(name: FontName.\(fontNameSanitize).rawValue, size: size)!
|
|
}
|
|
"""
|
|
case (false, false):
|
|
// UIKit, Not Static => func
|
|
"""
|
|
\(visibility) func \(fontNameSanitize)(withSize size: CGFloat) -> UIFont {
|
|
UIFont(name: FontName.\(fontNameSanitize).rawValue, size: size)!
|
|
}
|
|
"""
|
|
}
|
|
}
|
|
}
|