|
@@ -1,22 +1,26 @@
|
|
|
|
|
|
#include "import-font.h"
|
|
#include "import-font.h"
|
|
|
|
|
|
-#include <cstdlib>
|
|
|
|
-#include <queue>
|
|
|
|
|
|
+#include <cstring>
|
|
|
|
+#include <vector>
|
|
#include <ft2build.h>
|
|
#include <ft2build.h>
|
|
#include FT_FREETYPE_H
|
|
#include FT_FREETYPE_H
|
|
#include FT_OUTLINE_H
|
|
#include FT_OUTLINE_H
|
|
|
|
+#include FT_MULTIPLE_MASTERS_H
|
|
|
|
|
|
namespace msdfgen {
|
|
namespace msdfgen {
|
|
|
|
|
|
-#define REQUIRE(cond) { if (!(cond)) return false; }
|
|
|
|
#define F26DOT6_TO_DOUBLE(x) (1/64.*double(x))
|
|
#define F26DOT6_TO_DOUBLE(x) (1/64.*double(x))
|
|
|
|
+#define F16DOT16_TO_DOUBLE(x) (1/65536.*double(x))
|
|
|
|
+#define DOUBLE_TO_F16DOT16(x) FT_Fixed(65536.*x)
|
|
|
|
|
|
class FreetypeHandle {
|
|
class FreetypeHandle {
|
|
friend FreetypeHandle * initializeFreetype();
|
|
friend FreetypeHandle * initializeFreetype();
|
|
friend void deinitializeFreetype(FreetypeHandle *library);
|
|
friend void deinitializeFreetype(FreetypeHandle *library);
|
|
friend FontHandle * loadFont(FreetypeHandle *library, const char *filename);
|
|
friend FontHandle * loadFont(FreetypeHandle *library, const char *filename);
|
|
friend FontHandle * loadFontData(FreetypeHandle *library, const byte *data, int length);
|
|
friend FontHandle * loadFontData(FreetypeHandle *library, const byte *data, int length);
|
|
|
|
+ friend bool setFontVariationAxis(FreetypeHandle *library, FontHandle *font, const char *name, double coordinate);
|
|
|
|
+ friend bool listFontVariationAxes(std::vector<FontVariationAxis> &axes, FreetypeHandle *library, FontHandle *font);
|
|
|
|
|
|
FT_Library library;
|
|
FT_Library library;
|
|
|
|
|
|
@@ -34,6 +38,8 @@ class FontHandle {
|
|
friend bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *advance);
|
|
friend bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *advance);
|
|
friend bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex1, GlyphIndex glyphIndex2);
|
|
friend bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex1, GlyphIndex glyphIndex2);
|
|
friend bool getKerning(double &output, FontHandle *font, unicode_t unicode1, unicode_t unicode2);
|
|
friend bool getKerning(double &output, FontHandle *font, unicode_t unicode1, unicode_t unicode2);
|
|
|
|
+ friend bool setFontVariationAxis(FreetypeHandle *library, FontHandle *font, const char *name, double coordinate);
|
|
|
|
+ friend bool listFontVariationAxes(std::vector<FontVariationAxis> &axes, FreetypeHandle *library, FontHandle *font);
|
|
|
|
|
|
FT_Face face;
|
|
FT_Face face;
|
|
bool ownership;
|
|
bool ownership;
|
|
@@ -215,4 +221,48 @@ bool getKerning(double &output, FontHandle *font, unicode_t unicode1, unicode_t
|
|
return getKerning(output, font, GlyphIndex(FT_Get_Char_Index(font->face, unicode1)), GlyphIndex(FT_Get_Char_Index(font->face, unicode2)));
|
|
return getKerning(output, font, GlyphIndex(FT_Get_Char_Index(font->face, unicode1)), GlyphIndex(FT_Get_Char_Index(font->face, unicode2)));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+bool setFontVariationAxis(FreetypeHandle *library, FontHandle *font, const char *name, double coordinate) {
|
|
|
|
+ bool success = false;
|
|
|
|
+ if (font->face->face_flags&FT_FACE_FLAG_MULTIPLE_MASTERS) {
|
|
|
|
+ FT_MM_Var *master = NULL;
|
|
|
|
+ if (FT_Get_MM_Var(font->face, &master))
|
|
|
|
+ return false;
|
|
|
|
+ if (master && master->num_axis) {
|
|
|
|
+ std::vector<FT_Fixed> coords(master->num_axis);
|
|
|
|
+ if (!FT_Get_Var_Design_Coordinates(font->face, FT_UInt(coords.size()), &coords[0])) {
|
|
|
|
+ for (FT_UInt i = 0; i < master->num_axis; ++i) {
|
|
|
|
+ if (!strcmp(name, master->axis[i].name)) {
|
|
|
|
+ coords[i] = DOUBLE_TO_F16DOT16(coordinate);
|
|
|
|
+ success = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (FT_Set_Var_Design_Coordinates(font->face, FT_UInt(coords.size()), &coords[0]))
|
|
|
|
+ success = false;
|
|
|
|
+ }
|
|
|
|
+ FT_Done_MM_Var(library->library, master);
|
|
|
|
+ }
|
|
|
|
+ return success;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool listFontVariationAxes(std::vector<FontVariationAxis> &axes, FreetypeHandle *library, FontHandle *font) {
|
|
|
|
+ if (font->face->face_flags&FT_FACE_FLAG_MULTIPLE_MASTERS) {
|
|
|
|
+ FT_MM_Var *master = NULL;
|
|
|
|
+ if (FT_Get_MM_Var(font->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 = master->axis[i].minimum;
|
|
|
|
+ axis.maxValue = master->axis[i].maximum;
|
|
|
|
+ axis.defaultValue = master->axis[i].def;
|
|
|
|
+ }
|
|
|
|
+ FT_Done_MM_Var(library->library, master);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
}
|
|
}
|