Bug 132030

Summary: [OS X] Make checking if a font is the system font more robust
Product: WebKit Reporter: Myles C. Maxfield <mmaxfield>
Component: New BugsAssignee: Myles C. Maxfield <mmaxfield>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, dino, jonlee, simon.fraser, thorton
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 132070    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch
none
Patch darin: review-

Description Myles C. Maxfield 2014-04-22 17:01:38 PDT
[OS X] Make checking if a font is the system font more robust
Comment 1 Myles C. Maxfield 2014-04-22 17:07:08 PDT
Created attachment 229925 [details]
Patch
Comment 2 Dean Jackson 2014-04-22 17:36:12 PDT
Comment on attachment 229925 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=229925&action=review

> Source/WebCore/platform/graphics/mac/FontMac.mm:40
> +extern "C" bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);

Do we want to wrap this in a #if __MAC_MIN thing as well, to make it clear we only use it on 1090+?

> Source/WebCore/platform/graphics/mac/FontMac.mm:545
> +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1090

So this existed on 10.9 as well?
Comment 3 Tim Horton 2014-04-22 17:45:54 PDT
Comment on attachment 229925 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=229925&action=review

> Source/WebCore/platform/graphics/mac/FontMac.mm:37
> +#if defined(__has_include) && __has_include(<CoreText/CTFontDescriptorPriv.h>)

we don't need the defined() part

> Source/WebCore/platform/graphics/mac/FontMac.mm:548
> +    return firstFamily().startsWith('.');

does this actually make sense on any platform? were there dot-prefixed fonts in 10.8?
Comment 4 Myles C. Maxfield 2014-04-22 21:07:23 PDT
Comment on attachment 229925 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=229925&action=review

>> Source/WebCore/platform/graphics/mac/FontMac.mm:37
>> +#if defined(__has_include) && __has_include(<CoreText/CTFontDescriptorPriv.h>)
> 
> we don't need the defined() part

Done.

>> Source/WebCore/platform/graphics/mac/FontMac.mm:40
>> +extern "C" bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);
> 
> Do we want to wrap this in a #if __MAC_MIN thing as well, to make it clear we only use it on 1090+?

I actually feel like this would do more harm than good. It would add more preprocessor bloat, and wouldn't actually be very valuable. There are many places in WebKit where functions are declared, yet never used or defined. Therefore, seeing a function declaration already doesn't necessarily mean that we ever use it.

>> Source/WebCore/platform/graphics/mac/FontMac.mm:545
>> +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1090
> 
> So this existed on 10.9 as well?

Yep!

>> Source/WebCore/platform/graphics/mac/FontMac.mm:548
>> +    return firstFamily().startsWith('.');
> 
> does this actually make sense on any platform? were there dot-prefixed fonts in 10.8?

Conveniently, the only platforms with the dot prefix are also platforms which have the CTFontDescriptorIsSystemUIFont() call :) Done.
Comment 5 Myles C. Maxfield 2014-04-22 21:09:44 PDT
Created attachment 229951 [details]
Patch
Comment 6 Myles C. Maxfield 2014-04-23 10:50:51 PDT
First patch r+'ed by dino. Second patch simply addresses comments.

http://trac.webkit.org/changeset/167713
Comment 7 WebKit Commit Bot 2014-04-23 11:28:57 PDT
Re-opened since this is blocked by bug 132070
Comment 8 Myles C. Maxfield 2014-04-23 14:25:45 PDT
Created attachment 230010 [details]
Patch
Comment 9 Myles C. Maxfield 2014-04-23 14:34:13 PDT
Re-landed in http://trac.webkit.org/changeset/167724
Comment 10 Darin Adler 2014-04-23 20:32:28 PDT
Comment on attachment 230010 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=230010&action=review

I think you already landed this, but it was still marked review?

> Source/WebCore/platform/graphics/mac/FontMac.mm:546
> +    RetainPtr<CTFontDescriptorRef> descriptor = CTFontCopyFontDescriptor(primaryFont()->platformData().ctFont());

This needs an adoptCF, otherwise it will be a storage leak.
Comment 11 Myles C. Maxfield 2014-04-23 20:51:38 PDT
Yeah - I marked the bug as closed but forgot to clear the r?. Thanks for the review.