Open aaronrogers opened 5 years ago
Oddly enough, it looks like with macOS there's yet another Awesome.bundle
in fontBundle
. Changing the load
code to the following appears to work on iOS and macOS.
static func load(type: AwesomeFont, from bundle: Bundle? = nil) {
guard !Font.fontNames(forFamilyName: type.description).contains(type.memberName) else {
return
}
let fontBundle: Bundle!
if bundle == nil {
fontBundle = Bundle(for: Fonts.self)
} else {
fontBundle = bundle
}
var awesomeBundle = fontBundle!
while true {
guard
let url = awesomeBundle.url(forResource: "Awesome", withExtension: "bundle"),
let subBundle = Bundle(url: url)
else {
break
}
awesomeBundle = subBundle
}
let fontURL = awesomeBundle.url(forResource: type.file, withExtension: "ttf")
guard let url = fontURL else {
return
}
let data = try! Data(contentsOf: url as URL)
let provider = CGDataProvider(data: data as CFData)
let font = CGFont(provider!)
var error: Unmanaged<CFError>?
if CTFontManagerRegisterGraphicsFont(font!, &error) == false {
let errorDescription: CFString = CFErrorCopyDescription(error!.takeUnretainedValue())
let nsError = error!.takeUnretainedValue() as AnyObject as! NSError
NSException(name: NSExceptionName.internalInconsistencyException, reason: errorDescription as String, userInfo: [NSUnderlyingErrorKey: nsError]).raise()
}
}
In iOS everything works great with using cocoapods, but when using Awesome in a mac app I get the exception
Is there a step that I'm missing?
In
Fonts.swift
the following code returnsnil
.