Web Font is downloaded even when all the characters in the document are outside its...
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 May 2016 00:13:01 +0000 (00:13 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 May 2016 00:13:01 +0000 (00:13 +0000)
commit49d66e49b6cd4fd728b9dc7409840375ad3295eb
tree94edc280aba435f73c4f8cb00ab472b2766d902c
parentc1254e6168038bafb15601af29f2f83a2e5f8bd0
Web Font is downloaded even when all the characters in the document are outside its unicode-range
https://bugs.webkit.org/show_bug.cgi?id=42154
<rdar://problem/17779042>

Reviewed by Darin Adler.

Source/WebCore:

Fonts are requested in two stages:
- For a given font family, all the relevant @font-face rules are consulted. We build up a
mapping of unicode-range -> Font object. This result is cached.
- Then, when we have the mapping, we look up the character we are trying to render to
find the appropriate Font object.

However, we are not supposed to create any Font objects (because that causes a download to
be triggered) until we consult with the character we're trying to render. Therefore, this
patch swaps out the Font objects with a FontAccessor. This FontAccessor is essentially a
lazily-created Font. When step 2 starts looking up the appropriate character, the
FontAccessor will be asked to start the download.

Test: fast/text/unicode-range-download.html

* css/CSSFontFace.cpp:
(WebCore::CSSFontFace::removeClient):
as a client from all its CSSFontFaces.
* css/CSSFontFaceSet.cpp:
(WebCore::CSSFontFaceSet::clear): Clearing the CSSFontFaceSet needs to remove itself as a
client from all its CSSFontFaces.
* css/CSSSegmentedFontFace.cpp:
(WebCore::CSSFontAccessor::create): The lazy Font object.
(WebCore::CSSFontAccessor::CSSFontAccessor): Ditto.
(WebCore::appendFontWithInvalidUnicodeRangeIfLoading): Appends a FontAccessor.
(WebCore::CSSSegmentedFontFace::fontRanges): Create the FontAccessor and use it instead.
* platform/graphics/FontCascadeFonts.cpp:
(WebCore::FontCascadeFonts::determinePitch): Use the fontForFirstRange() convenience
function.
(WebCore::glyphPageFromFontRanges): font() may now return nullptr. Update this function to
handle that.
* platform/graphics/FontRanges.cpp:
(WebCore::FontRanges::Range::font): Trigger the lazy initialization.
(WebCore::TrivialFontAccessor::create): Used in the case where there is only one font in
the Ranges object and it has a full unicode-range.
(WebCore::TrivialFontAccessor::TrivialFontAccessor):
(WebCore::FontRanges::FontRanges): Use TrivialFontAccessor.
(WebCore::FontRanges::glyphDataForCharacter): font() may now return nullptr. Update this
function to handle that. This is where the magic happens: this is where we trigger
downloads only if the character falls within the unicode-range.
(WebCore::FontRanges::fontForFirstRange): Add ASSERT.
(WebCore::FontRanges::isLoading): Update to use the new FontAccessor.
* platform/graphics/FontRanges.h: Ditto.
(WebCore::FontRanges::Range::Range):
(WebCore::FontRanges::Range::fontAccessor):
(WebCore::FontRanges::appendRange):
(WebCore::FontRanges::Range::font): Deleted.
* platform/graphics/FontSelector.h: The virtual base class of FontAccessor. This is
necessary because it must be shared between platform code and non-platform code.
(WebCore::FontAccessor::~FontAccessor):

LayoutTests:

* fast/text/unicode-range-download-expected.txt: Added.
* fast/text/unicode-range-download.html: Added.
* fast/text/resources/unicode-range-download-Ahem.otf: Added.
* fast/text/resources/unicode-range-download-Ahem.ttf: Added.
* fast/text/resources/unicode-range-download-Ahem.woff: Added.
* imported/blink/svg/custom/resources/graffiti.svg: Added.
imported/blink/svg/custom/svg-fonts-unloaded-segment.html requires this font.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200601 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/text/resources/unicode-range-download-Ahem.otf [new file with mode: 0644]
LayoutTests/fast/text/resources/unicode-range-download-Ahem.ttf [new file with mode: 0644]
LayoutTests/fast/text/resources/unicode-range-download-Ahem.woff [new file with mode: 0644]
LayoutTests/fast/text/unicode-range-download-expected.txt [new file with mode: 0644]
LayoutTests/fast/text/unicode-range-download.html [new file with mode: 0644]
LayoutTests/imported/blink/svg/custom/resources/graffiti.svg [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSFontFaceSet.cpp
Source/WebCore/css/CSSSegmentedFontFace.cpp
Source/WebCore/platform/graphics/FontCascadeFonts.cpp
Source/WebCore/platform/graphics/FontRanges.cpp
Source/WebCore/platform/graphics/FontRanges.h
Source/WebCore/platform/graphics/FontSelector.h