Skip to content

Commit

Permalink
Fix iOS 13 System Font Lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
b3ll committed Jun 18, 2019
1 parent 71d6238 commit 140af43
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions Source/TextKit/ASTextKitCoreTextAdditions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,22 @@ BOOL ASAttributeWithNameIsUnsupportedCoreTextAttribute(NSString *attributeName)
NSShadowAttributeName
NSBackgroundColorAttributeName
*/

// kCTFontAttributeName -> NSFontAttributeName
if ([coreTextKey isEqualToString:(NSString *)kCTFontAttributeName]) {
CTFontRef coreTextFont = (__bridge CTFontRef)coreTextValue;
NSString *fontName = (__bridge_transfer NSString *)CTFontCopyPostScriptName(coreTextFont);
CGFloat fontSize = CTFontGetSize(coreTextFont);
UIFont *font = [UIFont fontWithName:fontName size:fontSize];
ASDisplayNodeCAssertNotNil(font, @"unable to load font %@ with size %f", fontName, fontSize);
if (font == nil) {
// Gracefully fail if we were unable to load the font.
font = [UIFont systemFontOfSize:fontSize];
UIFont *font = nil;
if ([coreTextValue isKindOfClass:[UIFont class]]) {
font = (UIFont *)coreTextValue;
} else {
CTFontRef coreTextFont = (__bridge CTFontRef)coreTextValue;
NSString *fontName = (__bridge_transfer NSString *)CTFontCopyPostScriptName(coreTextFont);
CGFloat fontSize = CTFontGetSize(coreTextFont);
[UIFont fontWithName:fontName size:fontSize];
ASDisplayNodeCAssertNotNil(font, @"unable to load font %@ with size %f", fontName, fontSize);
if (font == nil) {
// Gracefully fail if we were unable to load the font.
font = [UIFont systemFontOfSize:fontSize];
}
}
cleanAttributes[NSFontAttributeName] = font;
}
Expand Down

0 comments on commit 140af43

Please sign in to comment.