Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Under iOS13 (Beta 7) TimesNewRomanPSMT will be used instead of SFUI #1168

Open
jingx23 opened this issue Aug 21, 2019 · 15 comments

Comments

@jingx23
Copy link

commented Aug 21, 2019

If you set DTDefaultFontFamily and DTDefaultFontName to iOS13 system font (family: .AppleSystemUIFont name: .SFUI-Regular) e.g. in initWithHTMLData:

NSAttributedString *attributedString = [[NSAttributedString alloc] initWithHTMLData:data options:@{ DTUseiOS6Attributes: @YES, DTDefaultFontFamily: [UIFont systemFontOfSize:[UIFont systemFontSize]].familyName, DTDefaultFontName : [UIFont systemFontOfSize:[UIFont systemFontSize]].fontName, DTDefaultFontSize : @([UIFont systemFontSize])} documentAttributes:nil];

you will get the following message:

CoreText performance note: Client called CTFontCreateWithName() using name ".SFUI-Regular" and got font with PostScript name "TimesNewRomanPSMT". For best performance, only use PostScript names when calling this API.

@jingx23 jingx23 changed the title Under iOS13 TimesNewRomanPSMT will be used instead of SFUI Under iOS13 (Beta 7) TimesNewRomanPSMT will be used instead of SFUI Aug 21, 2019

@yichengchen

This comment has been minimized.

Copy link

commented Aug 28, 2019

same problem here

@odrobnik

This comment has been minimized.

Copy link
Collaborator

commented Aug 28, 2019

What is the correct post script font name for San Francisco? This is the one you should use.

@yichengchen

This comment has been minimized.

Copy link

commented Aug 28, 2019

if we use

CTFontCreateWithName(UIFont.systemFont(ofSize: 10).fontName as CFString, 10, nil)

it log above error message and get error TimesNewRoman. When changing to follow method

 CTFontCreateWithFontDescriptor(UIFont.systemFont(ofSize: 10).fontDescriptor, 10, nil)

then we can return correct result. is there way to use fontDescriptor?

a bug feedback is sent to apple.

@yichengchen

This comment has been minimized.

Copy link

commented Aug 30, 2019

@odrobnik The following is the feedback from apple. Maybe we should provide a way to pass UIFont directly or fontDescriptor as DTDefaultFont?

because we are adopting dynamic font, it's not suitable to hardcode the font name

This issue behaves as intended.

As mentioned in numerous WWDC sessions, dot-prefixed font names are not to be directly used.

I would also note that UIFont and CTFont are toll-free bridged, so they can be used interchangeably with casts.

Please update your feedback report to let us know if this is still an issue for you.
@odrobnik

This comment has been minimized.

Copy link
Collaborator

commented Aug 30, 2019

Why don't you specify the proper family name for San Francisco?

@jcaccavale-mdsol

This comment has been minimized.

Copy link

commented Aug 30, 2019

I used the PostScript Names SFProDisplay-Regular, SFProDisplay-Semibold, etc, which resolved my issue.

@yichengchen

This comment has been minimized.

Copy link

commented Aug 30, 2019

Why don't you specify the proper family name for San Francisco?

because we want to follow dynamic font or Dynamic Type. setting such as UIFont.preferredFont(forTextStyle: .subheadline). it may become bold or other type due to system settings.

it's ok for us to manually maintain an mapping table from ".SFUI-Regular"->"SFProDisplay-Regular" and Semibold etc and for different languages. But it just no pretty enough.

@fruitcoder

This comment has been minimized.

Copy link

commented Sep 3, 2019

I have the same problem as @yichengchen with supporting dynamic fonts. Is providing the postscript name also working for < iOS 13?

@yichengchen

This comment has been minimized.

Copy link

commented Sep 9, 2019

I have the same problem as @yichengchen with supporting dynamic fonts. Is providing the postscript name also working for < iOS 13?

Have you come out with any solutions? I found that font would be different default font on different language. E.g: the PingFang in Chinese. also i can't find the postscript name of San Francisco

@jcaccavale-mdsol I tried CTFontCreateWithName("SFProDisplay-Semibold" as CFString, 20, nil) it return me

 <UICTFont: 0x7fdca6e0d510> font-family: "Helvetica"; font-weight: normal; font-style: normal;

look likes any wrong font name not start with a dot would return Helvetica, it's this really solve your problem?

@yichengchen

This comment has been minimized.

Copy link

commented Sep 9, 2019

I found we set .AppleSystemUIFont as DTDefaultFontName can avoid the above warning and get correct, but in DTHTMLElement.m line 148 UIFont *uiFont = [UIFont fontWithCTFont:font]; it return time's new roman back……

@fruitcoder

This comment has been minimized.

Copy link

commented Sep 9, 2019

Yeah I thought the post script names would solve the issue but we also noticed that it's actually Helvetica that's being rendered... For now we manually copied the font in our bundle and reference it by our custom name :(

@odrobnik

This comment has been minimized.

Copy link
Collaborator

commented Sep 10, 2019

Well, the problem is that we have no API that would allow you to set the font instance itself, but only to set a name. In DTHTMLAttributedStringBuilder.m:229 the _defaultFontDescriptor is initialized with the font name only. Then while parsing it keeps attaching updated versions of this font descriptor to tags.

What you need instead is to be able to provide a default font descriptor and make sure that the extra attributes which dynamic text adds to that are also preserved. Then to use CTFontCreateWithFontDescriptor to get the font. There are two kinds of font creation, a fast or a slow one and except for some exceptions, like Chinese characters. But the options of default font or default font family omit these extra parameters that dynamic text adds.

If somebody were to sponsor the creation of this functionality, I'd be happy to add it. You can email me at oliver@cocoanetics.com to inquire.

@odrobnik

This comment has been minimized.

Copy link
Collaborator

commented Sep 10, 2019

PS: Of course you can also implement this functionality yourself and provide a PR.

@phamanhvan24

This comment has been minimized.

Copy link

commented Sep 11, 2019

iOS 13 not support UIWebView

@odrobnik

This comment has been minimized.

Copy link
Collaborator

commented Sep 11, 2019

@phamanhvan24 please see #1169 - already addressed by a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.