Added hidden options to disable SVG / PNG dependencies

This commit is contained in:
Chlumsky 2023-04-07 13:10:24 +02:00
parent 00d404686c
commit 5eef2e5985
5 changed files with 50 additions and 15 deletions

View File

@ -124,10 +124,10 @@ if(NOT MSDFGEN_CORE_ONLY)
if(NOT TARGET Freetype::Freetype) if(NOT TARGET Freetype::Freetype)
find_package(Freetype REQUIRED) find_package(Freetype REQUIRED)
endif() endif()
if(NOT TARGET tinyxml2::tinyxml2) if(NOT MSDFGEN_DISABLE_SVG AND NOT TARGET tinyxml2::tinyxml2)
find_package(tinyxml2 REQUIRED) find_package(tinyxml2 REQUIRED)
endif() endif()
if(NOT TARGET PNG::PNG) if(NOT MSDFGEN_DISABLE_PNG AND NOT TARGET PNG::PNG)
find_package(PNG REQUIRED) find_package(PNG REQUIRED)
endif() endif()
@ -135,9 +135,19 @@ if(NOT MSDFGEN_CORE_ONLY)
add_library(msdfgen::msdfgen-ext ALIAS msdfgen-ext) add_library(msdfgen::msdfgen-ext ALIAS msdfgen-ext)
set_target_properties(msdfgen-ext PROPERTIES PUBLIC_HEADER "${MSDFGEN_EXT_HEADERS}") set_target_properties(msdfgen-ext PROPERTIES PUBLIC_HEADER "${MSDFGEN_EXT_HEADERS}")
set_property(TARGET msdfgen-ext PROPERTY MSVC_RUNTIME_LIBRARY "${MSDFGEN_MSVC_RUNTIME}") set_property(TARGET msdfgen-ext PROPERTY MSVC_RUNTIME_LIBRARY "${MSDFGEN_MSVC_RUNTIME}")
target_compile_definitions(msdfgen-ext PUBLIC MSDFGEN_USE_LIBPNG)
target_compile_definitions(msdfgen-ext INTERFACE MSDFGEN_EXTENSIONS) target_compile_definitions(msdfgen-ext INTERFACE MSDFGEN_EXTENSIONS)
target_link_libraries(msdfgen-ext PRIVATE msdfgen::msdfgen-core Freetype::Freetype tinyxml2::tinyxml2 PNG::PNG) if(NOT MSDFGEN_DISABLE_SVG)
target_link_libraries(msdfgen-ext PRIVATE tinyxml2::tinyxml2)
else()
target_compile_definitions(msdfgen-ext PUBLIC MSDFGEN_DISABLE_SVG)
endif()
if(NOT MSDFGEN_DISABLE_PNG)
target_compile_definitions(msdfgen-ext PUBLIC MSDFGEN_USE_LIBPNG)
target_link_libraries(msdfgen-ext PRIVATE PNG::PNG)
else()
target_compile_definitions(msdfgen-ext PUBLIC MSDFGEN_DISABLE_PNG)
endif()
target_link_libraries(msdfgen-ext PRIVATE Freetype::Freetype msdfgen::msdfgen-core)
target_include_directories(msdfgen-ext target_include_directories(msdfgen-ext
PUBLIC PUBLIC
$<INSTALL_INTERFACE:include/msdfgen> $<INSTALL_INTERFACE:include/msdfgen>

View File

@ -3,6 +3,8 @@
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#include "import-svg.h" #include "import-svg.h"
#ifndef MSDFGEN_DISABLE_SVG
#include <cstdio> #include <cstdio>
#include <tinyxml2.h> #include <tinyxml2.h>
#include "../core/arithmetics.hpp" #include "../core/arithmetics.hpp"
@ -308,3 +310,5 @@ bool loadSvgShape(Shape &output, const char *filename, int pathIndex, Vector2 *d
} }
} }
#endif

View File

