Added hidden option to disable variable fonts

This commit is contained in:
Chlumsky 2023-04-12 18:04:01 +02:00
parent 5eef2e5985
commit d576034d22
7 changed files with 31 additions and 7 deletions

View File

@ -147,6 +147,9 @@ if(NOT MSDFGEN_CORE_ONLY)
else()
target_compile_definitions(msdfgen-ext PUBLIC MSDFGEN_DISABLE_PNG)
endif()
if(MSDFGEN_DISABLE_VARIABLE_FONTS)
target_compile_definitions(msdfgen-ext PUBLIC MSDFGEN_DISABLE_VARIABLE_FONTS)
endif()
target_link_libraries(msdfgen-ext PRIVATE Freetype::Freetype msdfgen::msdfgen-core)
target_include_directories(msdfgen-ext
PUBLIC

View File

@ -215,7 +215,7 @@
"name": "osx-core-dbg",
"configurePreset": "osx-core-dbg"
},
{
"name": "linux-vcpkg-rel",
"configurePreset": "linux-vcpkg-rel"

View File

@ -203,7 +203,7 @@ The text shape description has the following syntax.
- The last point of each contour must be equal to the first, or the symbol `#` can be used, which represents the first point.
- There can be an edge segment specification between any two points, also separated by semicolons.
This can include the edge's color (`c`, `m`, `y` or `w`) and/or one or two Bézier curve control points inside parentheses.
For example,
```
{ -1, -1; m; -1, +1; y; +1, +1; m; +1, -1; y; # }

View File

@ -49,7 +49,7 @@ static int solveCubicNormed(double x[3], double a, double b, double c) {
x[2] = q*cos(1/3.*(t-2*M_PI))-a;
return 3;
} else {
double u = (r < 0 ? 1 : -1)*pow(fabs(r)+sqrt(r2-q3), 1/3.);
double u = (r < 0 ? 1 : -1)*pow(fabs(r)+sqrt(r2-q3), 1/3.);
double v = u == 0 ? 0 : q/u;
x[0] = (u+v)-a;
if (u == v || fabs(u-v) < 1e-12*fabs(u+v)) {

View File

@ -6,7 +6,9 @@
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_OUTLINE_H
#ifndef MSDFGEN_DISABLE_VARIABLE_FONTS
#include FT_MULTIPLE_MASTERS_H
#endif
namespace msdfgen {
@ -222,6 +224,8 @@ 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)));
}
#ifndef MSDFGEN_DISABLE_VARIABLE_FONTS
bool setFontVariationAxis(FreetypeHandle *library, FontHandle *font, const char *name, double coordinate) {
bool success = false;
if (font->face->face_flags&FT_FACE_FLAG_MULTIPLE_MASTERS) {
@ -266,4 +270,6 @@ bool listFontVariationAxes(std::vector<FontVariationAxis> &axes, FreetypeHandle
return false;
}
#endif
}

View File

@ -77,9 +77,12 @@ bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *advan
/// Outputs the kerning distance adjustment between two specific glyphs.
bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex1, GlyphIndex glyphIndex2);
bool getKerning(double &output, FontHandle *font, unicode_t unicode1, unicode_t unicode2);
#ifndef MSDFGEN_DISABLE_VARIABLE_FONTS
/// Sets a single variation axis of a variable font.
bool setFontVariationAxis(FreetypeHandle *library, FontHandle *font, const char *name, double coordinate);
/// Lists names and ranges of variation axes of a variable font.
bool listFontVariationAxes(std::vector<FontVariationAxis> &axes, FreetypeHandle *library, FontHandle *font);
#endif
}

View File

@ -147,6 +147,7 @@ static bool parseUnicode(unicode_t &unicode, const char *arg) {
return false;
}
#ifndef MSDFGEN_DISABLE_VARIABLE_FONTS
static FontHandle * loadVarFont(FreetypeHandle *library, const char *filename) {
std::string buffer;
while (*filename && *filename != '?')
@ -170,6 +171,7 @@ static FontHandle * loadVarFont(FreetypeHandle *library, const char *filename) {
return font;
}
#endif
#endif
template <int N>
static void invertColor(const BitmapRef<float, N> &bitmap) {
@ -304,7 +306,7 @@ static const char * writeOutput(const BitmapConstRef<float, N> &bitmap, const ch
#define VERSION_UNDERLINE "--------"
#endif
#if defined(MSDFGEN_EXTENSIONS) && (defined(MSDFGEN_DISABLE_SVG) || defined(MSDFGEN_DISABLE_PNG))
#if defined(MSDFGEN_EXTENSIONS) && (defined(MSDFGEN_DISABLE_SVG) || defined(MSDFGEN_DISABLE_PNG) || defined(MSDFGEN_DISABLE_VARIABLE_FONTS))
#define TITLE_SUFFIX " - custom config"
#define SUFFIX_UNDERLINE "----------------"
#elif !defined(MSDFGEN_EXTENSIONS) && defined(MSDFGEN_USE_OPENMP)
@ -364,7 +366,7 @@ static const char * const helpText =
" -svg <filename.svg>\n"
"\tLoads the last vector path found in the specified SVG file.\n"
#endif
#ifdef MSDFGEN_EXTENSIONS
#if defined(MSDFGEN_EXTENSIONS) && !defined(MSDFGEN_DISABLE_VARIABLE_FONTS)
" -varfont <filename and variables> <character code>\n"
"\tLoads a single glyph from a variable font. Specify variable values as x.ttf?var1=0.5&var2=1\n"
#endif
@ -590,7 +592,12 @@ int main(int argc, const char * const *argv) {
#endif
#ifdef MSDFGEN_EXTENSIONS
//ARG_CASE -font, -varfont
if (argPos+2 < argc && ((!strcmp(arg, "-font") && (inputType = FONT)) || (!strcmp(arg, "-varfont") && (inputType = VAR_FONT)))) {
if (argPos+2 < argc && (
(!strcmp(arg, "-font") && (inputType = FONT, true))
#ifndef MSDFGEN_DISABLE_VARIABLE_FONTS
|| (!strcmp(arg, "-varfont") && (inputType = VAR_FONT, true))
#endif
)) {
input = argv[argPos+1];
const char *charArg = argv[argPos+2];
unsigned gi;
@ -971,7 +978,12 @@ int main(int argc, const char * const *argv) {
FreetypeHandle *ft = initializeFreetype();
if (!ft)
return -1;
FontHandle *font = inputType == VAR_FONT ? loadVarFont(ft, input) : loadFont(ft, input);
FontHandle *font = (
#ifndef MSDFGEN_DISABLE_VARIABLE_FONTS
inputType == VAR_FONT ? loadVarFont(ft, input) :
#endif
loadFont(ft, input)
);
if (!font) {
deinitializeFreetype(ft);
ABORT("Failed to load font file.");