mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 23:05:42 +00:00
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:
parent
7ef5a362b4
commit
5080cdedd5
@ -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);
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user