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

This, of course, also affects SKLabelNodes - setting the fontName seems not to have any effect except to make the SKLabelNode font appear as Times New Roman.

Same problem here. Simple way to reproduce

See my rant on twitter: https://twitter.com/altimac/status/1176788944886915072

By hugele.aurelien at Sept. 30, 2019, 1:37 p.m. (reply...)

serbuk

I have the same problem with NSAttributedString being set to UILabel.attributedText (iOS 13.1)

By serg.bukharin at Sept. 27, 2019, 6:25 a.m. (reply...)

Following up with the comment of tfonfara, we had that same problem. By investigating more we could conclude the exact details of the problem:

Product version: iOS 13.0 GM

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 occur for UITextView that render HTML as an attributed text.

Setting a CSS inside the HTML with the font family from the system font does not work either. It preserves the information about the font size, but not the family name. For all previous iOS versions (< iOS 13) is working as expected and the rendered font is San Francisco.

Failing case

1. Create a textView

1.1.Optional (set a default system font)

2.Set as its text a NSAttributedString with HTML document type.

3.Check the font family. (This is Times New Roman)

Overriding font after setting text:

1. Create a textView.

2. Set as its text a NSAttributedString with HTML document type.

3. Set UITextView's font to be UIFont.systemFont(ofSize:)

4. Check the font family. (This is .AppleSystemUIFont)


It looks like setting an attributed text is causing the font to be changed to Times New Roman when it does not include a NSAttributedString.Key.font. If the attributed text includes this key, the given font is used when rendering the text.

Expected Result: The font returned is in the SF system typeface, or the correct default type font (Same as for any UILabel).

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

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!