Skip to content

Commit

Permalink
Bridge CTFontRef directly to UIFont when converting attributes on NSA…
Browse files Browse the repository at this point in the history
…ttributedString (#1579)

In iOS13, there is an issue with the font returned from "-[UIFontj fontWithName:size:]". When asking for "SFUI-Regular" returns "Times New Roman" font.

It isn't clear why we were trying to create a new font instance when CTFontRef toll-free bridges to UIFont. This appears to pass tests both internally at Pinterest and Texture so I feel like the change is pretty safe and should also solve the iOS 13 regression users are experiencing.
  • Loading branch information
rahul-malik authored and nguyenhuy committed Jul 11, 2019
1 parent 901f4dd commit 6176aa4
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions Source/TextKit/ASTextKitCoreTextAdditions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,9 @@ BOOL ASAttributeWithNameIsUnsupportedCoreTextAttribute(NSString *attributeName)

// kCTFontAttributeName -> NSFontAttributeName
if ([coreTextKey isEqualToString:(NSString *)kCTFontAttributeName]) {
// Its reference type, CTFontRef, is toll-free bridged with UIFont in iOS and NSFont in OS X
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];
}
cleanAttributes[NSFontAttributeName] = font;
cleanAttributes[NSFontAttributeName] = (__bridge UIFont *)coreTextFont;
}
// kCTKernAttributeName -> NSKernAttributeName
else if ([coreTextKey isEqualToString:(NSString *)kCTKernAttributeName]) {
Expand Down

0 comments on commit 6176aa4

Please sign in to comment.