Command line to generate R2Font
This commit is contained in:
59
Sources/FontToolCore/FontToolContentGenerator.swift
Normal file
59
Sources/FontToolCore/FontToolContentGenerator.swift
Normal 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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user