diff --git a/Common/Controllers/Preferences.swift b/Common/Controllers/Preferences.swift index 810244d..3408a29 100644 --- a/Common/Controllers/Preferences.swift +++ b/Common/Controllers/Preferences.swift @@ -35,11 +35,14 @@ public enum KeyboardButtonStyle: Int { override init() { super.init() + // TODO: Preferences really shouldn’t be responsible for loading fonts! + FontMetrics.loadFonts() + let defaultFontName: String if #available(iOS 13.0, macOS 10.15, *) { defaultFontName = "SF Mono" } else { - defaultFontName = "Fira Code" + defaultFontName = "Menlo" } let defaults: [String: Any] = [ "fontName": defaultFontName, diff --git a/Common/VT100/FontMetrics.swift b/Common/VT100/FontMetrics.swift index e7adf99..3aa350d 100644 --- a/Common/VT100/FontMetrics.swift +++ b/Common/VT100/FontMetrics.swift @@ -6,6 +6,7 @@ // import Foundation +import CoreGraphics import CoreText @objc public class FontMetrics: NSObject { @@ -19,6 +20,23 @@ import CoreText @objc public let boundingBox: CGSize + class func loadFonts() { + // Runtime load all fonts we’re interested in. + // TODO: This should only load the fonts the user wants. + guard let listing = try? FileManager.default.contentsOfDirectory(at: Bundle.main.resourceURL!, includingPropertiesForKeys: nil, options: [ .skipsSubdirectoryDescendants, .skipsHiddenFiles ]) else { + return + } + let fonts = listing.filter { item in item.pathExtension == "ttf" || item.pathExtension == "otf" } + if fonts.count > 0 { + var cfErrorsWrapper: Unmanaged? = nil + CTFontManagerRegisterFontsForURLs(fonts as CFArray, .process, &cfErrorsWrapper) + if let cfErrors = cfErrorsWrapper?.takeUnretainedValue(), + let errors = cfErrors as? [NSError] { + NSLog("%li error(s) loading fonts: %@", errors.count, errors) + } + } + } + init(regularFont: Font, boldFont: Font) { self.regularFont = regularFont self.boldFont = boldFont diff --git a/Makefile b/Makefile index f459b1e..c664d62 100644 --- a/Makefile +++ b/Makefile @@ -23,3 +23,7 @@ SUBPROJECTS = prefs include $(THEOS_MAKE_PATH)/aggregate.mk endif + +all package install:: +# TODO: This should be possible natively in Theos! + +$(MAKE) -C Fonts $@ THEOS_PROJECT_DIR=$(THEOS_PROJECT_DIR)/Fonts diff --git a/iOS/Supporting Files/Info.plist b/iOS/Supporting Files/Info.plist index 471d74f..0f70910 100644 --- a/iOS/Supporting Files/Info.plist +++ b/iOS/Supporting Files/Info.plist @@ -22,27 +22,6 @@ $(CURRENT_PROJECT_VERSION) LSRequiresIPhoneOS - UIAppFonts - - AnonymousPro-Bold.ttf - AnonymousPro-BoldItalic.ttf - AnonymousPro-Italic.ttf - AnonymousPro-Regular.ttf - FiraCode-Bold.otf - FiraCode-Retina.otf - Hack-Bold.ttf - Hack-Regular.ttf - JetBrainsMono-Bold.ttf - JetBrainsMono-BoldItalic.ttf - JetBrainsMono-Italic.ttf - JetBrainsMono-Regular.ttf - SourceCodePro-Bold.otf - SourceCodePro-Regular.otf - UbuntuMono-Bold.ttf - UbuntuMono-BoldItalic.ttf - UbuntuMono-Italic.ttf - UbuntuMono-Regular.ttf - UIApplicationSceneManifest UIApplicationSupportsMultipleScenes