Bug 1673098 - Ensure we use our implementation of the get_nominal_glyph callback when shaping a CFF font, so that hyphen fallbacks can take effect. r=lsalzman

CLOSED TREE

Differential Revision: https://phabricator.services.mozilla.com/D94681
This commit is contained in:
Jonathan Kew 2020-10-26 05:33:06 +00:00
Родитель db195fbaa4
Коммит eae3c7f86f
4 изменённых файлов: 46 добавлений и 5 удалений

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

@ -1114,6 +1114,7 @@ static void AddOpenTypeFeature(const uint32_t& aTag, uint32_t& aValue,
*/
static hb_font_funcs_t* sHBFontFuncs = nullptr;
static hb_font_funcs_t* sNominalGlyphFunc = nullptr;
static hb_unicode_funcs_t* sHBUnicodeFuncs = nullptr;
static const hb_script_t sMathScript =
hb_ot_tag_to_script(HB_TAG('m', 'a', 't', 'h'));
@ -1145,6 +1146,12 @@ bool gfxHarfBuzzShaper::Initialize() {
nullptr, nullptr);
hb_font_funcs_set_glyph_h_kerning_func(sHBFontFuncs, HBGetHKerning, nullptr,
nullptr);
hb_font_funcs_make_immutable(sHBFontFuncs);
sNominalGlyphFunc = hb_font_funcs_create();
hb_font_funcs_set_nominal_glyph_func(sNominalGlyphFunc, HBGetNominalGlyph,
nullptr, nullptr);
hb_font_funcs_make_immutable(sNominalGlyphFunc);
sHBUnicodeFuncs = hb_unicode_funcs_create(hb_unicode_funcs_get_empty());
hb_unicode_funcs_set_mirroring_func(sHBUnicodeFuncs, HBGetMirroring,
@ -1159,6 +1166,7 @@ bool gfxHarfBuzzShaper::Initialize() {
nullptr, nullptr);
hb_unicode_funcs_set_decompose_func(sHBUnicodeFuncs, HBUnicodeDecompose,
nullptr, nullptr);
hb_unicode_funcs_make_immutable(sHBUnicodeFuncs);
UErrorCode error = U_ZERO_ERROR;
sNormalizer = unorm2_getNFCInstance(&error);
@ -1195,7 +1203,11 @@ bool gfxHarfBuzzShaper::Initialize() {
hb_buffer_set_cluster_level(mBuffer,
HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS);
mHBFont = CreateHBFont(mFont, sHBFontFuncs, &mCallbackData);
auto* funcs =
mFont->GetFontEntry()->HasFontTable(TRUETYPE_TAG('C', 'F', 'F', ' '))
? sNominalGlyphFunc
: sHBFontFuncs;
mHBFont = CreateHBFont(mFont, funcs, &mCallbackData);
return true;
}
@ -1207,10 +1219,12 @@ hb_font_t* gfxHarfBuzzShaper::CreateHBFont(gfxFont* aFont,
hb_font_t* result = hb_font_create(hbFace);
hb_face_destroy(hbFace);
if (!aFontFuncs || !aCallbackData ||
aFont->GetFontEntry()->HasFontTable(TRUETYPE_TAG('C', 'F', 'F', ' '))) {
hb_ot_font_set_funcs(result);
} else {
if (aFontFuncs && aCallbackData) {
if (aFontFuncs == sNominalGlyphFunc) {
hb_font_t* subfont = hb_font_create_sub_font(result);
hb_font_destroy(result);
result = subfont;
}
hb_font_set_funcs(result, aFontFuncs, aCallbackData, nullptr);
}
hb_font_set_ppem(result, aFont->GetAdjustedSize(), aFont->GetAdjustedSize());

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

@ -0,0 +1,13 @@
<!DOCTYPE html>
<meta charset=utf-8>
<style>
@font-face {
font-family: "Chunkfive";
src: url("../fonts/Chunkfive.otf");
}
:root {
font-family: "Chunkfive", monospace;
font-size: 2rem;
}
</style>
Foo-bar-baz.

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

@ -0,0 +1,13 @@
<!DOCTYPE html>
<meta charset=utf-8>
<style>
@font-face {
font-family: "Chunkfive";
src: url("../fonts/Chunkfive.otf");
}
:root {
font-family: "Chunkfive", monospace;
font-size: 2rem;
}
</style>
Foo&#x2010;bar&#x2011;baz.

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

@ -194,6 +194,7 @@ fuzzy-if(!webrender,12-66,288-1681) fails-if(gtkWidget&&!webrender) == 1522857-1
!= 1637405-pua-shaping-1.html 1637405-pua-shaping-1-notref.html
fuzzy-if(!webrender,0-42,0-1553) fuzzy-if(gtkWidget&&!webrender,0-255,0-50) == 1655364-1.html 1655364-1-ref.html
== 1670581-1.html 1670581-1-ref.html
== 1673098-1.html 1673098-1-ref.html
# ensure emoji chars don't render blank (bug 715798, bug 779042);
# should at least render hexboxes if there's no font support