Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
Fixed a crash when opening certain fonts (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamusAranX authored Feb 1, 2022
1 parent cc8ef15 commit 7124bf8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Sources/FontBlaster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ private extension FontBlaster {
if let fontData = try? Data(contentsOf: fontFileURL) as CFData,
let dataProvider = CGDataProvider(data: fontData) {

let fontRef = CGFont(dataProvider)
guard let fontRef = CGFont(dataProvider) else {
printDebugMessage(message: "Failed to load font: '\(fontName)': fontRef is nil")
return
}

if CTFontManagerRegisterGraphicsFont(fontRef!, &fontError),
let postScriptName = fontRef?.postScriptName {
if CTFontManagerRegisterGraphicsFont(fontRef, &fontError),
let postScriptName = fontRef.postScriptName {
printDebugMessage(message: "Successfully loaded font: '\(postScriptName)'.")
loadedFonts.append(String(postScriptName))
} else if let fontError = fontError?.takeRetainedValue() {
Expand Down

0 comments on commit 7124bf8

Please sign in to comment.