Skip to content

Commit 0113371

Browse files
REGRESSION(r212513): LastResort is platform-dependent, so its semantics should not be required to perform font loading correctly.
https://bugs.webkit.org/show_bug.cgi?id=168487 Reviewed by Antti Koivisto. Source/WebCore: There are three ways a Web author can chain multiple font files together: 1. Multiple entries in the "src" descriptor in an @font-face rule 2. Multiple @font-face rules with the same "font-family" descriptor 3. Multiple entries in the "font-family" property on an element Before r212513, the code which iterated across #2 and #3 above could have triggered each item in the chain to download. r212513 tried to solve this by using LastResort as the interstitial font used during downloads, because LastResort supports every character and therefore solves #3 above. However, this change had a few problems: 1. Previously, our code would try to avoid using the interstitial font for layout or rendering whenever possible (because one of the chains above may have named a local font which would be better to use). In order to use the benefits of LastResort, I had to remove this avoidance logic and make WebKit try to use the interstitial font as often as possible. However, due to the large metrics of LastResort, this means that offsetWidth queries during font loading would be wildly inaccurate, causing Google Docs to break. 2. It also means that canvas drawing during font loading would actually draw LastResort, causing Bing maps to break. 3. LastResort is platform-specific, so only platforms which have it would actually be able to load fonts correctly. Instead, we should keep the older logic about avoiding using the interstitial font so that loading has a better experience for the user. We solve the unnecessary download problem by giving our loading code a downloading policy enum, which has two values: allow downloads or forbid downloads. Whenever our loading code returns the interstitial font, we continue our search, but we change the policy to forbid downloads. There is one piece of subtlety, though: It is more common for web authors to put good fallbacks in the "font-family" property than in the "src" descriptor inside @font-face. This means that we shouldn't exhaustively search through the @font-face src list first. Instead, we should look through the src list until we hit a non-local font, and then immediately start looking through the other other chains. Tests: fast/text/font-download-font-face-src-list.html fast/text/font-download-font-family-property.html fast/text/font-download-remote-fallback-all.html fast/text/font-interstitial-invisible-width-while-loading.html fast/text/font-weight-download-3.html fast/text/web-font-load-fallback-during-loading-2.html fast/text/web-font-load-invisible-during-loading.html * css/CSSFontFace.cpp: (WebCore::CSSFontFace::fontLoadEventOccurred): Implement support for the font download policy. (WebCore::CSSFontFace::setStatus): After 3 seconds of loading, we will start drawing the fallback font. However, for testing, we have an internal setting to make this switch happen immediately. This patch now requires that this internal switch happen synchronously. (WebCore::CSSFontFace::pump): Implement support for the font download policy. (WebCore::CSSFontFace::load): Ditto. (WebCore::CSSFontFace::font): Ditto. * css/CSSFontFace.h: Ditto. * css/CSSFontSelector.cpp: (WebCore::CSSFontSelector::beginLoadingFontSoon): Implement support for synchronous font download timeouts. * css/CSSSegmentedFontFace.cpp: (WebCore::CSSSegmentedFontFace::fontRanges): Implement support for the font download policy. * platform/graphics/Font.cpp: Add new flag which represents if the interstitial font was created after the 3 second timeout or before. Previously, we would distinguish between these two cases by knowing that one font was LastResort and the other font was a fallback. Now that we're using fallback fonts on both sides of the 3 second timeout, we now no longer know which one should be invisible. This new enum solves this problem. (WebCore::Font::Font): (WebCore::Font::verticalRightOrientationFont): (WebCore::Font::uprightOrientationFont): * platform/graphics/Font.h: Ditto. (WebCore::Font::create): (WebCore::Font::origin): (WebCore::Font::visibility): * platform/graphics/FontCache.h: * platform/graphics/FontCascade.cpp: We try to fall back to a local() font during downloads, but there might not be one that we can use. Therefore, we can't use the presence of the interstitial font to detect if we should paint invisibly. Instead, we can move this logic into the font-specific part of painting, and consult with the specific font to know if it was created from a timed-out @font-face rule or not. (WebCore::FontCascade::drawText): (WebCore::shouldDrawIfLoading): (WebCore::FontCascade::drawGlyphBuffer): (WebCore::FontCascade::drawEmphasisMarks): * platform/graphics/FontCascade.h: * platform/graphics/FontCascadeFonts.cpp: (WebCore::FontCascadeFonts::glyphDataForVariant): Implement the logic described above where we switch the policy if we encounter the intestitial font. (WebCore::FontCascadeFonts::glyphDataForNormalVariant): Ditto. (WebCore::glyphPageFromFontRanges): Ditto. * platform/graphics/FontRanges.cpp: Implement support for the font download policy. (WebCore::FontRanges::Range::font): (WebCore::FontRanges::glyphDataForCharacter): (WebCore::FontRanges::fontForCharacter): (WebCore::FontRanges::fontForFirstRange): * platform/graphics/FontRanges.h: * platform/graphics/FontSelector.h: * platform/graphics/freetype/FontCacheFreeType.cpp: (WebCore::FontCache::lastResortFallbackFontForEveryCharacter): Deleted. * platform/graphics/mac/FontCacheMac.mm: (WebCore::FontCache::lastResortFallbackFontForEveryCharacter): Deleted. * platform/graphics/win/FontCacheWin.cpp: (WebCore::FontCache::lastResortFallbackFontForEveryCharacter): Deleted. LayoutTests: * fast/text/font-download-font-face-src-list-expected.txt: Added. * fast/text/font-download-font-face-src-list.html: Copied from LayoutTests/fast/text/font-weight-download-2.html. * fast/text/font-download-font-family-property-expected.txt: Added. * fast/text/font-download-font-family-property.html: Copied from LayoutTests/fast/text/font-weight-download-2.html. * fast/text/font-download-remote-fallback-all-expected.txt: Added. * fast/text/font-download-remote-fallback-all.html: Copied from LayoutTests/fast/text/font-weight-download-2.html. * fast/text/font-interstitial-invisible-width-while-loading-expected.txt: Added. * fast/text/font-interstitial-invisible-width-while-loading.html: Added. * fast/text/font-weight-download-2.html: * fast/text/font-weight-download-3-expected.txt: Added. * fast/text/font-weight-download-3.html: Copied from LayoutTests/fast/text/font-weight-download-2.html. * fast/text/web-font-load-fallback-during-loading-2-expected.html: Added. * fast/text/web-font-load-fallback-during-loading-2.html: Added. * fast/text/web-font-load-fallback-during-loading-expected.html: * fast/text/web-font-load-fallback-during-loading.html: * fast/text/web-font-load-invisible-during-loading-expected.txt: Added. * fast/text/web-font-load-invisible-during-loading.html: Added. * http/tests/webfont/fallback-font-while-loading-expected.txt: * http/tests/webfont/fallback-font-while-loading.html: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@216944 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent b7650a5 commit 0113371

