From 61950f81db4d1b684a48271eff3bb699d3746775 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Thu, 26 Apr 2018 17:08:18 +0100 Subject: [PATCH] Bug 1457103 - patch 2 - Refactor logic from gfxFontconfigFontEntry implementations of GetVariationAxes and GetVariationInstances to gfxFT2Utils, where it can be shared by the gfxFT2Fonts backend. r=jwatt --- gfx/thebes/gfxFT2Utils.cpp | 62 ++++++++++++++++++++++++++++ gfx/thebes/gfxFT2Utils.h | 18 ++++++++ gfx/thebes/gfxFcPlatformFontList.cpp | 44 ++------------------ 3 files changed, 84 insertions(+), 40 deletions(-) diff --git a/gfx/thebes/gfxFT2Utils.cpp b/gfx/thebes/gfxFT2Utils.cpp index 1f28feb1fd9c..85f6a26c3490 100644 --- a/gfx/thebes/gfxFT2Utils.cpp +++ b/gfx/thebes/gfxFT2Utils.cpp @@ -11,6 +11,9 @@ #include #endif +#include "ft2build.h" +#include FT_MULTIPLE_MASTERS_H + #include "prlink.h" uint32_t @@ -96,3 +99,62 @@ gfxFT2LockedFace::FindCharVariantFunction() return function; } + +/*static*/ +void +gfxFT2Utils::GetVariationAxes(const FT_MM_Var* aMMVar, + nsTArray& aAxes) +{ + MOZ_ASSERT(aAxes.IsEmpty()); + if (!aMMVar) { + return; + } + aAxes.SetCapacity(aMMVar->num_axis); + for (unsigned i = 0; i < aMMVar->num_axis; i++) { + const auto& a = aMMVar->axis[i]; + gfxFontVariationAxis axis; + axis.mMinValue = a.minimum / 65536.0; + axis.mMaxValue = a.maximum / 65536.0; + axis.mDefaultValue = a.def / 65536.0; + axis.mTag = a.tag; + axis.mName.Assign(NS_ConvertUTF8toUTF16(a.name)); + aAxes.AppendElement(axis); + } +} + +/*static*/ +void +gfxFT2Utils::GetVariationInstances( + gfxFontEntry* aFontEntry, + const FT_MM_Var* aMMVar, + nsTArray& aInstances) +{ + MOZ_ASSERT(aInstances.IsEmpty()); + if (!aMMVar) { + return; + } + hb_blob_t* nameTable = + aFontEntry->GetFontTable(TRUETYPE_TAG('n','a','m','e')); + if (!nameTable) { + return; + } + aInstances.SetCapacity(aMMVar->num_namedstyles); + for (unsigned i = 0; i < aMMVar->num_namedstyles; i++) { + const auto& ns = aMMVar->namedstyle[i]; + gfxFontVariationInstance inst; + nsresult rv = + gfxFontUtils::ReadCanonicalName(nameTable, ns.strid, inst.mName); + if (NS_FAILED(rv)) { + continue; + } + inst.mValues.SetCapacity(aMMVar->num_axis); + for (unsigned j = 0; j < aMMVar->num_axis; j++) { + gfxFontVariationValue value; + value.mAxis = aMMVar->axis[j].tag; + value.mValue = ns.coords[j] / 65536.0; + inst.mValues.AppendElement(value); + } + aInstances.AppendElement(inst); + } + hb_blob_destroy(nameTable); +} diff --git a/gfx/thebes/gfxFT2Utils.h b/gfx/thebes/gfxFT2Utils.h index c4b9afb0cbf7..84c7c67586ea 100644 --- a/gfx/thebes/gfxFT2Utils.h +++ b/gfx/thebes/gfxFT2Utils.h @@ -63,4 +63,22 @@ protected: FT_Face mFace; }; + +// A couple of FreeType-based utilities shared by gfxFontconfigFontEntry +// and FT2FontEntry. + +typedef struct FT_MM_Var_ FT_MM_Var; + +class gfxFT2Utils { +public: + static void + GetVariationAxes(const FT_MM_Var* aMMVar, + nsTArray& aAxes); + + static void + GetVariationInstances(gfxFontEntry* aFontEntry, + const FT_MM_Var* aMMVar, + nsTArray& aInstances); +}; + #endif /* GFX_FT2UTILS_H */ diff --git a/gfx/thebes/gfxFcPlatformFontList.cpp b/gfx/thebes/gfxFcPlatformFontList.cpp index 862bda17a08e..5b77875c3035 100644 --- a/gfx/thebes/gfxFcPlatformFontList.cpp +++ b/gfx/thebes/gfxFcPlatformFontList.cpp @@ -1112,56 +1112,20 @@ gfxFontconfigFontEntry::GetMMVar() void gfxFontconfigFontEntry::GetVariationAxes(nsTArray& aAxes) { - MOZ_ASSERT(aAxes.IsEmpty()); - FT_MM_Var* mmVar = GetMMVar(); - if (!mmVar) { + if (!HasVariations()) { return; } - aAxes.SetCapacity(mmVar->num_axis); - for (unsigned i = 0; i < mmVar->num_axis; i++) { - const auto& a = mmVar->axis[i]; - gfxFontVariationAxis axis; - axis.mMinValue = a.minimum / 65536.0; - axis.mMaxValue = a.maximum / 65536.0; - axis.mDefaultValue = a.def / 65536.0; - axis.mTag = a.tag; - axis.mName.Assign(NS_ConvertUTF8toUTF16(a.name)); - aAxes.AppendElement(axis); - } + gfxFT2Utils::GetVariationAxes(GetMMVar(), aAxes); } void gfxFontconfigFontEntry::GetVariationInstances( nsTArray& aInstances) { - MOZ_ASSERT(aInstances.IsEmpty()); - FT_MM_Var* mmVar = GetMMVar(); - if (!mmVar) { + if (!HasVariations()) { return; } - hb_blob_t* nameTable = GetFontTable(TRUETYPE_TAG('n','a','m','e')); - if (!nameTable) { - return; - } - aInstances.SetCapacity(mmVar->num_namedstyles); - for (unsigned i = 0; i < mmVar->num_namedstyles; i++) { - const auto& ns = mmVar->namedstyle[i]; - gfxFontVariationInstance inst; - nsresult rv = - gfxFontUtils::ReadCanonicalName(nameTable, ns.strid, inst.mName); - if (NS_FAILED(rv)) { - continue; - } - inst.mValues.SetCapacity(mmVar->num_axis); - for (unsigned j = 0; j < mmVar->num_axis; j++) { - gfxFontVariationValue value; - value.mAxis = mmVar->axis[j].tag; - value.mValue = ns.coords[j] / 65536.0; - inst.mValues.AppendElement(value); - } - aInstances.AppendElement(inst); - } - hb_blob_destroy(nameTable); + gfxFT2Utils::GetVariationInstances(this, GetMMVar(), aInstances); } nsresult