Command line to generate R2Font

This commit is contained in:
2021-12-13 13:55:55 +01:00
parent e159b2e752
commit ce3cac90be
34 changed files with 369 additions and 422 deletions

View File

@ -0,0 +1,59 @@
//
// FontToolContentGenerator.swift
//
//
// Created by Thibaut Schmitt on 13/12/2021.
//
import Foundation
class FontToolContentGenerator {
static func getExtensionHeader(fontsNames: [String]) -> String {
"""
// Generated from FontToolCore
// \(fontsNames.joined(separator: " "))
import UIKit
"""
}
static func getFontNameEnum(fontsNames: [String]) -> String {
var enumDefinition = "\tenum FontName: String {"
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
}
}