Fix plist font file name and fix all tests
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
This commit is contained in:
@ -43,22 +43,31 @@ struct Fonts: ParsableCommand {
|
||||
let fontsToGenerate = FontFileParser.parse(options.inputFile)
|
||||
|
||||
// Get real font names
|
||||
let inputFolder = URL(fileURLWithPath: options.inputFile).deletingLastPathComponent().relativePath
|
||||
let fontsNames = FontsToolHelper.getFontPostScriptName(for: fontsToGenerate,
|
||||
inputFolder: inputFolder)
|
||||
let inputFolder = URL(fileURLWithPath: options.inputFile)
|
||||
.deletingLastPathComponent()
|
||||
.relativePath
|
||||
|
||||
let fontsNames = FontsToolHelper.getFontPostScriptName(
|
||||
for: fontsToGenerate,
|
||||
inputFolder: inputFolder
|
||||
)
|
||||
|
||||
// Generate extension
|
||||
FontExtensionGenerator.writeExtensionFile(fontsNames: fontsNames,
|
||||
staticVar: options.staticMembers,
|
||||
extensionName: options.extensionName,
|
||||
extensionFilePath: options.extensionFilePath,
|
||||
isSwiftUI: true)
|
||||
FontExtensionGenerator.writeExtensionFile(
|
||||
fontsNames: fontsNames,
|
||||
staticVar: options.staticMembers,
|
||||
extensionName: options.extensionName,
|
||||
extensionFilePath: options.extensionFilePath,
|
||||
isSwiftUI: true
|
||||
)
|
||||
|
||||
FontExtensionGenerator.writeExtensionFile(fontsNames: fontsNames,
|
||||
staticVar: options.staticMembers,
|
||||
extensionName: options.extensionNameUIKit,
|
||||
extensionFilePath: options.extensionFilePathUIKit,
|
||||
isSwiftUI: false)
|
||||
FontExtensionGenerator.writeExtensionFile(
|
||||
fontsNames: fontsNames,
|
||||
staticVar: options.staticMembers,
|
||||
extensionName: options.extensionNameUIKit,
|
||||
extensionFilePath: options.extensionFilePathUIKit,
|
||||
isSwiftUI: false
|
||||
)
|
||||
|
||||
print("Info.plist has been updated with:")
|
||||
print("\(FontPlistGenerator.generatePlistUIAppsFontContent(for: fontsNames, infoPlistPaths: options.infoPlistPaths))")
|
||||
|
@ -57,17 +57,26 @@ class FontsToolHelper {
|
||||
return fontsFileNames
|
||||
}
|
||||
|
||||
private static func getFontName(atPath path: String) -> String {
|
||||
private static func getFontName(atPath path: String) -> FontName {
|
||||
//print("fc-scan --format %{postscriptname} \(path)")
|
||||
// Get real font name
|
||||
let task = Shell.shell(["fc-scan", "--format", "%{postscriptname}", path])
|
||||
|
||||
guard let fontName = task.output, task.terminationStatus == 0 else {
|
||||
guard let postscriptName = task.output, task.terminationStatus == 0 else {
|
||||
let error = FontsToolError.fcScan(path, task.terminationStatus, task.output)
|
||||
print(error.description)
|
||||
Fonts.exit(withError: error)
|
||||
}
|
||||
|
||||
return fontName
|
||||
|
||||
let pathURL = URL(fileURLWithPath: path)
|
||||
let filename = pathURL
|
||||
.deletingPathExtension()
|
||||
.lastPathComponent
|
||||
|
||||
return FontName(
|
||||
postscriptName: postscriptName,
|
||||
filename: filename,
|
||||
fileExtension: pathURL.pathExtension
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -26,16 +26,16 @@ class FontPlistGenerator {
|
||||
|
||||
// Fill array with fonts
|
||||
fontsToAddToPlist
|
||||
.forEach {
|
||||
.forEach { fontName in
|
||||
Shell.shell(launchPath: "/usr/libexec/PlistBuddy",
|
||||
["-c", "add :UIAppFonts: string \($0)", infoPlist])
|
||||
["-c", "add :UIAppFonts: string \(fontName.filename).\(fontName.fileExtension)", infoPlist])
|
||||
}
|
||||
}
|
||||
|
||||
var plistData = "<key>UIAppFonts</key>\n\t<array>\n"
|
||||
fontsToAddToPlist
|
||||
.forEach {
|
||||
plistData += "\t\t<string>\($0)</string>\n"
|
||||
.forEach { fontName in
|
||||
plistData += "\t\t<string>\(fontName.filename).\(fontName.fileExtension)</string>\n"
|
||||
}
|
||||
plistData += "\t</array>"
|
||||
|
||||
|
@ -10,18 +10,18 @@ import ToolCore
|
||||
|
||||
class FontExtensionGenerator {
|
||||
|
||||
private static func getFontNameEnum(fontsNames: [String]) -> String {
|
||||
private static func getFontNameEnum(fontsNames: [FontName]) -> String {
|
||||
var enumDefinition = " enum FontName: String {\n"
|
||||
|
||||
fontsNames.forEach {
|
||||
enumDefinition += " case \($0.fontNameSanitize) = \"\($0)\"\n"
|
||||
enumDefinition += " case \($0.fontNameSanitize) = \"\($0.postscriptName)\"\n"
|
||||
}
|
||||
enumDefinition += " }\n"
|
||||
|
||||
return enumDefinition
|
||||
}
|
||||
|
||||
static func writeExtensionFile(fontsNames: [String],
|
||||
static func writeExtensionFile(fontsNames: [FontName],
|
||||
staticVar: Bool,
|
||||
extensionName: String,
|
||||
extensionFilePath: String,
|
||||
@ -43,7 +43,7 @@ class FontExtensionGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
static func getExtensionContent(fontsNames: [String],
|
||||
static func getExtensionContent(fontsNames: [FontName],
|
||||
staticVar: Bool,
|
||||
extensionName: String,
|
||||
isSwiftUI: Bool) -> String {
|
||||
|
@ -7,11 +7,18 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
typealias FontName = String
|
||||
//typealias FontName = String
|
||||
|
||||
struct FontName: Hashable {
|
||||
|
||||
let postscriptName: String
|
||||
let filename: String
|
||||
let fileExtension: String
|
||||
}
|
||||
|
||||
extension FontName {
|
||||
var fontNameSanitize: String {
|
||||
self.removeCharacters(from: "[]+-_")
|
||||
postscriptName.removeCharacters(from: "[]+-_")
|
||||
}
|
||||
|
||||
func getProperty(isStatic: Bool, isSwiftUI: Bool) -> String {
|
||||
|
@ -7,4 +7,4 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public let ResgenSwiftVersion = "1.2"
|
||||
public let ResgenSwiftVersion = "2.1.0"
|
||||
|
Reference in New Issue
Block a user