[Cocoa] Google Fonts doesn't work if the user has the requested font locally-installed
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Jul 2018 00:15:20 +0000 (00:15 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Jul 2018 00:15:20 +0000 (00:15 +0000)
commite46f178f45e84c13324aa33944bcadd539dff22e
tree946061873a9fba13e9f14dc3a3648d27bcfdcae1
parent52c0651b0f5db4844cbbfec079ec0458cb5f5798
[Cocoa] Google Fonts doesn't work if the user has the requested font locally-installed
https://bugs.webkit.org/show_bug.cgi?id=187228
<rdar://problem/40967280>

Reviewed by Brent Fulgham.

Source/WebCore:

This is due to the local() items in the src: descriptor in the @font-family blocks.

This is because of a behavior difference between CSSFontFaceSource::load() and CSSFontFaceSource::font().
load() is supposed to set the status() to Success iff the font can be used, and then CSSFontFaceSource::font()
is supposed to return the font itself to use. load() works by constructing a dummy FontDescription and
performing a system lookup (to see if the local font really exists). However, this dummy FontDescription
doesn't set the ShouldAllowUserInstalledFonts flag. Then, in CSSFontFaceSource::font(), a similar lookup is
performed, except this one has the original FontDescription (with the correct value of the
ShouldAllowUserInstalledFonts flag set. Therefore, the two functions disagree about the state of the flag.

When the CSSFontFaceSource's status gets set to Success, that means "this is the font face source that
represents the @font-face block" but when CSSFontFaceSource::font() returns nullptr, that means "The font face
source can't be used for some reason" so we then continue searching down the font-family list (and render the
text in Helvetica or whatever comes next).

The solution is simple - just set the ShouldAllowUserInstalledFonts flag correctly in the dummy
FontDescription.

Test: fast/text/user-installed-fonts/local.html

* css/CSSFontFace.cpp:
(WebCore::CSSFontFace::allowUserInstalledFonts const):
* css/CSSFontFace.h:
* css/CSSFontFaceSet.cpp:
(WebCore::CSSFontFaceSet::ensureLocalFontFacesForFamilyRegistered):
* css/CSSFontFaceSource.cpp:
(WebCore::CSSFontFaceSource::load):

Tools:

The test only fails before the patch if the lookup for Helvetica2 is allowed to occur.

* WebKitTestRunner/mac/TestControllerMac.mm:
(WTR::allowedFontFamilySet):

LayoutTests:

* fast/text/user-installed-fonts/local-expected.html: Added.
* fast/text/user-installed-fonts/local.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233447 268f45cc-cd09-0410-ab3c-d52691b4dbfc
12 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/text/user-installed-fonts/local-expected.html [new file with mode: 0644]
LayoutTests/fast/text/user-installed-fonts/local.html [new file with mode: 0644]
LayoutTests/platform/ios/TestExpectations
LayoutTests/platform/mac/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/css/CSSFontFace.cpp
Source/WebCore/css/CSSFontFace.h
Source/WebCore/css/CSSFontFaceSet.cpp
Source/WebCore/css/CSSFontFaceSource.cpp
Tools/ChangeLog
Tools/WebKitTestRunner/mac/TestControllerMac.mm