Change FontFaceSet#check() behavior when no matched font-face

When the font name passed to check() does not match any font face in the
FontFaceSet, current implementation always returns true.  As per the
latest spec draft [1], it should return true if it matches platform font
name, otherwise false.

[1] http://dev.w3.org/csswg/css-font-loading/#font-face-set-check

BUG=378989
TEST=fast/css/fontfaceset-check-platform-fonts.html

Review URL: https://codereview.chromium.org/324293003

git-svn-id: svn://svn.chromium.org/blink/trunk@176278 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 85721a82
Tests FontFaceSet#check() returns true for platform fonts
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS document.fonts.check('10px Arial'); is true
PASS document.fonts.check('10px Nonexistent'); is false
PASS document.fonts.check('10px sans-serif'); is true
PASS document.fonts.check('10px Nonexistent, monospace'); is true
PASS document.fonts.check('10px Nonexistent1, Nonexistent2'); is false
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<script>
description('Tests FontFaceSet#check() returns true for platform fonts');
shouldBeTrue("document.fonts.check('10px Arial');");
shouldBeFalse("document.fonts.check('10px Nonexistent');");
shouldBeTrue("document.fonts.check('10px sans-serif');");
shouldBeTrue("document.fonts.check('10px Nonexistent, monospace');");
shouldBeFalse("document.fonts.check('10px Nonexistent1, Nonexistent2');");
</script>
......@@ -149,6 +149,14 @@ void CSSFontSelector::willUseFontData(const FontDescription& fontDescription, co
face->willUseFontData(fontDescription, character);
}
bool CSSFontSelector::isPlatformFontAvailable(const FontDescription& fontDescription, const AtomicString& passedFamily)
{
AtomicString family = familyNameFromSettings(m_genericFontFamilySettings, fontDescription, passedFamily);
if (family.isEmpty())
family = passedFamily;
return FontCache::fontCache()->isPlatformFontAvailable(fontDescription, family);
}
#if !ENABLE(OILPAN)
void CSSFontSelector::clearDocument()
{
......
......@@ -57,6 +57,7 @@ public:
virtual PassRefPtr<FontData> getFontData(const FontDescription&, const AtomicString&) OVERRIDE;
virtual void willUseFontData(const FontDescription&, const AtomicString& family, UChar32) OVERRIDE;
bool isPlatformFontAvailable(const FontDescription&, const AtomicString& family);
#if !ENABLE(OILPAN)
void clearDocument();
......
......@@ -480,13 +480,25 @@ bool FontFaceSet::check(const String& fontString, const String& text, ExceptionS
return false;
}
FontFaceCache* fontFaceCache = document()->styleEngine()->fontSelector()->fontFaceCache();
CSSFontSelector* fontSelector = document()->styleEngine()->fontSelector();
FontFaceCache* fontFaceCache = fontSelector->fontFaceCache();
bool hasLoadedFaces = false;
for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next()) {
CSSSegmentedFontFace* face = fontFaceCache->get(font.fontDescription(), f->family());
if (face && !face->checkFont(nullToSpace(text)))
if (face) {
if (!face->checkFont(nullToSpace(text)))
return false;
hasLoadedFaces = true;
}
}
if (hasLoadedFaces)
return true;
for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next()) {
if (fontSelector->isPlatformFontAvailable(font.fontDescription(), f->family()))
return true;
}
return false;
}
bool FontFaceSet::resolveFontStyle(const String& fontString, Font& font)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment