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

This commit is contained in:
Jonathan Kew 2018-04-26 17:08:18 +01:00
Родитель 6ad9a5ee43
Коммит 61950f81db
3 изменённых файлов: 84 добавлений и 40 удалений

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

@ -11,6 +11,9 @@
#include <fontconfig/fcfreetype.h>
#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<gfxFontVariationAxis>& 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<gfxFontVariationInstance>& 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);
}

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

@ -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<gfxFontVariationAxis>& aAxes);
static void
GetVariationInstances(gfxFontEntry* aFontEntry,
const FT_MM_Var* aMMVar,
nsTArray<gfxFontVariationInstance>& aInstances);
};
#endif /* GFX_FT2UTILS_H */

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

@ -1112,56 +1112,20 @@ gfxFontconfigFontEntry::GetMMVar()
void
gfxFontconfigFontEntry::GetVariationAxes(nsTArray<gfxFontVariationAxis>& 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<gfxFontVariationInstance>& 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