37 files changed

Lines changed: 637 additions & 158 deletions

‎LayoutTests/ChangeLog‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
2017-05-16 Myles C. Maxfield <[email protected]>
2+
3+
REGRESSION(r212513): LastResort is platform-dependent, so its semantics should not be required to perform font loading correctly.
4+
https://bugs.webkit.org/show_bug.cgi?id=168487
5+
6+
Reviewed by Antti Koivisto.
7+
8+
* fast/text/font-download-font-face-src-list-expected.txt: Added.
9+
* fast/text/font-download-font-face-src-list.html: Copied from LayoutTests/fast/text/font-weight-download-2.html.
10+
* fast/text/font-download-font-family-property-expected.txt: Added.
11+
* fast/text/font-download-font-family-property.html: Copied from LayoutTests/fast/text/font-weight-download-2.html.
12+
* fast/text/font-download-remote-fallback-all-expected.txt: Added.
13+
* fast/text/font-download-remote-fallback-all.html: Copied from LayoutTests/fast/text/font-weight-download-2.html.
14+
* fast/text/font-interstitial-invisible-width-while-loading-expected.txt: Added.
15+
* fast/text/font-interstitial-invisible-width-while-loading.html: Added.
16+
* fast/text/font-weight-download-2.html:
17+
* fast/text/font-weight-download-3-expected.txt: Added.
18+
* fast/text/font-weight-download-3.html: Copied from LayoutTests/fast/text/font-weight-download-2.html.
19+
* fast/text/web-font-load-fallback-during-loading-2-expected.html: Added.
20+
* fast/text/web-font-load-fallback-during-loading-2.html: Added.
21+
* fast/text/web-font-load-fallback-during-loading-expected.html:
22+
* fast/text/web-font-load-fallback-during-loading.html:
23+
* fast/text/web-font-load-invisible-during-loading-expected.txt: Added.
24+
* fast/text/web-font-load-invisible-during-loading.html: Added.
25+
* http/tests/webfont/fallback-font-while-loading-expected.txt:
26+
* http/tests/webfont/fallback-font-while-loading.html:
27+
128
2017-05-16 Eric Carlson <[email protected]>
229

