Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
60 lines
1.7 KiB
Swift
60 lines
1.7 KiB
Swift
//
|
|
// FontToolContentGenerator.swift
|
|
//
|
|
//
|
|
// Created by Thibaut Schmitt on 13/12/2021.
|
|
//
|
|
|
|
import Foundation
|
|
import ToolCore
|
|
|
|
class FontToolContentGenerator {
|
|
|
|
static func getExtensionHeader(fontsNames: [String]) -> String {
|
|
"""
|
|
// Generated by ResgenSwift.FontToolCore \(ResgenSwiftVersion)
|
|
|
|
import UIKit
|
|
|
|
"""
|
|
}
|
|
|
|
static func getFontNameEnum(fontsNames: [String]) -> String {
|
|
var enumDefinition = "\tenum FontName: String {\n"
|
|
|
|
fontsNames.forEach {
|
|
//debugPrint("Name: \($0.removeCharacters(from: "[]+-_"))")
|
|
enumDefinition += "\t\tcase \($0.removeCharacters(from: "[]+-_")) = \"\($0)\"\n"
|
|
}
|
|
enumDefinition += "\t}\n"
|
|
|
|
return enumDefinition
|
|
}
|
|
|
|
static func getFontMethods(fontsNames: [String], isUIFontExtension: Bool) -> String {
|
|
var methods = "\t// MARK: - Getter\n"
|
|
|
|
fontsNames
|
|
.unique()
|
|
.forEach {
|
|
let fontNameSanitize = $0.removeCharacters(from: "[]+-_")
|
|
|
|
if isUIFontExtension {
|
|
methods += """
|
|
\n\tstatic let \(fontNameSanitize): ((_ size: CGFloat) -> UIFont) = { size in
|
|
\tUIFont(name: FontName.\(fontNameSanitize).rawValue, size: size)!
|
|
\t}\n
|
|
"""
|
|
} else {
|
|
methods += """
|
|
\n\tfunc \(fontNameSanitize)(withSize size: CGFloat) -> UIFont {
|
|
\tUIFont(name: FontName.\(fontNameSanitize).rawValue, size: size)!
|
|
\t}\n
|
|
"""
|
|
}
|
|
}
|
|
|
|
return methods
|
|
}
|
|
}
|