System font renders as Times New Roman in certain contexts

Originator:hmask
Number:rdar://6153065 Date Originated:6/13/19
Status:Open Resolved:
Product:iOS Product Version:13.0
Classification: Reproducible:Yes
 
Product version: iOS 13.0 beta (17A5492t)

Summary:
When accessing the system font via UIFont.systemFont(ofSize:weight:), the font will often be rendered in Times New Roman instead of the expected SF font face. This does not occur when accessing the font directly by name instead, e.g. UIFont(name: "SFUIText-Regular", size: 16). 

Reproduction steps:
While we were unable to determine exact conditions to reproduce, we found the issue occurs primarily where we are accessing fonts declared as named static constants. Furthermore, we were also able to reproduce this in a playground by using the system accessor name to instantiate the font like this: UIFont(name: ".SFUI-Regular", size: 14)

Expected behavior:
The font returned is in the SF system typeface, or nil is returned if an improper font name is passed in.

Actual behavior:
The font returned is Times New Roman in a size that matches the size passed in.

Comments

Workaround doesn't work for NSAttributedString with options [.documentType: NSAttributedString.DocumentType.html] and css e.g. <style type="text/css">body { font-family: '\(font.fontName)', '\(font.familyName)'; font-size: \(font.pointSize)px; }</style>

We've isolated this behavior to instances of UIFont initialized using UIFont(name:size:) where name is the fontName property of a system font. This can be avoided by using the withSize() transform directly on the system font instead.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!