330
[MediaStream] Return default device list until user gives permission to capture
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
font-download-font-face-src-list.html - didFinishLoading
2+
Ahem_CJK.ttf - willSendRequest <NSURLRequest URL Ahem_CJK.ttf, main document URL font-download-font-face-src-list.html, http method GET> redirectResponse (null)
3+
Ahem_CJK.ttf - didReceiveResponse <NSURLResponse Ahem_CJK.ttf, http status code 0>
4+
Ahem_CJK.ttf - didFinishLoading
5+
This test makes sure that unnecessary fonts aren't downloaded. The test fails if Ahem.otf is downloaded.
6+
横
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script>
5+
if (window.testRunner) {
6+
testRunner.dumpResourceLoadCallbacks();
7+
testRunner.dumpAsText();
8+
}
9+
if (window.internals) {
10+
internals.invalidateFontCache();
11+
internals.clearMemoryCache();
12+
}
13+
</script>
14+
<style>
15+
@font-face {
16+
font-family: "WebFont";
17+
src: url("../../resources/Ahem_CJK.ttf") format("truetype"), url("../../resources/Ahem.otf") format("opentype");
18+
}
19+
</style>
20+
</head>
21+
<body>
22+
This test makes sure that unnecessary fonts aren't downloaded. The test fails if Ahem.otf is downloaded.
23+
<div style="font-size: 100px; font-family: 'WebFont';">&#x6A2A;</div>
24+
</body>
25+
</html>
26+
27+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
font-download-font-family-property.html - didFinishLoading
2+
Ahem_CJK.ttf - willSendRequest <NSURLRequest URL Ahem_CJK.ttf, main document URL font-download-font-family-property.html, http method GET> redirectResponse (null)
3+
Ahem_CJK.ttf - didReceiveResponse <NSURLResponse Ahem_CJK.ttf, http status code 0>
4+
Ahem_CJK.ttf - didFinishLoading
5+
This test makes sure that unnecessary fonts aren't downloaded. The test fails if Ahem.otf is downloaded.
6+
横
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script>
5+
if (window.testRunner) {
6+
testRunner.dumpResourceLoadCallbacks();
7+
testRunner.dumpAsText();
8+
}
9+
if (window.internals) {
10+
internals.invalidateFontCache();
11+
internals.clearMemoryCache();
12+
}
13+
</script>
14+
<style>
15+
@font-face {
16+
font-family: "WebFont";
17+
src: url("../../resources/Ahem_CJK.ttf") format("truetype");
18+
}
19+
@font-face {
20+
font-family: "WebFont2";
21+
src: url("../../resources/Ahem.otf") format("opentype");
22+
}
23+
</style>
24+
</head>
25+
<body>
26+
This test makes sure that unnecessary fonts aren't downloaded. The test fails if Ahem.otf is downloaded.
27+
<div style="font-size: 100px; font-family: 'WebFont', 'WebFont2';">&#x6A2A;</div>
28+
</body>
29+
</html>
30+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
font-download-remote-fallback-all.html - didFinishLoading
2+
Ahem_CJK.ttf - willSendRequest <NSURLRequest URL Ahem_CJK.ttf, main document URL font-download-remote-fallback-all.html, http method GET> redirectResponse (null)
3+
Ahem_CJK.ttf - didReceiveResponse <NSURLResponse Ahem_CJK.ttf, http status code 0>
4+
Ahem_CJK.ttf - didFinishLoading
5+
This test makes sure that unnecessary fonts aren't downloaded. The test fails if any of the "garbage" font names are requested.
6+
横
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script>
5+
if (window.testRunner) {
6+
testRunner.dumpResourceLoadCallbacks();
7+
testRunner.dumpAsText();
8+
}
9+
if (window.internals) {
10+
internals.invalidateFontCache();
11+
internals.clearMemoryCache();
12+
}
13+
</script>
14+
<style>
15+
@font-face {
16+
font-family: "WebFont";
17+
font-weight: 100;
18+
src: url("../../resources/Ahem_CJK.ttf"), url("garbage2");
19+
}
20+
@font-face {
21+
font-family: "WebFont";
22+
font-weight: 900;
23+
src: url("garbage3"), url("garbage4");
24+
}
25+
@font-face {
26+
font-family: "WebFont2";
27+
src: url("garbage5"), url("garbage6");
28+
}
29+
</style>
30+
</head>
31+
<body>
32+
This test makes sure that unnecessary fonts aren't downloaded. The test fails if any of the "garbage" font names are requested.
33+
<div style="font-size: 100px; font-weight: 100; font-family: 'WebFont', 'WebFont2';">&#x6A2A;</div>
34+
</body>
35+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
This test makes sure that the advances of the interstitial (invisible) font used during font loading is not very far from 'Times'. This is necessary for web compatibility.
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS target.offsetWidth is within 5 of 223
7+
PASS successfullyParsed is true
8+
9+
TEST COMPLETE
10+
Hello
11+
Hello
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="../../resources/js-test-pre.js"></script>
5+
<script>
6+
if (window.internals) {
7+
internals.invalidateFontCache();
8+
internals.clearMemoryCache();
9+
}
10+
</script>
11+
<style>
12+
@font-face {
13+
font-family: "WebFont";
14+
src: url("../../resources/Ahem.otf") format("opentype");
15+
}
16+
</style>
17+
</head>
18+
<body>
19+
<div><span id="target" style="font: 100px 'WebFont';">Hello</span></div>
20+
<div><span id="ref" style="font: 100px 'Times';">Hello</span></div>
21+
<script>
22+
description("This test makes sure that the advances of the interstitial (invisible) font used during font loading is not very far from 'Times'. This is necessary for web compatibility.");
23+
var target = document.getElementById("target");
24+
var ref = document.getElementById("ref");
25+
shouldBeCloseTo("target.offsetWidth", ref.offsetWidth, 5);
26+
</script>
27+
<script src="../../resources/js-test-post.js"></script>
28+
</body>
29+
</html>

‎LayoutTests/fast/text/font-weight-download-2.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
This test makes sure that unnecessary fonts aren't downloaded. The test fails if Ahem.otf is downloaded.
2929
<div style="font: 100 100px 'WebFont';">&#x6A2A;</div>
3030
</body>
31-
</html>
31+
</html>

0 commit comments

Comments
 (0)