Skip to content

Commit d5de2a2

Browse files
author
Shannon Ma
committed
Text node to gracefully fail upon font failure
1 parent 15133fd commit d5de2a2

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

AsyncDisplayKit/Details/ASTextNodeCoreTextAdditions.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#import <CoreText/CTFont.h>
1212
#import <CoreText/CTStringAttributes.h>
1313

14+
#import "ASAssert.h"
15+
1416
#pragma mark - Public
1517
BOOL ASAttributeWithNameIsUnsupportedCoreTextAttribute(NSString *attributeName)
1618
{
@@ -65,8 +67,13 @@ BOOL ASAttributeWithNameIsUnsupportedCoreTextAttribute(NSString *attributeName)
6567
CTFontRef coreTextFont = (__bridge CTFontRef)coreTextValue;
6668
NSString *fontName = (__bridge_transfer NSString *)CTFontCopyPostScriptName(coreTextFont);
6769
CGFloat fontSize = CTFontGetSize(coreTextFont);
68-
69-
cleanAttributes[NSFontAttributeName] = [UIFont fontWithName:fontName size:fontSize];
70+
UIFont *font = [UIFont fontWithName:fontName size:fontSize];
71+
ASDisplayNodeCAssertNotNil(font, @"unable to load font %@ with size %f", fontName, fontSize);
72+
if (font == nil) {
73+
// Gracefully fail if we were unable to load the font.
74+
font = [UIFont systemFontOfSize:fontSize];
75+
}
76+
cleanAttributes[NSFontAttributeName] = font;
7077
}
7178
// kCTKernAttributeName -> NSKernAttributeName
7279
else if ([coreTextKey isEqualToString:(NSString *)kCTKernAttributeName]) {

0 commit comments

Comments
 (0)