@ -4,6 +4,8 @@
#include <cstddef> #include <cstddef>
#include "../core/Shape.h" #include "../core/Shape.h"
#ifndef MSDFGEN_DISABLE_SVG
namespace msdfgen { namespace msdfgen {
/// Builds a shape from an SVG path string /// Builds a shape from an SVG path string
@ -13,3 +15,5 @@ bool buildShapeFromSvgPath(Shape &shape, const char *pathDef, double endpointSna
bool loadSvgShape(Shape &output, const char *filename, int pathIndex = 0, Vector2 *dimensions = NULL); bool loadSvgShape(Shape &output, const char *filename, int pathIndex = 0, Vector2 *dimensions = NULL);
} }
#endif

View File

@ -3,6 +3,8 @@
#include "../core/BitmapRef.hpp" #include "../core/BitmapRef.hpp"
#ifndef MSDFGEN_DISABLE_PNG
namespace msdfgen { namespace msdfgen {
/// Saves the bitmap as a PNG file. /// Saves the bitmap as a PNG file.
@ -14,3 +16,5 @@ bool savePng(const BitmapConstRef<float, 3> &bitmap, const char *filename);
bool savePng(const BitmapConstRef<float, 4> &bitmap, const char *filename); bool savePng(const BitmapConstRef<float, 4> &bitmap, const char *filename);
} }
#endif

View File

@ -25,7 +25,7 @@
#define SDF_ERROR_ESTIMATE_PRECISION 19 #define SDF_ERROR_ESTIMATE_PRECISION 19
#define DEFAULT_ANGLE_THRESHOLD 3. #define DEFAULT_ANGLE_THRESHOLD 3.
#ifdef MSDFGEN_EXTENSIONS #if defined(MSDFGEN_EXTENSIONS) && !defined(MSDFGEN_DISABLE_PNG)
#define DEFAULT_IMAGE_EXTENSION "png" #define DEFAULT_IMAGE_EXTENSION "png"
#define SAVE_DEFAULT_IMAGE_FORMAT savePng #define SAVE_DEFAULT_IMAGE_FORMAT savePng
#else #else
@ -241,7 +241,7 @@ template <int N>
static const char * writeOutput(const BitmapConstRef<float, N> &bitmap, const char *filename, Format &format) { static const char * writeOutput(const BitmapConstRef<float, N> &bitmap, const char *filename, Format &format) {
if (filename) { if (filename) {
if (format == AUTO) { if (format == AUTO) {
#ifdef MSDFGEN_EXTENSIONS #if defined(MSDFGEN_EXTENSIONS) && !defined(MSDFGEN_DISABLE_PNG)
if (cmpExtension(filename, ".png")) format = PNG; if (cmpExtension(filename, ".png")) format = PNG;
#else #else
if (cmpExtension(filename, ".png")) if (cmpExtension(filename, ".png"))
@ -255,7 +255,7 @@ static const char * writeOutput(const BitmapConstRef<float, N> &bitmap, const ch
return "Could not deduce format from output file name."; return "Could not deduce format from output file name.";
} }
switch (format) { switch (format) {
#ifdef MSDFGEN_EXTENSIONS #if defined(MSDFGEN_EXTENSIONS) && !defined(MSDFGEN_DISABLE_PNG)
case PNG: return savePng(bitmap, filename) ? NULL : "Failed to write output PNG image."; case PNG: return savePng(bitmap, filename) ? NULL : "Failed to write output PNG image.";
#endif #endif
case BMP: return saveBmp(bitmap, filename) ? NULL : "Failed to write output BMP image."; case BMP: return saveBmp(bitmap, filename) ? NULL : "Failed to write output BMP image.";
@ -304,7 +304,10 @@ static const char * writeOutput(const BitmapConstRef<float, N> &bitmap, const ch
#define VERSION_UNDERLINE "--------" #define VERSION_UNDERLINE "--------"
#endif #endif
#if !defined(MSDFGEN_EXTENSIONS) && defined(MSDFGEN_USE_OPENMP) #if defined(MSDFGEN_EXTENSIONS) && (defined(MSDFGEN_DISABLE_SVG) || defined(MSDFGEN_DISABLE_PNG))
#define TITLE_SUFFIX " - custom config"
#define SUFFIX_UNDERLINE "----------------"
#elif !defined(MSDFGEN_EXTENSIONS) && defined(MSDFGEN_USE_OPENMP)
#define TITLE_SUFFIX " - core with OpenMP" #define TITLE_SUFFIX " - core with OpenMP"
#define SUFFIX_UNDERLINE "-------------------" #define SUFFIX_UNDERLINE "-------------------"
#elif !defined(MSDFGEN_EXTENSIONS) #elif !defined(MSDFGEN_EXTENSIONS)
@ -357,9 +360,11 @@ static const char * const helpText =
"\tLoads text shape description from a file.\n" "\tLoads text shape description from a file.\n"
" -stdin\n" " -stdin\n"
"\tReads text shape description from the standard input.\n" "\tReads text shape description from the standard input.\n"
#ifdef MSDFGEN_EXTENSIONS #if defined(MSDFGEN_EXTENSIONS) && !defined(MSDFGEN_DISABLE_SVG)
" -svg <filename.svg>\n" " -svg <filename.svg>\n"
"\tLoads the last vector path found in the specified SVG file.\n" "\tLoads the last vector path found in the specified SVG file.\n"
#endif
#ifdef MSDFGEN_EXTENSIONS
" -varfont <filename and variables> <character code>\n" " -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" "\tLoads a single glyph from a variable font. Specify variable values as x.ttf?var1=0.5&var2=1\n"
#endif #endif
@ -390,7 +395,7 @@ static const char * const helpText =
"\tSaves the shape description into a text file that can be edited and loaded using -shapedesc.\n" "\tSaves the shape description into a text file that can be edited and loaded using -shapedesc.\n"
" -fillrule <nonzero / evenodd / positive / negative>\n" " -fillrule <nonzero / evenodd / positive / negative>\n"
"\tSets the fill rule for the scanline pass. Default is nonzero.\n" "\tSets the fill rule for the scanline pass. Default is nonzero.\n"
#ifdef MSDFGEN_EXTENSIONS #if defined(MSDFGEN_EXTENSIONS) && !defined(MSDFGEN_DISABLE_PNG)
" -format <png / bmp / tiff / text / textfloat / bin / binfloat / binfloatbe>\n" " -format <png / bmp / tiff / text / textfloat / bin / binfloat / binfloatbe>\n"
#else #else
" -format <bmp / tiff / text / textfloat / bin / binfloat / binfloatbe>\n" " -format <bmp / tiff / text / textfloat / bin / binfloat / binfloatbe>\n"
@ -438,7 +443,7 @@ static const char * const helpText =
" -stdout\n" " -stdout\n"
"\tPrints the output instead of storing it in a file. Only text formats are supported.\n" "\tPrints the output instead of storing it in a file. Only text formats are supported.\n"
" -testrender <filename." DEFAULT_IMAGE_EXTENSION "> <width> <height>\n" " -testrender <filename." DEFAULT_IMAGE_EXTENSION "> <width> <height>\n"
#ifdef MSDFGEN_EXTENSIONS #if defined(MSDFGEN_EXTENSIONS) && !defined(MSDFGEN_DISABLE_PNG)
"\tRenders an image preview using the generated distance field and saves it as a PNG file.\n" "\tRenders an image preview using the generated distance field and saves it as a PNG file.\n"
#else #else
"\tRenders an image preview using the generated distance field and saves it as a TIFF file.\n" "\tRenders an image preview using the generated distance field and saves it as a TIFF file.\n"
@ -575,13 +580,15 @@ int main(int argc, const char * const *argv) {
ARG_MODE("mtsdf", MULTI_AND_TRUE) ARG_MODE("mtsdf", MULTI_AND_TRUE)
ARG_MODE("metrics", METRICS) ARG_MODE("metrics", METRICS)
#ifdef MSDFGEN_EXTENSIONS #if defined(MSDFGEN_EXTENSIONS) && !defined(MSDFGEN_DISABLE_SVG)
ARG_CASE("-svg", 1) { ARG_CASE("-svg", 1) {
inputType = SVG; inputType = SVG;
input = argv[argPos+1]; input = argv[argPos+1];
argPos += 2; argPos += 2;
continue; continue;
} }
#endif
#ifdef MSDFGEN_EXTENSIONS
//ARG_CASE -font, -varfont //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)) || (!strcmp(arg, "-varfont") && (inputType = VAR_FONT)))) {
input = argv[argPos+1]; input = argv[argPos+1];
@ -695,7 +702,7 @@ int main(int argc, const char * const *argv) {
} }
ARG_CASE("-format", 1) { ARG_CASE("-format", 1) {
if (!strcmp(argv[argPos+1], "auto")) format = AUTO; if (!strcmp(argv[argPos+1], "auto")) format = AUTO;
#ifdef MSDFGEN_EXTENSIONS #if defined(MSDFGEN_EXTENSIONS) && !defined(MSDFGEN_DISABLE_PNG)
else if (!strcmp(argv[argPos+1], "png")) SET_FORMAT(PNG, "png"); else if (!strcmp(argv[argPos+1], "png")) SET_FORMAT(PNG, "png");
#else #else
else if (!strcmp(argv[argPos+1], "png")) else if (!strcmp(argv[argPos+1], "png"))
@ -937,7 +944,11 @@ int main(int argc, const char * const *argv) {
double glyphAdvance = 0; double glyphAdvance = 0;
if (!inputType || !input) { if (!inputType || !input) {
#ifdef MSDFGEN_EXTENSIONS #ifdef MSDFGEN_EXTENSIONS
ABORT("No input specified! Use either -svg <file.svg> or -font <file.ttf/otf> <character code>, or see -help."); #ifdef MSDFGEN_DISABLE_SVG
ABORT("No input specified! Use -font <file.ttf/otf> <character code> or see -help.");
#else
ABORT("No input specified! Use either -svg <file.svg> or -font <file.ttf/otf> <character code>, or see -help.");
#endif
#else #else
ABORT("No input specified! See -help."); ABORT("No input specified! See -help.");
#endif #endif
@ -946,12 +957,14 @@ int main(int argc, const char * const *argv) {
ABORT("Incompatible image format. A BMP file cannot contain alpha channel, which is required in mtsdf mode."); ABORT("Incompatible image format. A BMP file cannot contain alpha channel, which is required in mtsdf mode.");
Shape shape; Shape shape;
switch (inputType) { switch (inputType) {
#ifdef MSDFGEN_EXTENSIONS #if defined(MSDFGEN_EXTENSIONS) && !defined(MSDFGEN_DISABLE_SVG)
case SVG: { case SVG: {
if (!loadSvgShape(shape, input, svgPathIndex, &svgDims)) if (!loadSvgShape(shape, input, svgPathIndex, &svgDims))
ABORT("Failed to load shape from SVG file."); ABORT("Failed to load shape from SVG file.");
break; break;
} }
#endif
#ifdef MSDFGEN_EXTENSIONS
case FONT: case VAR_FONT: { case FONT: case VAR_FONT: {
if (!glyphIndexSpecified && !unicode) if (!glyphIndexSpecified && !unicode)
ABORT("No character specified! Use -font <file.ttf/otf> <character code>. Character code can be a Unicode index (65, 0x41), a character in apostrophes ('A'), or a glyph index prefixed by g (g36, g0x24)."); ABORT("No character specified! Use -font <file.ttf/otf> <character code>. Character code can be a Unicode index (65, 0x41), a character in apostrophes ('A'), or a glyph index prefixed by g (g36, g0x24).");