Bug 156929

Summary: [Cocoa] Guarantee FontPlatformData's m_cgFont is never nullptr
Product: WebKit Reporter: Myles C. Maxfield <mmaxfield>
Component: New BugsAssignee: Myles C. Maxfield <mmaxfield>
Severity: Normal CC: cdumez, commit-queue
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Description Flags
darin: review+
Patch for committing none

Description Myles C. Maxfield 2016-04-22 13:54:34 PDT
[Cocoa] Guarantee FontPlatformData's m_cgFont is never nullptr
Comment 1 Myles C. Maxfield 2016-04-22 13:54:59 PDT
Created attachment 277097 [details]
Comment 2 Myles C. Maxfield 2016-04-22 14:00:21 PDT
Created attachment 277098 [details]
Comment 3 WebKit Commit Bot 2016-04-22 14:05:48 PDT
Attachment 277098 [details] did not pass style-queue:

ERROR: Source/WebCore/ChangeLog:8:  You should remove the 'No new tests' and either add and list tests, or explain why no new tests were possible.  [changelog/nonewtests] [5]
Total errors found: 1 in 8 files

If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Myles C. Maxfield 2016-04-22 17:07:43 PDT
Created attachment 277118 [details]
Comment 5 Myles C. Maxfield 2016-04-22 17:39:19 PDT
I should delete FontPlatformData::setFont()
Comment 6 Chris Dumez 2016-04-22 18:20:54 PDT
Does not build?
Comment 7 Myles C. Maxfield 2016-04-22 18:33:17 PDT
Created attachment 277126 [details]
Comment 8 Darin Adler 2016-04-23 16:52:48 PDT
Comment on attachment 277126 [details]

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

r=me if you fix the Windows build

> Source/WebCore/platform/graphics/FontPlatformData.cpp:60
>      m_cgFont = cgFont;

Could we construct this instead of initializing it?

> Source/WebCore/platform/graphics/FontPlatformData.h:-221
> -#if USE(CG)
> -    void setFallbackCGFont();
> -#endif

Broke the Windows build, which is still trying to call this function.

> Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm:265
> -            ASSERT(CFGetTypeID(runCTFont) == CTFontGetTypeID());
> +            ASSERT(runCTFont && CFGetTypeID(runCTFont) == CTFontGetTypeID());

If you want to add an assertion about this not being null, then it should be a separate assertion; we don’t use &&.

But also, CFGetTypeID is already a function that crashes when passed null; I don’t think we really need any change here.

> Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp:44
> +    ASSERT(font);

Is this really guaranteed?

> Source/WebCore/platform/mac/DragImageMac.mm:336
> +    if (drawURLString && urlFont) {

Doesn’t seem like we need this.

> Source/WebCore/platform/mac/DragImageMac.mm:343
> +    if (labelFont) {

Doesn’t seem like we need this.

> Source/WebKit/mac/Misc/WebStringTruncator.mm:65
> +    if (!menuFont.get())
> +        return nil;

I don’t think we need this. No chance of getting nil for the menu font. Probably don’t need the assertion either, since fontFromNSFont asserts.

> Source/WebKit/mac/Misc/WebStringTruncator.mm:73
> +    if (!font)
> +        return nil;

Returning @"" or returning the string without doing truncation would be better than returning nil.

> Source/WebKit/mac/Misc/WebStringTruncator.mm:81
> +    if (!font)
> +        return nil;

Returning @"" or returning the string without doing truncation would be better than returning nil.
Comment 9 Myles C. Maxfield 2016-04-25 19:05:59 PDT
Created attachment 277304 [details]
Patch for committing
Comment 10 Myles C. Maxfield 2016-04-25 20:53:08 PDT
Committed r200070: <http://trac.webkit.org/changeset/200070>