Thibaut Schmitt 279f13dbd5
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
Add SwiftLint HARD rules
2025-04-30 17:05:02 +02:00

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)!
}
"""
}
}