Diff
Modified: trunk/LayoutTests/ChangeLog (189037 => 189038)
--- trunk/LayoutTests/ChangeLog 2015-08-27 18:03:43 UTC (rev 189037)
+++ trunk/LayoutTests/ChangeLog 2015-08-27 18:09:20 UTC (rev 189038)
@@ -1,3 +1,22 @@
+2015-08-27 Myles C. Maxfield <[email protected]>
+
+ [Cocoa] Generic font families do not consult with the user's preferred language
+ https://bugs.webkit.org/show_bug.cgi?id=148499
+ <rdar://problem/22407296>
+
+ Reviewed by Antti Koivisto.
+
+ Mock the user's font preferences.
+
+ * fast/text/international/font-fallback-to-common-script.html:
+ * fast/text/international/generic-font-family-language-simplified-expected.html: Added.
+ * fast/text/international/generic-font-family-language-simplified.html: Added.
+ * fast/text/international/generic-font-family-language-traditional-expected.html: Added.
+ * fast/text/international/generic-font-family-language-traditional.html: Added.
+ * fast/text/international/lang-sensitive-fonts-xml.xhtml:
+ * fast/text/international/lang-sensitive-fonts.html:
+ * fast/text/international/locale-sensitive-fonts.html:
+
2015-08-27 Joseph Pecoraro <[email protected]>
Web Inspector: Standardize on CSSStyleSheet.Type enum and move more protocol enum conversion to the manager
Modified: trunk/LayoutTests/fast/text/international/font-fallback-to-common-script.html (189037 => 189038)
--- trunk/LayoutTests/fast/text/international/font-fallback-to-common-script.html 2015-08-27 18:03:43 UTC (rev 189037)
+++ trunk/LayoutTests/fast/text/international/font-fallback-to-common-script.html 2015-08-27 18:09:20 UTC (rev 189038)
@@ -8,6 +8,8 @@
window.internals.settings.setStandardFontFamily("Ahem", "Zyyy");
window.internals.settings.setSansSerifFontFamily("Ahem", "Zyyy");
+
+ window.internals.setUserPreferredLanguages("en", "zh-cn");
}
</script>
</head>
Added: trunk/LayoutTests/fast/text/international/generic-font-family-language-simplified-expected.html (0 => 189038)
--- trunk/LayoutTests/fast/text/international/generic-font-family-language-simplified-expected.html (rev 0)
+++ trunk/LayoutTests/fast/text/international/generic-font-family-language-simplified-expected.html 2015-08-27 18:09:20 UTC (rev 189038)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+This test makes sure that generic font families consult with the system language preferences for Chinese when we can't tell
+from the lang if we should use Simplified Chinese of Traditional Chinese.
+<div lang="zh-hans" style="font-size: 50px;">
+<div style="font-family: sans-serif;">透過</div>
+<div style="font-family: serif;">透過</div>
+<div style="font-family: -webkit-standard;">透過</div>
+<div style="font-family: fixed;">透過</div>
+</div>
+</body>
+</html>
Added: trunk/LayoutTests/fast/text/international/generic-font-family-language-simplified.html (0 => 189038)
--- trunk/LayoutTests/fast/text/international/generic-font-family-language-simplified.html (rev 0)
+++ trunk/LayoutTests/fast/text/international/generic-font-family-language-simplified.html 2015-08-27 18:09:20 UTC (rev 189038)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+window.internals.setUserPreferredLanguages(["en", "zh-cn"]);
+</script>
+</head>
+<body>
+This test makes sure that generic font families consult with the system language preferences for Chinese when we can't tell
+from the lang if we should use Simplified Chinese of Traditional Chinese.
+<div lang="zh" style="font-size: 50px;">
+<div style="font-family: sans-serif;">透過</div>
+<div style="font-family: serif;">透過</div>
+<div style="font-family: -webkit-standard;">透過</div>
+<div style="font-family: fixed;">透過</div>
+</div>
+</body>
+</html>
Added: trunk/LayoutTests/fast/text/international/generic-font-family-language-traditional-expected.html (0 => 189038)
--- trunk/LayoutTests/fast/text/international/generic-font-family-language-traditional-expected.html (rev 0)
+++ trunk/LayoutTests/fast/text/international/generic-font-family-language-traditional-expected.html 2015-08-27 18:09:20 UTC (rev 189038)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+This test makes sure that generic font families consult with the system language preferences for Chinese when we can't tell
+from the lang if we should use Simplified Chinese of Traditional Chinese.
+<div lang="zh-hant" style="font-size: 50px;">
+<div style="font-family: sans-serif;">透過</div>
+<div style="font-family: serif;">透過</div>
+<div style="font-family: -webkit-standard;">透過</div>
+<div style="font-family: fixed;">透過</div>
+</div>
+</body>
+</html>
Added: trunk/LayoutTests/fast/text/international/generic-font-family-language-traditional.html (0 => 189038)
--- trunk/LayoutTests/fast/text/international/generic-font-family-language-traditional.html (rev 0)
+++ trunk/LayoutTests/fast/text/international/generic-font-family-language-traditional.html 2015-08-27 18:09:20 UTC (rev 189038)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+window.internals.setUserPreferredLanguages(["en", "zh-tw"]);
+</script>
+</head>
+<body>
+This test makes sure that generic font families consult with the system language preferences for Chinese when we can't tell
+from the lang if we should use Simplified Chinese of Traditional Chinese.
+<div lang="zh" style="font-size: 50px;">
+<div style="font-family: sans-serif;">透過</div>
+<div style="font-family: serif;">透過</div>
+<div style="font-family: -webkit-standard;">透過</div>
+<div style="font-family: fixed;">透過</div>
+</div>
+</body>
+</html>
Modified: trunk/LayoutTests/fast/text/international/lang-sensitive-fonts-xml.xhtml (189037 => 189038)
--- trunk/LayoutTests/fast/text/international/lang-sensitive-fonts-xml.xhtml 2015-08-27 18:03:43 UTC (rev 189037)
+++ trunk/LayoutTests/fast/text/international/lang-sensitive-fonts-xml.xhtml 2015-08-27 18:09:20 UTC (rev 189038)
@@ -6,6 +6,8 @@
if (window.internals) {
window.internals.settings.setStandardFontFamily("Ahem", "Hans");
window.internals.settings.setFantasyFontFamily("Ahem", "Hans");
+
+ window.internals.setUserPreferredLanguages("en", "zh-cn");
}
</script>
</head>
Modified: trunk/LayoutTests/fast/text/international/lang-sensitive-fonts.html (189037 => 189038)
--- trunk/LayoutTests/fast/text/international/lang-sensitive-fonts.html 2015-08-27 18:03:43 UTC (rev 189037)
+++ trunk/LayoutTests/fast/text/international/lang-sensitive-fonts.html 2015-08-27 18:09:20 UTC (rev 189038)
@@ -5,6 +5,8 @@
if (window.internals) {
window.internals.settings.setStandardFontFamily("Ahem", "Hans");
window.internals.settings.setFantasyFontFamily("Ahem", "Hans");
+
+ window.internals.setUserPreferredLanguages("en", "zh-cn");
}
</script>
</head>
Modified: trunk/LayoutTests/fast/text/international/locale-sensitive-fonts.html (189037 => 189038)
--- trunk/LayoutTests/fast/text/international/locale-sensitive-fonts.html 2015-08-27 18:03:43 UTC (rev 189037)
+++ trunk/LayoutTests/fast/text/international/locale-sensitive-fonts.html 2015-08-27 18:09:20 UTC (rev 189038)
@@ -5,6 +5,8 @@
if (window.internals) {
window.internals.settings.setStandardFontFamily("Ahem", "Hans");
window.internals.settings.setFantasyFontFamily("Ahem", "Hans");
+
+ window.internals.setUserPreferredLanguages("en", "zh-cn");
}
</script>
</head>
Modified: trunk/Source/WebCore/ChangeLog (189037 => 189038)
--- trunk/Source/WebCore/ChangeLog 2015-08-27 18:03:43 UTC (rev 189037)
+++ trunk/Source/WebCore/ChangeLog 2015-08-27 18:09:20 UTC (rev 189038)
@@ -1,5 +1,34 @@
2015-08-27 Myles C. Maxfield <[email protected]>
+ [Cocoa] Generic font families do not consult with the user's preferred language
+ https://bugs.webkit.org/show_bug.cgi?id=148499
+ <rdar://problem/22407296>
+
+ Reviewed by Antti Koivisto.
+
+ When WebKit encounters markup like lang="zh" style="font-family: sans-serif;"
+ we currently always use Simplified Chinese fonts. However, the user may
+ have specifically selected Traditional Chinese in their user preferences.
+ In this absence of other signals, we should consult with the user
+ preferences when determining which font to pick.
+
+ Tests: fast/text/international/generic-font-family-language-simplified.html
+ fast/text/international/generic-font-family-language-traditional.html
+
+ * platform/Language.cpp:
+ (WebCore::observerMap):
+ (WebCore::overrideUserPreferredLanguages):
+ * platform/graphics/FontGenericFamilies.cpp:
+ (WebCore::computeUserPrefersSimplified):
+ (WebCore::cachedUserPrefersSimplified):
+ (WebCore::languageChanged):
+ (WebCore::genericFontFamilyForScript):
+ (WebCore::FontGenericFamilies::FontGenericFamilies):
+ * platform/text/LocaleToScriptMappingDefault.cpp:
+ (WebCore::scriptNameToCode):
+
+2015-08-27 Myles C. Maxfield <[email protected]>
+
Update Grid Layout to use fewer magic -1s
https://bugs.webkit.org/show_bug.cgi?id=148505
Modified: trunk/Source/WebCore/platform/Language.cpp (189037 => 189038)
--- trunk/Source/WebCore/platform/Language.cpp 2015-08-27 18:03:43 UTC (rev 189037)
+++ trunk/Source/WebCore/platform/Language.cpp 2015-08-27 18:09:20 UTC (rev 189038)
@@ -27,6 +27,7 @@
#include "Language.h"
#include <wtf/HashMap.h>
+#include <wtf/NeverDestroyed.h>
#include <wtf/RetainPtr.h>
#include <wtf/text/WTFString.h>
@@ -39,8 +40,8 @@
typedef HashMap<void*, LanguageChangeObserverFunction> ObserverMap;
static ObserverMap& observerMap()
{
- DEPRECATED_DEFINE_STATIC_LOCAL(ObserverMap, map, ());
- return map;
+ static NeverDestroyed<ObserverMap> map;
+ return map.get();
}
void addLanguageChangeObserver(void* context, LanguageChangeObserverFunction customObserver)
@@ -84,6 +85,7 @@
void overrideUserPreferredLanguages(const Vector<String>& override)
{
preferredLanguagesOverride() = override;
+ languageDidChange();
}
Vector<String> userPreferredLanguages()
Modified: trunk/Source/WebCore/platform/graphics/FontGenericFamilies.cpp (189037 => 189038)
--- trunk/Source/WebCore/platform/graphics/FontGenericFamilies.cpp 2015-08-27 18:03:43 UTC (rev 189037)
+++ trunk/Source/WebCore/platform/graphics/FontGenericFamilies.cpp 2015-08-27 18:09:20 UTC (rev 189038)
@@ -25,6 +25,7 @@
#include "config.h"
#include "FontGenericFamilies.h"
+#include "Language.h"
namespace WebCore {
@@ -46,11 +47,41 @@
return true;
}
+static inline bool computeUserPrefersSimplified()
+{
+ const Vector<String>& preferredLanguages = userPreferredLanguages();
+ for (auto& language : preferredLanguages) {
+ if (equalIgnoringASCIICase(language, "zh-tw"))
+ return false;
+ if (equalIgnoringASCIICase(language, "zh-cn"))
+ return true;
+ }
+ return true;
+}
+
+static bool& cachedUserPrefersSimplified()
+{
+ static bool cached = true;
+ return cached;
+}
+
+static void languageChanged(void*)
+{
+ cachedUserPrefersSimplified() = computeUserPrefersSimplified();
+}
+
static const AtomicString& genericFontFamilyForScript(const ScriptFontFamilyMap& fontMap, UScriptCode script)
{
ScriptFontFamilyMap::const_iterator it = fontMap.find(static_cast<int>(script));
if (it != fontMap.end())
return it->value;
+ // Content using USCRIPT_HAN doesn't tell us if we should be using Simplified Chinese or Traditional Chinese. In the
+ // absence of all other signals, we consult with the user's system preferences.
+ if (script == USCRIPT_HAN) {
+ it = fontMap.find(static_cast<int>(cachedUserPrefersSimplified() ? USCRIPT_SIMPLIFIED_HAN : USCRIPT_TRADITIONAL_HAN));
+ if (it != fontMap.end())
+ return it->value;
+ }
if (script != USCRIPT_COMMON)
return genericFontFamilyForScript(fontMap, USCRIPT_COMMON);
return emptyAtom;
@@ -58,6 +89,8 @@
FontGenericFamilies::FontGenericFamilies()
{
+ addLanguageChangeObserver(this, &languageChanged);
+ languageChanged(nullptr);
}
const AtomicString& FontGenericFamilies::standardFontFamily(UScriptCode script) const
Modified: trunk/Source/WebCore/platform/text/LocaleToScriptMappingDefault.cpp (189037 => 189038)
--- trunk/Source/WebCore/platform/text/LocaleToScriptMappingDefault.cpp 2015-08-27 18:03:43 UTC (rev 189037)
+++ trunk/Source/WebCore/platform/text/LocaleToScriptMappingDefault.cpp 2015-08-27 18:09:20 UTC (rev 189038)
@@ -164,14 +164,14 @@
UScriptCode scriptNameToCode(const String& scriptName)
{
- DEPRECATED_DEFINE_STATIC_LOCAL(ScriptNameCodeMap, scriptNameCodeMap, ());
- if (scriptNameCodeMap.isEmpty()) {
+ static NeverDestroyed<ScriptNameCodeMap> scriptNameCodeMap;
+ if (scriptNameCodeMap.get().isEmpty()) {
for (size_t i = 0; i < sizeof(scriptNameCodeList) / sizeof(ScriptNameCode); ++i)
- scriptNameCodeMap.set(ASCIILiteral(scriptNameCodeList[i].name), scriptNameCodeList[i].code);
+ scriptNameCodeMap.get().set(ASCIILiteral(scriptNameCodeList[i].name), scriptNameCodeList[i].code);
}
- ScriptNameCodeMap::iterator it = scriptNameCodeMap.find(scriptName.lower());
- if (it != scriptNameCodeMap.end())
+ ScriptNameCodeMap::iterator it = scriptNameCodeMap.get().find(scriptName.lower());
+ if (it != scriptNameCodeMap.get().end())
return it->value;
return USCRIPT_INVALID_CODE;
}
@@ -376,7 +376,7 @@
{ "yap", USCRIPT_LATIN },
{ "yo", USCRIPT_LATIN },
{ "za", USCRIPT_LATIN },
- { "zh", USCRIPT_SIMPLIFIED_HAN }, // FIXME: This mapping in incorrect. Instead, we should consult with an external source (such as the user's language preferences).
+ { "zh", USCRIPT_HAN },
{ "zh_hk", USCRIPT_TRADITIONAL_HAN },
{ "zh_tw", USCRIPT_TRADITIONAL_HAN },
{ "zu", USCRIPT_LATIN }