list font variation axes
This commit is contained in:
parent
bd81be30df
commit
c071d3bd9c
1 changed files with 63 additions and 0 deletions
63
src/Utils.h
63
src/Utils.h
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <glm/glm.hpp>
|
||||
#include <ft2build.h>
|
||||
|
@ -22,6 +23,16 @@ struct FontVariation {
|
|||
float value;
|
||||
};
|
||||
|
||||
#ifndef F26DOT6_TO_DOUBLE
|
||||
#define F26DOT6_TO_DOUBLE(x) (1 / 64. * double(x))
|
||||
#endif
|
||||
#ifndef F16DOT16_TO_DOUBLE
|
||||
#define F16DOT16_TO_DOUBLE(x) (1 / 65536. * double(x))
|
||||
#endif
|
||||
#ifndef DOUBLE_TO_F16DOT16
|
||||
#define DOUBLE_TO_F16DOT16(x) FT_Fixed(65536. * x)
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
inline void hash_combine(std::size_t & seed, const T & v){
|
||||
std::hash <T> hasher;
|
||||
|
@ -71,4 +82,56 @@ void getVFlip(const VFlipBehaviour & vFlipBehaviour,
|
|||
VFlipState & vFlip);
|
||||
|
||||
|
||||
static bool listFontVariationAxes(FT_Library & library,
|
||||
FT_Face & face,
|
||||
std::vector <FontVariationAxis> & axes){
|
||||
if(face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS){
|
||||
FT_MM_Var * master = NULL;
|
||||
if(FT_Get_MM_Var(face, &master)){
|
||||
return false;
|
||||
}
|
||||
axes.resize(master->num_axis);
|
||||
for(FT_UInt i = 0; i < master->num_axis; i++){
|
||||
FontVariationAxis & axis = axes[i];
|
||||
axis.name = master->axis[i].name;
|
||||
axis.minValue = F16DOT16_TO_DOUBLE(master->axis[i].minimum);
|
||||
axis.maxValue = F16DOT16_TO_DOUBLE(master->axis[i].maximum);
|
||||
axis.defaultValue = F16DOT16_TO_DOUBLE(master->axis[i].def);
|
||||
}
|
||||
FT_Done_MM_Var(library, master);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool listFontVariationAxes(std::string fontPath,
|
||||
std::vector <FontVariationAxis> & axes){
|
||||
FT_Library library; /* handle to library */
|
||||
FT_Face face; /* handle to face object */
|
||||
|
||||
FT_Error error = FT_Init_FreeType(&library);
|
||||
if(error){
|
||||
FT_Done_FreeType(library);
|
||||
return false;
|
||||
}
|
||||
error = FT_New_Face(library,
|
||||
fontPath.c_str(),
|
||||
0,
|
||||
&face);
|
||||
if(error == FT_Err_Unknown_File_Format){
|
||||
FT_Done_Face(face);
|
||||
FT_Done_FreeType(library);
|
||||
return false;
|
||||
}else if(error){
|
||||
FT_Done_Face(face);
|
||||
FT_Done_FreeType(library);
|
||||
return false;
|
||||
}
|
||||
bool success = listFontVariationAxes(library, face, axes);
|
||||
// clean the fuck up
|
||||
FT_Done_Face(face);
|
||||
FT_Done_FreeType(library);
|
||||
return success;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue