Bug 1796648 - Drop any SVG table from downloaded fonts if OpenType-SVG rendering is disabled. r=gfx-reviewers,lsalzman

This makes e.g. https://nabla.typearture.com/ perform VASTLY better on macOS if OT-SVG is preffed off;
without it, we get bogged down in Core Text internally parsing all the SVG when all we want are the
TrueType outlines.

Differential Revision: https://phabricator.services.mozilla.com/D159888
This commit is contained in:
Jonathan Kew 2022-10-27 20:55:04 +00:00
Родитель c36af6b84f
Коммит c8a2f63e06
4 изменённых файлов: 67 добавлений и 11 удалений

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

@ -102,23 +102,18 @@ class MOZ_STACK_CLASS gfxOTSContext : public ots::OTSContext {
// Whether to preserve color bitmap glyphs
mKeepColorBitmaps =
StaticPrefs::gfx_downloadable_fonts_keep_color_bitmaps();
// Whether to preserve SVG glyphs (which can be expensive in Core Text,
// so better to drop them if we're not going to render them anyhow).
mKeepSVG = StaticPrefs::gfx_font_rendering_opentype_svg_enabled();
}
virtual ots::TableAction GetTableAction(uint32_t aTag) override {
// Preserve Graphite and SVG tables,
// and possibly OTL and Variation tables (depending on prefs)
// Pass through or validate OTL and Variation tables, depending on prefs.
if ((!mCheckOTLTables && (aTag == TRUETYPE_TAG('G', 'D', 'E', 'F') ||
aTag == TRUETYPE_TAG('G', 'P', 'O', 'S') ||
aTag == TRUETYPE_TAG('G', 'S', 'U', 'B')))) {
return ots::TABLE_ACTION_PASSTHRU;
}
if (aTag == TRUETYPE_TAG('S', 'V', 'G', ' ')) {
return ots::TABLE_ACTION_PASSTHRU;
}
if (mKeepColorBitmaps && (aTag == TRUETYPE_TAG('C', 'B', 'D', 'T') ||
aTag == TRUETYPE_TAG('C', 'B', 'L', 'C'))) {
return ots::TABLE_ACTION_PASSTHRU;
}
auto isVariationTable = [](uint32_t aTag) -> bool {
return aTag == TRUETYPE_TAG('a', 'v', 'a', 'r') ||
aTag == TRUETYPE_TAG('c', 'v', 'a', 'r') ||
@ -135,6 +130,14 @@ class MOZ_STACK_CLASS gfxOTSContext : public ots::OTSContext {
if (!gfxPlatform::HasVariationFontSupport() && isVariationTable(aTag)) {
return ots::TABLE_ACTION_DROP;
}
// Preserve SVG table if OpenType-SVG rendering is enabled.
if (aTag == TRUETYPE_TAG('S', 'V', 'G', ' ')) {
return mKeepSVG ? ots::TABLE_ACTION_PASSTHRU : ots::TABLE_ACTION_DROP;
}
if (mKeepColorBitmaps && (aTag == TRUETYPE_TAG('C', 'B', 'D', 'T') ||
aTag == TRUETYPE_TAG('C', 'B', 'L', 'C'))) {
return ots::TABLE_ACTION_PASSTHRU;
}
return ots::TABLE_ACTION_DEFAULT;
}
@ -169,6 +172,7 @@ class MOZ_STACK_CLASS gfxOTSContext : public ots::OTSContext {
bool mCheckOTLTables;
bool mCheckVariationTables;
bool mKeepColorBitmaps;
bool mKeepSVG;
};
#endif /* GFX_OTS_UTILS_H */

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

@ -1,9 +1,9 @@
defaults pref(gfx.font_rendering.opentype_svg.enabled,true)
pref(gfx.font_rendering.opentype_svg.enabled,false) != svg-glyph-basic.svg svg-glyph-basic-ref.svg
pref(gfx.font_rendering.opentype_svg.enabled,false) != svg-glyph-basic-disabled.svg svg-glyph-basic-ref.svg
fuzzy(0-1,0-200) == svg-glyph-basic.svg svg-glyph-basic-ref.svg
== svg-glyph-invalid-ids.svg svg-glyph-invalid-ids-ref.svg
pref(gfx.font_rendering.opentype_svg.enabled,false) != svg-glyph-positioning.svg svg-glyph-positioning-ref.svg
pref(gfx.font_rendering.opentype_svg.enabled,false) != svg-glyph-positioning-disabled.svg svg-glyph-positioning-ref.svg
fuzzy(0-2,0-350) == svg-glyph-positioning.svg svg-glyph-positioning-ref.svg
== svg-glyph-html.html svg-glyph-html-ref.svg
== svg-glyph-direct.svg svg-glyph-direct-ref.svg

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

@ -0,0 +1,27 @@
<svg xmlns="http://www.w3.org/2000/svg">
<style type="text/css">
<![CDATA[
@font-face {
font-family: "Liberation";
/* For testing with the pref disabled, add a query to the font URL
to avoid cache confusion between enabled/disabled. */
src:url(resources/svg.woff?disabled);
}
text
{
font-family: Liberation;
font-size: 200px;
stroke: black;
}
]]>
</style>
<!--
Test that SVG glyphs are being drawn instead of TrueType glyphs
Also testing that this does not happen if the
gfx.font_rendering.opentype_svg.enabled preference is set to true.
-->
<!-- glyphid -->
<text x="0" y="200">
L
</text>
</svg>

После

Ширина:  |  Высота:  |  Размер: 728 B

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

@ -0,0 +1,25 @@
<svg xmlns="http://www.w3.org/2000/svg">
<style type="text/css">
<![CDATA[
@font-face {
font-family: "Liberation";
/* For testing with the pref disabled, add a query to the font URL
to avoid cache confusion between enabled/disabled. */
src:url(resources/svg.woff?disabled);
}
text
{
font-family: Liberation;
font-size: 200px;
stroke: black;
}
]]>
</style>
<!--
Test that we're rendering in the right place in the middle of a
text run
-->
<text x="0" y="200">
LLL
</text>
</svg>

После

Ширина:  |  Высота:  |  Размер: 601 B