Bug 1454598 - part 2.1 - For system-installed fonts, query FC_VARIABLE to determine if a face has variations rather than instantiating a FT_Face. r=lsalzman

This commit is contained in:
Jonathan Kew 2018-04-25 07:18:23 +01:00
Родитель 8ff8fafa15
Коммит c75bb6f48d
2 изменённых файлов: 34 добавлений и 4 удалений

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

@ -58,6 +58,9 @@ using mozilla::dom::FontPatternListEntry;
#ifndef FC_POSTSCRIPT_NAME #ifndef FC_POSTSCRIPT_NAME
#define FC_POSTSCRIPT_NAME "postscriptname" /* String */ #define FC_POSTSCRIPT_NAME "postscriptname" /* String */
#endif #endif
#ifndef FC_VARIABLE
#define FC_VARIABLE "variable" /* Bool */
#endif
#define PRINTING_FC_PROPERTY "gfx.printing" #define PRINTING_FC_PROPERTY "gfx.printing"
@ -233,6 +236,7 @@ gfxFontconfigFontEntry::gfxFontconfigFontEntry(const nsAString& aFaceName,
: gfxFontEntry(aFaceName), mFontPattern(aFontPattern), : gfxFontEntry(aFaceName), mFontPattern(aFontPattern),
mFTFace(nullptr), mFTFaceInitialized(false), mFTFace(nullptr), mFTFaceInitialized(false),
mIgnoreFcCharmap(aIgnoreFcCharmap), mIgnoreFcCharmap(aIgnoreFcCharmap),
mHasVariationsInitialized(false),
mAspect(0.0), mFontData(nullptr), mLength(0) mAspect(0.0), mFontData(nullptr), mLength(0)
{ {
// italic // italic
@ -321,6 +325,7 @@ gfxFontconfigFontEntry::gfxFontconfigFontEntry(const nsAString& aFaceName,
: gfxFontEntry(aFaceName), : gfxFontEntry(aFaceName),
mFTFace(aFace), mFTFaceInitialized(true), mFTFace(aFace), mFTFaceInitialized(true),
mIgnoreFcCharmap(true), mIgnoreFcCharmap(true),
mHasVariationsInitialized(false),
mAspect(0.0), mFontData(aData), mLength(aLength) mAspect(0.0), mFontData(aData), mLength(aLength)
{ {
mWeight = aWeight; mWeight = aWeight;
@ -340,6 +345,7 @@ gfxFontconfigFontEntry::gfxFontconfigFontEntry(const nsAString& aFaceName,
FontSlantStyle aStyle) FontSlantStyle aStyle)
: gfxFontEntry(aFaceName), mFontPattern(aFontPattern), : gfxFontEntry(aFaceName), mFontPattern(aFontPattern),
mFTFace(nullptr), mFTFaceInitialized(false), mFTFace(nullptr), mFTFaceInitialized(false),
mHasVariationsInitialized(false),
mAspect(0.0), mFontData(nullptr), mLength(0) mAspect(0.0), mFontData(nullptr), mLength(0)
{ {
mWeight = aWeight; mWeight = aWeight;
@ -1064,11 +1070,28 @@ gfxFontconfigFontEntry::GetFTFace()
bool bool
gfxFontconfigFontEntry::HasVariations() gfxFontconfigFontEntry::HasVariations()
{ {
FT_Face face = GetFTFace(); if (mHasVariationsInitialized) {
if (face) { return mHasVariations;
return face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS;
} }
return false; mHasVariationsInitialized = true;
mHasVariations = false;
// For installed fonts, query the fontconfig pattern rather than paying
// the cost of loading a FT_Face that we otherwise might never need.
if (!IsUserFont() || IsLocalUserFont()) {
FcBool variable;
if ((FcPatternGetBool(mFontPattern, FC_VARIABLE, 0,
&variable) == FcResultMatch) && variable) {
mHasVariations = true;
}
} else {
FT_Face face = GetFTFace();
if (face) {
mHasVariations = face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS;
}
}
return mHasVariations;
} }
FT_MM_Var* FT_MM_Var*

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

@ -168,6 +168,13 @@ protected:
// loaded via @font-face. // loaded via @font-face.
bool mIgnoreFcCharmap; bool mIgnoreFcCharmap;
// Whether the face supports variations. For system-installed fonts, we
// query fontconfig for this (so they will only work if fontconfig is
// recent enough to include support); for downloaded user-fonts we query
// the FreeType face.
bool mHasVariations;
bool mHasVariationsInitialized;
double mAspect; double mAspect;
// data font // data font