Bug 1769279 - Disable FT_LOAD_COLOR when getting glyph metrics for fonts that include an SVG table. r=lsalzman

See https://gitlab.freedesktop.org/freetype/freetype/-/issues/1156
for the issue this is addressing.

Differential Revision: https://phabricator.services.mozilla.com/D146318
This commit is contained in:
Jonathan Kew 2022-05-14 06:36:43 +00:00
Родитель ce2f603260
Коммит 80ef7350dc
2 изменённых файлов: 22 добавлений и 2 удалений

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

@ -45,6 +45,13 @@ typedef enum FT_LcdFilter_
# define FT_PIXEL_MODE_BGRA 7
#endif
// If compiling with FreeType before 2.12.0
#ifndef FT_FACE_FLAG_SVG
// We need the format tag so that we can switch on it and handle a possibly-
// newer version of the library at runtime.
static constexpr FT_UInt32 FT_IMAGE_TAG(FT_GLYPH_FORMAT_SVG, 'S', 'V', 'G', ' ');
#endif
#ifndef SK_CAN_USE_DLOPEN
#define SK_CAN_USE_DLOPEN 1
#endif
@ -587,6 +594,10 @@ void SkScalerContext_CairoFT::generateMetrics(SkGlyph* glyph)
fFTFace->glyph->bitmap.rows);
}
break;
case FT_GLYPH_FORMAT_SVG:
// We don't support getting glyph bounds for SVG, but at least the advance
// should be correctly returned, and we don't want to fire an assertion.
break;
default:
SkDEBUGFAIL("unknown glyph format");
return;

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

@ -646,6 +646,17 @@ bool gfxFT2FontBase::GetFTGlyphExtents(uint16_t aGID, int32_t* aAdvance,
if (!aBounds) {
flags |= FT_LOAD_ADVANCE_ONLY;
}
// Whether to disable subpixel positioning
bool roundX = ShouldRoundXOffset(nullptr);
// Workaround for FT_Load_Glyph not setting linearHoriAdvance for SVG glyphs.
// See https://gitlab.freedesktop.org/freetype/freetype/-/issues/1156.
if (!roundX &&
GetFontEntry()->HasFontTable(TRUETYPE_TAG('S', 'V', 'G', ' '))) {
flags &= ~FT_LOAD_COLOR;
}
if (Factory::LoadFTGlyph(face.get(), aGID, flags) != FT_Err_Ok) {
// FT_Face was somehow broken/invalid? Don't try to access glyph slot.
// This probably shouldn't happen, but does: see bug 1440938.
@ -655,8 +666,6 @@ bool gfxFT2FontBase::GetFTGlyphExtents(uint16_t aGID, int32_t* aAdvance,
// Whether to interpret hinting settings (i.e. not printing)
bool hintMetrics = ShouldHintMetrics();
// Whether to disable subpixel positioning
bool roundX = ShouldRoundXOffset(nullptr);
// No hinting disables X and Y hinting. Light disables only X hinting.
bool unhintedY = (mFTLoadFlags & FT_LOAD_NO_HINTING) != 0;
bool unhintedX =