Bug 1457103 - patch 3 - Make gfxFontEntry::GetVariationAxes and GetVariationInstances pure virtual, and provide missing subclass implementations. r=jwatt

This commit is contained in:
Jonathan Kew 2018-04-26 17:08:18 +01:00
parent 61950f81db
commit d384879f12
5 changed files with 65 additions and 8 deletions

View File

@ -635,6 +635,43 @@ FT2FontEntry::HasVariations()
return mHasVariations;
}
void
FT2FontEntry::GetVariationAxes(nsTArray<gfxFontVariationAxis>& aAxes)
{
if (!HasVariations()) {
return;
}
AutoFTFace face(this);
if (!face) {
return;
}
FT_MM_Var* mmVar;
if (FT_Err_Ok != (FT_Get_MM_Var(face, &mmVar))) {
return;
}
gfxFT2Utils::GetVariationAxes(mmVar, aAxes);
FT_Done_MM_Var(FT_Face(face)->glyph->library, mmVar);
}
void
FT2FontEntry::GetVariationInstances(
nsTArray<gfxFontVariationInstance>& aInstances)
{
if (!HasVariations()) {
return;
}
AutoFTFace face(this);
if (!face) {
return;
}
FT_MM_Var* mmVar;
if (FT_Err_Ok != (FT_Get_MM_Var(face, &mmVar))) {
return;
}
gfxFT2Utils::GetVariationInstances(this, mmVar, aInstances);
FT_Done_MM_Var(FT_Face(face)->glyph->library, mmVar);
}
void
FT2FontEntry::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
FontListSizes* aSizes) const

View File

@ -88,6 +88,8 @@ public:
nsTArray<uint8_t>& aBuffer) override;
bool HasVariations() override;
void GetVariationAxes(nsTArray<gfxFontVariationAxis>& aVariationAxes) override;
void GetVariationInstances(nsTArray<gfxFontVariationInstance>& aInstances) override;
// Check for various kinds of brokenness, and set flags on the entry
// accordingly so that we avoid using bad font tables

View File

@ -365,14 +365,19 @@ public:
bool SupportsScriptInGSUB(const hb_tag_t* aScriptTags);
// For variation font support; default implementations assume it is not present.
/**
* Font-variation query methods.
*
* Font backends that don't support variations should provide empty
* implementations.
*/
virtual bool HasVariations() = 0;
virtual void GetVariationAxes(nsTArray<gfxFontVariationAxis>& aVariationAxes)
{
}
virtual void GetVariationInstances(nsTArray<gfxFontVariationInstance>& aInstances)
{
}
virtual void
GetVariationAxes(nsTArray<gfxFontVariationAxis>& aVariationAxes) = 0;
virtual void
GetVariationInstances(nsTArray<gfxFontVariationInstance>& aInstances) = 0;
// Set up the entry's weight/stretch/style ranges according to axes found
// by GetVariationAxes (for installed fonts; do NOT call this for user

View File

@ -163,7 +163,10 @@ public:
gfxFontEntry* Clone() const override;
// GDI backend doesn't support font variations:
bool HasVariations() override { return false; }
void GetVariationAxes(nsTArray<gfxFontVariationAxis>&) override {}
void GetVariationInstances(nsTArray<gfxFontVariationInstance>&) override {}
// create a font entry for a font with a given name
static GDIFontEntry* CreateFontEntry(const nsAString& aName,

View File

@ -639,7 +639,17 @@ public:
return mSrcList;
}
bool HasVariations() override { return false; }
// The variation-query APIs should not be called on placeholders.
bool HasVariations() override {
MOZ_ASSERT_UNREACHABLE("not meaningful for a userfont placeholder");
return false;
}
void GetVariationAxes(nsTArray<gfxFontVariationAxis>&) override {
MOZ_ASSERT_UNREACHABLE("not meaningful for a userfont placeholder");
}
void GetVariationInstances(nsTArray<gfxFontVariationInstance>&) override {
MOZ_ASSERT_UNREACHABLE("not meaningful for a userfont placeholder");
}
protected:
const uint8_t* SanitizeOpenTypeData(const uint8_t* aData,