Bug 1427641 - patch 2 - Convert variation values into FreeType's data type, and apply them to the FT_Face. r=lsalzman

This commit is contained in:
Jonathan Kew 2017-12-06 14:42:42 +00:00
parent 7ef5a362b4
commit 5080cdedd5
2 changed files with 40 additions and 0 deletions

View File

@ -10,10 +10,12 @@
#include "gfxFontConstants.h"
#include "gfxFontUtils.h"
#include <algorithm>
#include <dlfcn.h>
#include FT_TRUETYPE_TAGS_H
#include FT_TRUETYPE_TABLES_H
#include FT_ADVANCES_H
#include FT_MULTIPLE_MASTERS_H
#ifndef FT_FACE_FLAG_COLOR
#define FT_FACE_FLAG_COLOR ( 1L << 14 )
@ -205,6 +207,37 @@ gfxFT2FontBase::InitMetrics()
return;
}
// For variation fonts, figure out the variation coordinates to be applied
// for each axis, in freetype's order (which may not match the order of
// axes in mStyle.variationSettings, so we need to search by axis tag).
if (face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS) {
typedef FT_UInt (*GetVarFunc)(FT_Face, FT_MM_Var**);
typedef FT_UInt (*SetCoordsFunc)(FT_Face, FT_UInt, FT_Fixed*);
static GetVarFunc getVar =
(GetVarFunc)dlsym(RTLD_DEFAULT, "FT_Get_MM_Var");
static SetCoordsFunc setCoords =
(SetCoordsFunc)dlsym(RTLD_DEFAULT, "FT_Set_Var_Design_Coordinates");
FT_MM_Var* ftVar;
if (getVar && setCoords && FT_Err_Ok == (*getVar)(face, &ftVar)) {
for (unsigned i = 0; i < ftVar->num_axis; ++i) {
mCoords.AppendElement(ftVar->axis[i].def);
for (const auto& v : mStyle.variationSettings) {
if (ftVar->axis[i].tag == v.mTag) {
FT_Fixed val = v.mValue * 0x10000;
val = std::min(val, ftVar->axis[i].maximum);
val = std::max(val, ftVar->axis[i].minimum);
mCoords[i] = val;
break;
}
}
}
free(ftVar);
if (!mCoords.IsEmpty()) {
(*setCoords)(face, mCoords.Length(), mCoords.Elements());
}
}
}
const FT_Size_Metrics& ftMetrics = face->size->metrics;
mMetrics.maxAscent = FLOAT_FROM_26_6(ftMetrics.ascender);

View File

@ -49,6 +49,13 @@ protected:
Metrics mMetrics;
bool mEmbolden;
// For variation/multiple-master fonts, this will be an array of the values
// for each axis, as specified by mStyle.variationSettings (or the font's
// default for axes not present in variationSettings). Values here are in
// freetype's 16.16 fixed-point format, and clamped to the valid min/max
// range reported by the face.
nsTArray<FT_Fixed> mCoords;
mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey,int32_t>> mGlyphWidths;
};