diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fc8cd9..5b7f6db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ option(MSDF_ATLAS_DYNAMIC_RUNTIME "Link dynamic runtime library instead of stati option(BUILD_SHARED_LIBS "Generate dynamic library files instead of static" OFF) if(NOT MSDF_ATLAS_MSDFGEN_EXTERNAL) + set(MSDFGEN_DISABLE_SVG ON CACHE BOOL "Disable unused SVG functionality to minimize dependencies") set(MSDFGEN_CORE_ONLY OFF CACHE INTERNAL "Only build the core msdfgen library with no dependencies (disabled for msdf-atlas-gen)" FORCE) set(MSDFGEN_BUILD_STANDALONE OFF CACHE BOOL "Build the msdfgen standalone executable") set(MSDFGEN_USE_VCPKG ${MSDF_ATLAS_USE_VCPKG} CACHE INTERNAL "Use vcpkg package manager to link msdfgen project dependencies" FORCE) @@ -82,7 +83,7 @@ else() add_subdirectory(msdfgen) endif() find_package(Threads REQUIRED) -if(NOT TARGET PNG::PNG) +if(NOT MSDFGEN_DISABLE_PNG AND NOT TARGET PNG::PNG) find_package(PNG REQUIRED) endif() @@ -113,7 +114,10 @@ endif() set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT msdf-atlas-gen) target_compile_features(msdf-atlas-gen PUBLIC cxx_std_11) -target_link_libraries(msdf-atlas-gen PRIVATE Threads::Threads PNG::PNG) +target_link_libraries(msdf-atlas-gen PRIVATE Threads::Threads) +if(NOT MSDFGEN_DISABLE_PNG) + target_link_libraries(msdf-atlas-gen PRIVATE PNG::PNG) +endif() target_link_libraries(msdf-atlas-gen PUBLIC msdfgen::msdfgen) if(BUILD_SHARED_LIBS AND WIN32) diff --git a/README.md b/README.md index 142913b..c666243 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ The atlas generator can generate the following six types of atlases. Notes: - *Sharp corners* refers to preservation of corner sharpness when upscaled. -- *Soft effects* refers to the support of effects that use true distance, such as glows, rounded borders, or simplified shadows. -- *Hard effects* refers to the support of effects that use pseudo-distance, such as mitered borders or thickness adjustment. +- *Soft effects* refers to the support of effects that use true distance, such as glows, rounded outlines, or simplified shadows. +- *Hard effects* refers to the support of effects that use perpendicular distance, such as mitered outlines or thickness adjustment. ## Getting started @@ -63,7 +63,7 @@ Use the following command line arguments for the standalone version of the atlas - `hardmask` – a non-anti-aliased binary image - `softmask` – an anti-aliased image - `sdf` – a true signed distance field (SDF) -- `psdf` – a pseudo-distance field +- `psdf` – a signed perpendicular distance field (PSDF) - `msdf` (default) – a multi-channel signed distance field (MSDF) - `mtsdf` – a combination of MSDF and true SDF in the alpha channel diff --git a/cmake/msdf-atlas-gen-config.cmake.in b/cmake/msdf-atlas-gen-config.cmake.in index 8789a4a..b5b2317 100644 --- a/cmake/msdf-atlas-gen-config.cmake.in +++ b/cmake/msdf-atlas-gen-config.cmake.in @@ -2,8 +2,11 @@ include(CMakeFindDependencyMacro) set(MSDF_ATLAS_STANDALONE_AVAILABLE @MSDF_ATLAS_BUILD_STANDALONE@) +set(MSDF_ATLAS_NO_PNG @MSDFGEN_DISABLE_PNG@) -find_dependency(PNG REQUIRED) +if(NOT MSDF_ATLAS_NO_PNG) + find_dependency(PNG REQUIRED) +endif() find_dependency(msdfgen REQUIRED) include("${CMAKE_CURRENT_LIST_DIR}/msdf-atlas-gen-targets.cmake") diff --git a/msdf-atlas-gen/artery-font-export.cpp b/msdf-atlas-gen/artery-font-export.cpp index f617a58..2c15ac6 100644 --- a/msdf-atlas-gen/artery-font-export.cpp +++ b/msdf-atlas-gen/artery-font-export.cpp @@ -134,12 +134,14 @@ bool exportArteryFont(const FontGeometry *fonts, int fontCount, const msdfgen::B image.channels = N; image.imageType = convertImageType(properties.imageType); switch (properties.imageFormat) { + #ifndef MSDFGEN_DISABLE_PNG case ImageFormat::PNG: image.encoding = artery_font::IMAGE_PNG; image.pixelFormat = artery_font::PIXEL_UNSIGNED8; if (!encodePng((std::vector &) image.data, atlas)) return false; break; + #endif case ImageFormat::TIFF: image.encoding = artery_font::IMAGE_TIFF; image.pixelFormat = artery_font::PIXEL_FLOAT32; diff --git a/msdf-atlas-gen/glyph-generators.cpp b/msdf-atlas-gen/glyph-generators.cpp index af4a325..d573dcf 100644 --- a/msdf-atlas-gen/glyph-generators.cpp +++ b/msdf-atlas-gen/glyph-generators.cpp @@ -14,7 +14,7 @@ void sdfGenerator(const msdfgen::BitmapRef &output, const GlyphGeometr } void psdfGenerator(const msdfgen::BitmapRef &output, const GlyphGeometry &glyph, const GeneratorAttributes &attribs) { - msdfgen::generatePseudoSDF(output, glyph.getShape(), glyph.getBoxProjection(), glyph.getBoxRange(), attribs.config); + msdfgen::generatePSDF(output, glyph.getShape(), glyph.getBoxProjection(), glyph.getBoxRange(), attribs.config); if (attribs.scanlinePass) msdfgen::distanceSignCorrection(output, glyph.getShape(), glyph.getBoxProjection(), MSDF_ATLAS_GLYPH_FILL_RULE); } diff --git a/msdf-atlas-gen/glyph-generators.h b/msdf-atlas-gen/glyph-generators.h index 1df7c24..e0d7b23 100644 --- a/msdf-atlas-gen/glyph-generators.h +++ b/msdf-atlas-gen/glyph-generators.h @@ -15,7 +15,7 @@ namespace msdf_atlas { void scanlineGenerator(const msdfgen::BitmapRef &output, const GlyphGeometry &glyph, const GeneratorAttributes &attribs); /// Generates a true signed distance field of the glyph void sdfGenerator(const msdfgen::BitmapRef &output, const GlyphGeometry &glyph, const GeneratorAttributes &attribs); -/// Generates a signed pseudo-distance field of the glyph +/// Generates a signed perpendicular distance field of the glyph void psdfGenerator(const msdfgen::BitmapRef &output, const GlyphGeometry &glyph, const GeneratorAttributes &attribs); /// Generates a multi-channel signed distance field of the glyph void msdfGenerator(const msdfgen::BitmapRef &output, const GlyphGeometry &glyph, const GeneratorAttributes &attribs); diff --git a/msdf-atlas-gen/image-encode.h b/msdf-atlas-gen/image-encode.h index 59a8fc5..9638357 100644 --- a/msdf-atlas-gen/image-encode.h +++ b/msdf-atlas-gen/image-encode.h @@ -5,6 +5,8 @@ #include #include "types.h" +#ifndef MSDFGEN_DISABLE_PNG + namespace msdf_atlas { // Functions to encode an image as a sequence of bytes in memory @@ -18,3 +20,5 @@ bool encodePng(std::vector &output, const msdfgen::BitmapConstRef &output, const msdfgen::BitmapConstRef &bitmap); } + +#endif diff --git a/msdf-atlas-gen/image-save.hpp b/msdf-atlas-gen/image-save.hpp index 2219b59..6be7df4 100644 --- a/msdf-atlas-gen/image-save.hpp +++ b/msdf-atlas-gen/image-save.hpp @@ -21,8 +21,10 @@ bool saveImageText(const msdfgen::BitmapConstRef &bitmap, const char * template bool saveImage(const msdfgen::BitmapConstRef &bitmap, ImageFormat format, const char *filename, YDirection outputYDirection) { switch (format) { + #ifndef MSDFGEN_DISABLE_PNG case ImageFormat::PNG: return msdfgen::savePng(bitmap, filename); + #endif case ImageFormat::BMP: return msdfgen::saveBmp(bitmap, filename); case ImageFormat::TIFF: @@ -44,8 +46,10 @@ bool saveImage(const msdfgen::BitmapConstRef &bitmap, ImageFormat forma template bool saveImage(const msdfgen::BitmapConstRef &bitmap, ImageFormat format, const char *filename, YDirection outputYDirection) { switch (format) { + #ifndef MSDFGEN_DISABLE_PNG case ImageFormat::PNG: return msdfgen::savePng(bitmap, filename); + #endif case ImageFormat::BMP: return msdfgen::saveBmp(bitmap, filename); case ImageFormat::TIFF: diff --git a/msdf-atlas-gen/main.cpp b/msdf-atlas-gen/main.cpp index beb6c36..b89744d 100644 --- a/msdf-atlas-gen/main.cpp +++ b/msdf-atlas-gen/main.cpp @@ -57,9 +57,13 @@ MSDF Atlas Generator by Viktor Chlumsky v)" MSDF_ATLAS_VERSION_STRING R"( (with INPUT SPECIFICATION -font - Specifies the input TrueType / OpenType font file. A font specification is required. + Specifies the input TrueType / OpenType font file. A font specification is required.)" +#ifndef MSDFGEN_DISABLE_VARIABLE_FONTS +R"( -varfont - Specifies an input variable font file and configures its variables. + Specifies an input variable font file and configures its variables.)" +#endif +R"( -charset Specifies the input character set. Refer to the documentation for format of charset specification. Defaults to ASCII. -glyphset @@ -76,7 +80,13 @@ INPUT SPECIFICATION ATLAS CONFIGURATION -type Selects the type of atlas to be generated. - -format +)" +#ifndef MSDFGEN_DISABLE_PNG +R"( -format )" +#else +R"( -format )" +#endif +R"( Selects the format for the atlas image output. Some image formats may be incompatible with embedded output formats. -dimensions Sets the atlas to have fixed dimensions (width x height). @@ -90,9 +100,9 @@ ATLAS CONFIGURATION -uniformcell Sets fixed dimensions of the grid's cells. -uniformcellconstraint - Constrains cell dimensions to the given rule (see -pots / ... above) + Constrains cell dimensions to the given rule (see -pots / ... above). -uniformorigin - Sets whether the glyph's origin point should be fixed at the same position in each cell + Sets whether the glyph's origin point should be fixed at the same position in each cell. -yorigin Determines whether the Y-axis is oriented upwards (bottom origin, default) or downwards (top origin). @@ -228,6 +238,7 @@ static bool strStartsWith(const char *str, const char *prefix) { return true; } +#ifndef MSDFGEN_DISABLE_VARIABLE_FONTS static msdfgen::FontHandle *loadVarFont(msdfgen::FreetypeHandle *library, const char *filename) { std::string buffer; while (*filename && *filename != '?') @@ -250,6 +261,7 @@ static msdfgen::FontHandle *loadVarFont(msdfgen::FreetypeHandle *library, const } return font; } +#endif struct FontInput { const char *fontFilename; @@ -406,9 +418,12 @@ int main(int argc, const char *const *argv) { continue; } ARG_CASE("-format", 1) { - if (ARG_IS("png")) - config.imageFormat = ImageFormat::PNG; - else if (ARG_IS("bmp")) + #ifndef MSDFGEN_DISABLE_PNG + if (ARG_IS("png")) + config.imageFormat = ImageFormat::PNG; + else + #endif + if (ARG_IS("bmp")) config.imageFormat = ImageFormat::BMP; else if (ARG_IS("tiff")) config.imageFormat = ImageFormat::TIFF; @@ -422,8 +437,13 @@ int main(int argc, const char *const *argv) { config.imageFormat = ImageFormat::BINARY_FLOAT; else if (ARG_IS("binfloatbe")) config.imageFormat = ImageFormat::BINARY_FLOAT_BE; - else - ABORT("Invalid image format. Valid formats are: png, bmp, tiff, text, textfloat, bin, binfloat"); + else { + #ifndef MSDFGEN_DISABLE_PNG + ABORT("Invalid image format. Valid formats are: png, bmp, tiff, text, textfloat, bin, binfloat"); + #else + ABORT("Invalid image format. Valid formats are: bmp, tiff, text, textfloat, bin, binfloat"); + #endif + } imageFormatName = arg; ++argPos; continue; @@ -433,11 +453,13 @@ int main(int argc, const char *const *argv) { fontInput.variableFont = false; continue; } + #ifndef MSDFGEN_DISABLE_VARIABLE_FONTS ARG_CASE("-varfont", 1) { fontInput.fontFilename = argv[argPos++]; fontInput.variableFont = true; continue; } + #endif ARG_CASE("-charset", 1) { fontInput.charsetFilename = argv[argPos++]; fontInput.glyphIdentifierType = GlyphIdentifierType::UNICODE_CODEPOINT; @@ -845,21 +867,31 @@ int main(int argc, const char *const *argv) { // Finalize image format ImageFormat imageExtension = ImageFormat::UNSPECIFIED; if (config.imageFilename) { - if (cmpExtension(config.imageFilename, ".png")) imageExtension = ImageFormat::PNG; - else if (cmpExtension(config.imageFilename, ".bmp")) imageExtension = ImageFormat::BMP; + if (cmpExtension(config.imageFilename, ".png")) { + #ifndef MSDFGEN_DISABLE_PNG + imageExtension = ImageFormat::PNG; + #else + fputs("Warning: You are using a version of this program without PNG image support!\n", stderr); + #endif + } else if (cmpExtension(config.imageFilename, ".bmp")) imageExtension = ImageFormat::BMP; else if (cmpExtension(config.imageFilename, ".tif") || cmpExtension(config.imageFilename, ".tiff")) imageExtension = ImageFormat::TIFF; else if (cmpExtension(config.imageFilename, ".txt")) imageExtension = ImageFormat::TEXT; else if (cmpExtension(config.imageFilename, ".bin")) imageExtension = ImageFormat::BINARY; } if (config.imageFormat == ImageFormat::UNSPECIFIED) { - config.imageFormat = ImageFormat::PNG; - imageFormatName = "png"; + #ifndef MSDFGEN_DISABLE_PNG + config.imageFormat = ImageFormat::PNG; + imageFormatName = "png"; + #else + config.imageFormat = ImageFormat::TIFF; + imageFormatName = "tiff"; + #endif // If image format is not specified and -imageout is the only image output, infer format from its extension if (!config.arteryFontFilename) { if (imageExtension != ImageFormat::UNSPECIFIED) config.imageFormat = imageExtension; else if (config.imageFilename) - fputs("Warning: Could not infer image format from file extension, PNG will be used.\n", stderr); + fprintf(stderr, "Warning: Could not infer image format from file extension, %s will be used.\n", imageFormatName); } } if (config.imageType == ImageType::MTSDF && config.imageFormat == ImageFormat::BMP) @@ -926,7 +958,12 @@ int main(int argc, const char *const *argv) { return true; if (font) msdfgen::destroyFont(font); - if ((font = isVarFont ? loadVarFont(ft, fontFilename) : msdfgen::loadFont(ft, fontFilename))) { + if ((font = ( + #ifndef MSDFGEN_DISABLE_VARIABLE_FONTS + isVarFont ? loadVarFont(ft, fontFilename) : + #endif + msdfgen::loadFont(ft, fontFilename) + ))) { this->fontFilename = fontFilename; return true; } diff --git a/msdf-atlas-gen/types.h b/msdf-atlas-gen/types.h index 78cc30c..92026fe 100644 --- a/msdf-atlas-gen/types.h +++ b/msdf-atlas-gen/types.h @@ -16,7 +16,7 @@ enum class ImageType { SOFT_MASK, /// Signed (true) distance field SDF, - /// Signed pseudo-distance field + /// Signed perpendicular distance field PSDF, /// Multi-channel signed distance field MSDF, diff --git a/msdfgen b/msdfgen index 682381a..937f31f 160000 --- a/msdfgen +++ b/msdfgen @@ -1 +1 @@ -Subproject commit 682381a03c5876cffcad256a59eab7efd83c3f4e +Subproject commit 937f31ff418e488e4b707a77c294cdb4fadb4235 diff --git a/vcpkg.json b/vcpkg.json index 9557d51..fdb7a67 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -7,7 +7,6 @@ "license": "MIT", "dependencies": [ "freetype", - "tinyxml2", "libpng" ], "default-features": [