Artery font made optional, print version. accept --args

This commit is contained in:
Chlumsky 2023-01-21 16:50:39 +01:00
parent 718a0ca77c
commit 132c3af316
5 changed files with 44 additions and 10 deletions

View File

@ -5,6 +5,7 @@ include(cmake/version.cmake)
option(MSDF_ATLAS_BUILD_STANDALONE "Build the msdf-atlas-gen standalone executable" ON)
option(MSDF_ATLAS_USE_VCPKG "Use vcpkg package manager to link project dependencies" ON)
option(MSDF_ATLAS_USE_SKIA "Build with the Skia library" ON)
option(MSDF_ATLAS_NO_ARTERY_FONT "Disable Artery Font export and do not require its submodule" OFF)
option(MSDF_ATLAS_MSDFGEN_EXTERNAL "Do not build the msdfgen submodule but find it as an external package" OFF)
option(MSDF_ATLAS_INSTALL "Generate installation target" OFF)
option(MSDF_ATLAS_DYNAMIC_RUNTIME "Link dynamic runtime library instead of static" OFF)
@ -100,13 +101,15 @@ target_compile_definitions(msdf-atlas-gen PUBLIC
MSDF_ATLAS_VERSION_REVISION=${MSDF_ATLAS_VERSION_REVISION}
MSDF_ATLAS_COPYRIGHT_YEAR=${MSDF_ATLAS_COPYRIGHT_YEAR}
)
target_include_directories(msdf-atlas-gen
INTERFACE
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/artery-font-format
target_include_directories(msdf-atlas-gen INTERFACE
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
if(MSDF_ATLAS_NO_ARTERY_FONT)
target_compile_definitions(msdf-atlas-gen PUBLIC MSDF_ATLAS_NO_ARTERY_FONT)
else()
target_include_directories(msdf-atlas-gen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/artery-font-format)
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)

View File

@ -1,6 +1,8 @@
#include "artery-font-export.h"
#ifndef MSDF_ATLAS_NO_ARTERY_FONT
#include <artery-font/std-artery-font.h>
#include <artery-font/stdio-serialization.h>
#include "GlyphGeometry.h"
@ -188,3 +190,5 @@ template bool exportArteryFont<float>(const FontGeometry *fonts, int fontCount,
template bool exportArteryFont<float>(const FontGeometry *fonts, int fontCount, const msdfgen::BitmapConstRef<float, 4> &atlas, const char *filename, const ArteryFontExportProperties &properties);
}
#endif

View File

@ -1,6 +1,8 @@
#pragma once
#ifndef MSDF_ATLAS_NO_ARTERY_FONT
#include <msdfgen.h>
#include <msdfgen-ext.h>
#include "types.h"
@ -21,3 +23,5 @@ template <typename REAL, typename T, int N>
bool exportArteryFont(const FontGeometry *fonts, int fontCount, const msdfgen::BitmapConstRef<T, N> &atlas, const char *filename, const ArteryFontExportProperties &properties);
}
#endif

View File

@ -46,6 +46,11 @@ using namespace msdf_atlas;
#define EXTRA_UNDERLINE
#endif
static const char * const versionText =
"MSDF-Atlas-Gen v" MSDF_ATLAS_VERSION_STRING "\n"
" with MSDFgen v" MSDFGEN_VERSION_STRING TITLE_SUFFIX "\n"
"(c) 2020 - " STRINGIZE(MSDF_ATLAS_COPYRIGHT_YEAR) " Viktor Chlumsky";
static const char * const helpText = R"(
MSDF Atlas Generator by Viktor Chlumsky v)" MSDF_ATLAS_VERSION_STRING R"( (with MSDFgen v)" MSDFGEN_VERSION_STRING TITLE_SUFFIX R"()
----------------------------------------------------------------)" VERSION_UNDERLINE EXTRA_UNDERLINE R"(
@ -85,9 +90,13 @@ OUTPUT SPECIFICATION - one or more can be specified
-json <filename.json>
Writes the atlas's layout data, as well as other metrics into a structured JSON file.
-csv <filename.csv>
Writes the layout data of the glyphs into a simple CSV file.
Writes the layout data of the glyphs into a simple CSV file.)"
#ifndef MSDF_ATLAS_NO_ARTERY_FONT
R"(
-arfont <filename.arfont>
Stores the atlas and its layout data as an Artery Font file. Supported formats: png, bin, binfloat.
Stores the atlas and its layout data as an Artery Font file. Supported formats: png, bin, binfloat.)"
#endif
R"(
-shadronpreview <filename.shadron> <sample text>
Generates a Shadron script that uses the generated atlas to draw a sample text as a preview.
@ -273,6 +282,7 @@ static bool makeAtlas(const std::vector<GlyphGeometry> &glyphs, const std::vecto
}
}
#ifndef MSDF_ATLAS_NO_ARTERY_FONT
if (config.arteryFontFilename) {
ArteryFontExportProperties arfontProps;
arfontProps.fontSize = config.emSize;
@ -287,6 +297,7 @@ static bool makeAtlas(const std::vector<GlyphGeometry> &glyphs, const std::vecto
puts("Failed to generate Artery Font file.");
}
}
#endif
return success;
}
@ -337,6 +348,10 @@ int main(int argc, const char * const *argv) {
const char *arg = argv[argPos];
#define ARG_CASE(s, p) if (!strcmp(arg, s) && argPos+(p) < argc)
// Accept arguments prefixed with -- instead of -
if (arg[0] == '-' && arg[1] == '-')
++arg;
ARG_CASE("-type", 1) {
arg = argv[++argPos];
if (!strcmp(arg, "hardmask"))
@ -427,11 +442,13 @@ int main(int argc, const char * const *argv) {
++argPos;
continue;
}
#ifndef MSDF_ATLAS_NO_ARTERY_FONT
ARG_CASE("-arfont", 1) {
config.arteryFontFilename = argv[++argPos];
++argPos;
continue;
}
#endif
ARG_CASE("-imageout", 1) {
config.imageFilename = argv[++argPos];
++argPos;
@ -666,11 +683,15 @@ int main(int argc, const char * const *argv) {
argPos += 2;
continue;
}
ARG_CASE("-version", 0) {
puts(versionText);
return 0;
}
ARG_CASE("-help", 0) {
puts(helpText);
return 0;
}
printf("Unknown setting or insufficient parameters: %s\n", arg);
printf("Unknown setting or insufficient parameters: %s\n", argv[argPos]);
suggestHelp = true;
++argPos;
}
@ -765,6 +786,7 @@ int main(int argc, const char * const *argv) {
}
if (config.imageType == ImageType::MTSDF && config.imageFormat == ImageFormat::BMP)
ABORT("Atlas type not compatible with image format. MTSDF requires a format with alpha channel.");
#ifndef MSDF_ATLAS_NO_ARTERY_FONT
if (config.arteryFontFilename && !(config.imageFormat == ImageFormat::PNG || config.imageFormat == ImageFormat::BINARY || config.imageFormat == ImageFormat::BINARY_FLOAT)) {
config.arteryFontFilename = nullptr;
result = 1;
@ -774,6 +796,7 @@ int main(int argc, const char * const *argv) {
return result;
layoutOnly = !(config.arteryFontFilename || config.imageFilename);
}
#endif
if (imageExtension != ImageFormat::UNSPECIFIED) {
// Warn if image format mismatches -imageout extension
bool mismatch = false;

@ -1 +1 @@
Subproject commit a811ef8935354d3f6d767cff6c4eebeb683777f2
Subproject commit 7ff249bcd4da6678c5779d9664633c039fb50c0a