Previous elements with lang= can affect fonts selected for subsequent elements
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Aug 2017 23:46:39 +0000 (23:46 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Aug 2017 23:46:39 +0000 (23:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175959
<rdar://problem/33785853>

Reviewed by Zalan Bujtas.

Source/WebCore:

FontCascade::update() was erroneously getting a cache hit. Elements with different lang=
should be distinct inside the FontCascadeCache. We should be keying off of the locale
string instead of the script enum because the string is the thing we actually pass to the
platform APIs when performing font selection. This is a regression because we only
recently (within the past few years) started making font selection sensitive to lang= at
all.

Test: fast/text/lang-font-selection-cache.html

* platform/graphics/FontCache.h:
(WebCore::FontDescriptionKey::FontDescriptionKey):
(WebCore::FontDescriptionKey::operator== const):
(WebCore::FontDescriptionKey::computeHash const):

LayoutTests:

* fast/text/lang-font-selection-cache-expected.html: Added.
* fast/text/lang-font-selection-cache.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221408 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/text/lang-font-selection-cache-expected.html [new file with mode: 0644]
LayoutTests/fast/text/lang-font-selection-cache.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/FontCache.h

index e549975..0bc2462 100644 (file)
@@ -1,3 +1,14 @@
+2017-08-30  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Previous elements with lang= can affect fonts selected for subsequent elements
+        https://bugs.webkit.org/show_bug.cgi?id=175959
+        <rdar://problem/33785853>
+
+        Reviewed by Zalan Bujtas.
+
+        * fast/text/lang-font-selection-cache-expected.html: Added.
+        * fast/text/lang-font-selection-cache.html: Added.
+
 2017-08-30  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r221327.
diff --git a/LayoutTests/fast/text/lang-font-selection-cache-expected.html b/LayoutTests/fast/text/lang-font-selection-cache-expected.html
new file mode 100644 (file)
index 0000000..7e02727
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+</style>
+</head>
+<body>
+This test makes sure that a previous element rendered with the same font but different lang doesn't affect the fonts chosen to render a subsequent element.
+<div style="font-size: 48px;">
+<div style="width: 1px; height: 200px; display: inline-block;"></div>
+<span lang="ku-Arab">&#x643;&#x648;&#x631;&#x62f;&#x6cc;</span>
+</div>
+</body>
+</html>
+
diff --git a/LayoutTests/fast/text/lang-font-selection-cache.html b/LayoutTests/fast/text/lang-font-selection-cache.html
new file mode 100644 (file)
index 0000000..90d3f94
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+</style>
+</head>
+<body>
+This test makes sure that a previous element rendered with the same font but different lang doesn't affect the fonts chosen to render a subsequent element.
+<div style="font-size: 48px;">
+<div style="width: 1px; height: 200px; display: inline-block;"></div>
+<span lang="ur" style="color: transparent;">&#x627;&#x631;&#x62f;&#x648;</span>
+<span lang="ku-Arab">&#x643;&#x648;&#x631;&#x62f;&#x6cc;</span>
+</div>
+</body>
+</html>
+
index 54ef34a..86fa163 100644 (file)
@@ -1,3 +1,25 @@
+2017-08-30  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Previous elements with lang= can affect fonts selected for subsequent elements
+        https://bugs.webkit.org/show_bug.cgi?id=175959
+        <rdar://problem/33785853>
+
+        Reviewed by Zalan Bujtas.
+
+        FontCascade::update() was erroneously getting a cache hit. Elements with different lang=
+        should be distinct inside the FontCascadeCache. We should be keying off of the locale
+        string instead of the script enum because the string is the thing we actually pass to the
+        platform APIs when performing font selection. This is a regression because we only
+        recently (within the past few years) started making font selection sensitive to lang= at
+        all.
+
+        Test: fast/text/lang-font-selection-cache.html
+
+        * platform/graphics/FontCache.h:
+        (WebCore::FontDescriptionKey::FontDescriptionKey):
+        (WebCore::FontDescriptionKey::operator== const):
+        (WebCore::FontDescriptionKey::computeHash const):
+
 2017-08-30  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r221327.
index 7e35035..890d6d7 100644 (file)
@@ -74,6 +74,7 @@ struct FontDescriptionKey {
         : m_size(description.computedPixelSize())
         , m_fontSelectionRequest(description.fontSelectionRequest())
         , m_flags(makeFlagsKey(description))
+        , m_locale(description.locale())
         , m_featureSettings(description.featureSettings())
 #if ENABLE(VARIATION_FONTS)
         , m_variationSettings(description.variationSettings())
@@ -89,6 +90,7 @@ struct FontDescriptionKey {
         return m_size == other.m_size
             && m_fontSelectionRequest == other.m_fontSelectionRequest
             && m_flags == other.m_flags
+            && m_locale == other.m_locale
 #if ENABLE(VARIATION_FONTS)
             && m_variationSettings == other.m_variationSettings
 #endif
@@ -109,6 +111,7 @@ struct FontDescriptionKey {
         hasher.add(m_fontSelectionRequest.weight);
         hasher.add(m_fontSelectionRequest.width);
         hasher.add(m_fontSelectionRequest.slope);
+        hasher.add(m_locale.existingHash());
         for (unsigned flagItem : m_flags)
             hasher.add(flagItem);
         hasher.add(m_featureSettings.hash());
@@ -154,6 +157,7 @@ private:
     unsigned m_size { 0 };
     FontSelectionRequest m_fontSelectionRequest;
     std::array<unsigned, 2> m_flags {{ 0, 0 }};
+    AtomicString m_locale;
     FontFeatureSettings m_featureSettings;
 #if ENABLE(VARIATION_FONTS)
     FontVariationSettings m_variationSettings;