Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
55 lines
1.4 KiB
Swift
55 lines
1.4 KiB
Swift
//
|
|
// FontName.swift
|
|
//
|
|
//
|
|
// Created by Thibaut Schmitt on 29/08/2022.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
// 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) -> String {
|
|
if isSwiftUI {
|
|
if isStatic {
|
|
return """
|
|
static let \(fontNameSanitize): ((_ size: CGFloat) -> Font) = { size in
|
|
Font.custom(FontName.\(fontNameSanitize).rawValue, size: size)
|
|
}
|
|
"""
|
|
}
|
|
return """
|
|
func \(fontNameSanitize)(withSize size: CGFloat) -> Font {
|
|
Font.custom(FontName.\(fontNameSanitize).rawValue, size: size)
|
|
}
|
|
"""
|
|
}
|
|
// UIKit
|
|
if isStatic {
|
|
return """
|
|
static let \(fontNameSanitize): ((_ size: CGFloat) -> UIFont) = { size in
|
|
UIFont(name: FontName.\(fontNameSanitize).rawValue, size: size)!
|
|
}
|
|
"""
|
|
}
|
|
return """
|
|
func \(fontNameSanitize)(withSize size: CGFloat) -> UIFont {
|
|
UIFont(name: FontName.\(fontNameSanitize).rawValue, size: size)!
|
|
}
|
|
"""
|
|
}
|
|
}
|