Bug 1757578 - For resolving font prefs, accept lang attribute with underscore in place of hyphen separators. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D139951
This commit is contained in:
Jonathan Kew 2022-03-02 13:15:27 +00:00
Родитель aed24dc0b6
Коммит 9f7ae29b2c
3 изменённых файлов: 65 добавлений и 0 удалений

Просмотреть файл

@ -190,6 +190,14 @@ nsStaticAtom* nsLanguageAtomService::GetUncachedLanguageGroup(
Locale loc;
auto result = LocaleParser::TryParse(langStr, loc);
if (!result.isOk()) {
// Did the author (wrongly) use '_' instead of '-' to separate subtags?
// If so, fix it up and re-try parsing.
if (langStr.Contains('_')) {
langStr.ReplaceChar('_', '-');
result = LocaleParser::TryParse(langStr, loc);
}
}
if (result.isOk() && loc.Canonicalize().isOk()) {
// Fill in script subtag if not present.
if (loc.Script().Missing()) {

Просмотреть файл

@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<style>
body {
font: 32px sans-serif;
}
.description {
font: 16px serif;
}
div {
position: relative;
height: 3em;
}
div p {
position: absolute;
color: red;
}
p + p {
color: green;
}
.red {
color: red;
}
.green {
color: green;
}
</style>
<body>
<p class=description>In each line, the <span class=green>green</span> glyphs should exactly overlay the <span class=red>red</span> ones:</p>
</body>
<script>
// Some ideographs that should have lang-specific font variants (examples found in
// https://en.wikipedia.org/wiki/Han_unification).
const doingTest = (location.search != "?ref");
const testStr = "今令免入全关具刃化外情才抵次海直真示神空者草蔥角道雇骨";
["zh-CN", "zh-HK", "zh-TW", "ja-JP", "ko-KR"].forEach((lang) => {
let div = document.createElement("div");
document.body.appendChild(div);
// Create two layers of text, red and then green. In the test rendering, one layer
// has the "correct" lang tag, and the other has an ill-formed version with underscore;
// nevertheless we want it to render identically.
let p1 = document.createElement("p");
p1.lang = lang;
p1.textContent = testStr;
div.appendChild(p1);
if (doingTest) {
lang = lang.replace("-", "_");
}
let p2 = document.createElement("p");
p2.lang = lang;
p2.textContent = testStr;
div.appendChild(p2);
});
</script>

Просмотреть файл

@ -176,5 +176,7 @@ skip-if(!cocoaWidget) == osaka-mono-exists.html osaka-mono-exists-ref.html
random-if(!winWidget&&!cocoaWidget) == wingdings-1.html wingdings-1-ref.html
random-if(!winWidget&&!cocoaWidget) != wingdings-1.html wingdings-1-notref.html
== illformed-lang-tags-1.html illformed-lang-tags-1.html?ref
# Reset default prefs.
defaults