Bug 1273154 - Re-land followup to handle word-initial NNBSP shaping in Mongolian, with its reftest. r=jrmuizel

This commit is contained in:
Jonathan Kew 2016-05-25 10:51:13 +01:00
Родитель d63df96367
Коммит 1233cee71f
4 изменённых файлов: 70 добавлений и 6 удалений

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

@ -2637,17 +2637,37 @@ gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh, uint32_t aNextCh,
Script aRunScript, gfxFont *aPrevMatchedFont,
uint8_t *aMatchType)
{
// If the char is a cluster extender or NNBSP, we want to use the same
// font as the preceding character if possible. This is preferable to using
// the font group because it avoids breaks in shaping within a cluster.
const uint32_t NARROW_NO_BREAK_SPACE = 0x202f;
if (aPrevMatchedFont &&
(IsClusterExtender(aCh) || aCh == NARROW_NO_BREAK_SPACE) &&
// If the char is a cluster extender, we want to use the same font as the
// preceding character if possible. This is preferable to using the font
// group because it avoids breaks in shaping within a cluster.
if (aPrevMatchedFont && IsClusterExtender(aCh) &&
aPrevMatchedFont->HasCharacter(aCh)) {
RefPtr<gfxFont> ret = aPrevMatchedFont;
return ret.forget();
}
// Special cases for NNBSP (as used in Mongolian):
const uint32_t NARROW_NO_BREAK_SPACE = 0x202f;
if (aCh == NARROW_NO_BREAK_SPACE) {
// If there is no preceding character, try the font that we'd use
// for the next char (unless it's just another NNBSP; we don't try
// to look ahead through a whole run of them).
if (!aPrevCh && aNextCh && aNextCh != NARROW_NO_BREAK_SPACE) {
RefPtr<gfxFont> nextFont =
FindFontForChar(aNextCh, 0, 0, aRunScript, aPrevMatchedFont,
aMatchType);
if (nextFont && nextFont->HasCharacter(aCh)) {
return nextFont.forget();
}
}
// Otherwise, treat NNBSP like a cluster extender (as above) and try
// to continue the preceding font run.
if (aPrevMatchedFont && aPrevMatchedFont->HasCharacter(aCh)) {
RefPtr<gfxFont> ret = aPrevMatchedFont;
return ret.forget();
}
}
// To optimize common cases, try the first font in the font-group
// before going into the more detailed checks below
uint32_t nextIndex = 0;

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

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<style>
body {
/* Force a large line-height so that we don't get a positioning
discrepancy on the test span depending on which font's metrics
are used in line-height computation. */
font: 64px/2 serif;
}
span {
font-family: "Mongolian Baiti", "Times New Roman", serif;
font-size: 32px;
}
</style>
</head>
<body>
<span>&#x202F;&#x1824;&#x1828;</span>
</body>
</html>

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

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<style>
body {
/* Force a large line-height so that we don't get a positioning
discrepancy on the test span depending on which font's metrics
are used in line-height computation. */
font: 64px/2 serif;
}
span {
/* Times does NOT support Mongolian characters, so the entire text
should be rendered as a single Mongolian Baiti run, including
the initial U+202F, even though it _is_ available in Times. */
font-family: "Times New Roman", "Mongolian Baiti", serif;
font-size: 32px;
}
</style>
</head>
<body>
<span>&#x202F;&#x1824;&#x1828;</span>
</body>
</html>

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

@ -1954,4 +1954,5 @@ fuzzy(100,2000) == 1239564.html 1239564-ref.html
== 1260543-1.html 1260543-1-ref.html
== 1272997-1.html 1272997-1-ref.html
random-if(!winWidget) == 1273154-1.html 1273154-1-ref.html # depends on Windows font
random-if(!winWidget) == 1273154-2.html 1273154-2-ref.html # depends on Windows font
== 1274368-1.html 1274368-1-ref.html