mirror of
https://github.com/TextureGroup/Texture.git
synced 2026-04-07 19:17:39 +00:00
Bridge CTFontRef directly to UIFont when converting attributes on NSAttributedString (#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.
This commit is contained in:
@@ -68,16 +68,9 @@ NSDictionary *NSAttributedStringAttributesForCoreTextAttributes(NSDictionary *co
|
||||
|
||||
// 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]) {
|
||||
|
||||
Reference in New Issue
Block a user