Bug 1664151 - Drop FC_CHARSET element from fontconfig patterns for TrueType/OpenType fonts, as we will read the cmap directly anyhow. r=lsalzman

Differential Revision: https://phabricator.services.mozilla.com/D117423
This commit is contained in:
Jonathan Kew 2021-06-10 16:13:39 +00:00
Родитель 1135b0ea6b
Коммит 74aef88b56
2 изменённых файлов: 21 добавлений и 1 удалений

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

@ -287,7 +287,12 @@ class FontList {
// systems, and memory is more constrained, so use a smaller default block
// size.
static constexpr uint32_t SHM_BLOCK_SIZE = 64 * 1024;
#elif XP_LINUX
// On Linux, font face descriptors are rather large (serialized FcPatterns),
// so use a larger block size for efficiency.
static constexpr uint32_t SHM_BLOCK_SIZE = 1024 * 1024;
#else
// Default block size for Windows and macOS.
static constexpr uint32_t SHM_BLOCK_SIZE = 256 * 1024;
#endif
static_assert(SHM_BLOCK_SIZE <= (1 << Pointer::kBlockShift),

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

@ -1781,7 +1781,22 @@ void gfxFcPlatformFontList::InitSharedFontListForPlatform() {
}
#endif
addPattern(pattern, lastFamilyName, familyName, aAppFonts);
// If this is a TrueType or OpenType font, discard the FC_CHARSET object
// (which may be very large), because we'll read the 'cmap' directly.
// This substantially reduces the pressure on shared memory (bug 1664151)
// due to the large font descriptors (serialized patterns).
FcChar8* fontFormat;
if (FcPatternGetString(pattern, FC_FONTFORMAT, 0, &fontFormat) ==
FcResultMatch &&
(!FcStrCmp(fontFormat, (const FcChar8*)"TrueType") ||
!FcStrCmp(fontFormat, (const FcChar8*)"CFF"))) {
FcPattern* clone = FcPatternDuplicate(pattern);
FcPatternDel(clone, FC_CHARSET);
addPattern(clone, lastFamilyName, familyName, aAppFonts);
FcPatternDestroy(clone);
} else {
addPattern(pattern, lastFamilyName, familyName, aAppFonts);
}
}
};