font-weight in @font-face can cause a font to be downloaded even when it's not used
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2017 01:28:00 +0000 (01:28 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2017 01:28:00 +0000 (01:28 +0000)
commit24bbf1f53049a1c56cda586a22d54b05d50fe4f3
treec01387a08671319239f4bbfb806be949790616cc
parent80649103e8b183ef5aadc769e2413a3242b09a7d
font-weight in @font-face can cause a font to be downloaded even when it's not used
https://bugs.webkit.org/show_bug.cgi?id=168114
<rdar://problem/30301317>

Reviewed by Darin Adler.

Source/WebCore:

There were two problems with our font loading code.

When we are in the middle of a download, we will use a special interstitial font,
and this special font has a flag set which will cause it to be invisible when it is
drawn. However, when we start using this font during the load, we give it a
unicode-range of U+0-0 which means that it will never be used, and fallback will
happen to other weights immediately.

The second problem with the font loading code is that this interstital font is just
Times. Times doesn't support every character, which means that if we are trying
to render some exotic character, we fall back to other weights. The solution here
is to use LastResort as the interstitial font, because it supports all characters.
Because its metrics are reasonable and we don't ever actually paint this
interstitial font, this choice is no worse than Times.

Tests: fast/text/font-style-download.html
       fast/text/font-weight-download-2.html
       fast/text/font-weight-download.html
       fast/text/font-weight-fallback.html

* css/CSSFontFace.cpp:
(WebCore::CSSFontFace::font):
* css/CSSSegmentedFontFace.cpp:
(WebCore::appendFont):
(WebCore::CSSSegmentedFontFace::fontRanges):
(WebCore::appendFontWithInvalidUnicodeRangeIfLoading): Deleted.
* platform/graphics/Font.h:
(WebCore::Font::widthForGlyph):
* platform/graphics/FontCache.h:
* platform/graphics/freetype/FontCacheFreeType.cpp:
(WebCore::FontCache::lastResortFallbackFontForEveryCharacter):
* platform/graphics/mac/FontCacheMac.mm:
(WebCore::FontCache::lastResortFallbackFontForEveryCharacter):
* platform/graphics/win/FontCacheWin.cpp:
(WebCore::FontCache::lastResortFallbackFontForEveryCharacter):

Tools:

LastResort needs to be usable in tests.

* DumpRenderTree/mac/DumpRenderTree.mm:
(allowedFontFamilySet):
* WebKitTestRunner/InjectedBundle/cocoa/ActivateFontsCocoa.mm:
(WTR::allowedFontFamilySet):
* WebKitTestRunner/mac/TestControllerMac.mm:
(WTR::allowedFontFamilySet):

LayoutTests:

* fast/text/font-style-download-expected.txt: Added.
* fast/text/font-style-download.html: Added.
* fast/text/font-weight-download-2-expected.txt: Added.
* fast/text/font-weight-download-2.html: Added.
* fast/text/font-weight-download-expected.txt: Added.
* fast/text/font-weight-download.html: Added.
* fast/text/font-weight-fallback-expected.html: Added.
* fast/text/font-weight-fallback.html: Added.
* http/tests/webfont/fallback-font-while-loading-expected.txt: We don't want to use the
fallback font while an earlier font is loading because the fallback font might require
an extra download. This represents a policy change.
* http/tests/webfont/fallback-font-while-loading.html: Ditto.
* resources/Ahem_CJK.ttf: Added.
* svg/W3C-SVG-1.1-SE/struct-dom-11-f.svg: The metrics of LastResort are different from
the metrics of the previous interstitial font, which means the new font causes elements
to intersect when they previously didn't. However, the web font isn't actually necessary
here, so we can just stop using it, thereby sidestepping the entire problem.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212513 268f45cc-cd09-0410-ab3c-d52691b4dbfc
25 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/text/font-style-download-expected.txt [new file with mode: 0644]
LayoutTests/fast/text/font-style-download.html [new file with mode: 0644]
LayoutTests/fast/text/font-weight-download-2-expected.txt [new file with mode: 0644]
LayoutTests/fast/text/font-weight-download-2.html [new file with mode: 0644]
LayoutTests/fast/text/font-weight-download-expected.txt [new file with mode: 0644]
LayoutTests/fast/text/font-weight-download.html [new file with mode: 0644]
LayoutTests/fast/text/font-weight-fallback-expected.html [new file with mode: 0644]
LayoutTests/fast/text/font-weight-fallback.html [new file with mode: 0644]
LayoutTests/http/tests/webfont/fallback-font-while-loading-expected.txt
LayoutTests/http/tests/webfont/fallback-font-while-loading.html
LayoutTests/resources/Ahem_CJK.ttf [new file with mode: 0644]
LayoutTests/svg/W3C-SVG-1.1-SE/struct-dom-11-f.svg
Source/WebCore/ChangeLog
Source/WebCore/css/CSSFontFace.cpp
Source/WebCore/css/CSSSegmentedFontFace.cpp
Source/WebCore/platform/graphics/Font.h
Source/WebCore/platform/graphics/FontCache.h
Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp
Source/WebCore/platform/graphics/mac/FontCacheMac.mm
Source/WebCore/platform/graphics/win/FontCacheWin.cpp
Tools/ChangeLog
Tools/DumpRenderTree/mac/DumpRenderTree.mm
Tools/WebKitTestRunner/InjectedBundle/cocoa/ActivateFontsCocoa.mm
Tools/WebKitTestRunner/mac/TestControllerMac.mm