From f6a1bc9f76cdaee40a4392e4b4c151cdc959bbb9 Mon Sep 17 00:00:00 2001 From: Chlumsky Date: Wed, 25 Jan 2023 22:32:35 +0100 Subject: [PATCH] Miscellaneous fixes --- CHANGELOG.md | 3 +++ msdf-atlas-gen/bitmap-blit.cpp | 14 ++++++++++++++ msdf-atlas-gen/main.cpp | 4 ++-- msdf-atlas-gen/shadron-preview-generator.cpp | 19 ++++++++++++++++++- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc8aa19..8272677 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ - CMake configuration overhaul, added installation configuration - Switched to libpng as the primary PNG file encoder - Added `-varfont` option to configure variables of variable fonts +- Added `-version` option to print program version +- Arguments with double dash (e.g. `--font`) now also accepted +- Minor fix to positioning for `-type hardmask` ### Version 1.2.2 (2021-09-06) diff --git a/msdf-atlas-gen/bitmap-blit.cpp b/msdf-atlas-gen/bitmap-blit.cpp index c1e6afa..56054ed 100644 --- a/msdf-atlas-gen/bitmap-blit.cpp +++ b/msdf-atlas-gen/bitmap-blit.cpp @@ -2,11 +2,22 @@ #include "bitmap-blit.h" #include +#include namespace msdf_atlas { +#define BOUND_AREA() { \ + if (dx < 0) w += dx, sx -= dx, dx = 0; \ + if (dy < 0) h += dy, sy -= dy, dy = 0; \ + if (sx < 0) w += sx, dx -= sx, sx = 0; \ + if (sy < 0) h += sy, dy -= sy, sy = 0; \ + w = std::max(0, std::min(w, std::min(dst.width-dx, src.width-sx))); \ + h = std::max(0, std::min(h, std::min(dst.height-dy, src.height-sy))); \ +} + template void blitSameType(const msdfgen::BitmapRef &dst, const msdfgen::BitmapConstRef &src, int dx, int dy, int sx, int sy, int w, int h) { + BOUND_AREA(); for (int y = 0; y < h; ++y) memcpy(dst(dx, dy+y), src(sx, sy+y), sizeof(T)*N*w); } @@ -21,6 +32,7 @@ BLIT_SAME_TYPE_IMPL(float, 3) BLIT_SAME_TYPE_IMPL(float, 4) void blit(const msdfgen::BitmapRef &dst, const msdfgen::BitmapConstRef &src, int dx, int dy, int sx, int sy, int w, int h) { + BOUND_AREA(); for (int y = 0; y < h; ++y) { byte *dstPixel = dst(dx, dy+y); for (int x = 0; x < w; ++x) { @@ -31,6 +43,7 @@ void blit(const msdfgen::BitmapRef &dst, const msdfgen::BitmapConstRef< } void blit(const msdfgen::BitmapRef &dst, const msdfgen::BitmapConstRef &src, int dx, int dy, int sx, int sy, int w, int h) { + BOUND_AREA(); for (int y = 0; y < h; ++y) { byte *dstPixel = dst(dx, dy+y); for (int x = 0; x < w; ++x) { @@ -43,6 +56,7 @@ void blit(const msdfgen::BitmapRef &dst, const msdfgen::BitmapConstRef< } void blit(const msdfgen::BitmapRef &dst, const msdfgen::BitmapConstRef &src, int dx, int dy, int sx, int sy, int w, int h) { + BOUND_AREA(); for (int y = 0; y < h; ++y) { byte *dstPixel = dst(dx, dy+y); for (int x = 0; x < w; ++x) { diff --git a/msdf-atlas-gen/main.cpp b/msdf-atlas-gen/main.cpp index 623b487..7481546 100644 --- a/msdf-atlas-gen/main.cpp +++ b/msdf-atlas-gen/main.cpp @@ -743,9 +743,9 @@ int main(int argc, const char * const *argv) { puts("Neither atlas size nor glyph size selected, using default..."); minEmSize = MSDF_ATLAS_DEFAULT_EM_SIZE; } - if (!(config.imageType == ImageType::SDF || config.imageType == ImageType::PSDF || config.imageType == ImageType::MSDF || config.imageType == ImageType::MTSDF)) { + if (config.imageType == ImageType::HARD_MASK || config.imageType == ImageType::SOFT_MASK) { rangeMode = RANGE_PIXEL; - rangeValue = (double) (config.imageType == ImageType::SOFT_MASK); + rangeValue = 1; } else if (rangeValue <= 0) { rangeMode = RANGE_PIXEL; rangeValue = DEFAULT_PIXEL_RANGE; diff --git a/msdf-atlas-gen/shadron-preview-generator.cpp b/msdf-atlas-gen/shadron-preview-generator.cpp index 479e773..dabe66c 100644 --- a/msdf-atlas-gen/shadron-preview-generator.cpp +++ b/msdf-atlas-gen/shadron-preview-generator.cpp @@ -77,6 +77,23 @@ static std::string relativizePath(const char *base, const char *target) { return output; } +static std::string escapeString(const std::string &str) { + std::string output; + for (int i = 0; i < (int) str.size(); ++i) { + switch (str[i]) { + case '"': + output += "\\\""; + break; + case '\\': + output += "\\\\"; + break; + default: + output.push_back(str[i]); + } + } + return output; +} + bool generateShadronPreview(const FontGeometry *fonts, int fontCount, ImageType atlasType, int atlasWidth, int atlasHeight, double pxRange, const unicode_t *text, const char *imageFilename, bool fullRange, const char *outputFilename) { if (fontCount <= 0) return false; @@ -88,7 +105,7 @@ bool generateShadronPreview(const FontGeometry *fonts, int fontCount, ImageType return false; fprintf(file, shadronPreviewPreamble, atlasType == ImageType::HARD_MASK || atlasType == ImageType::SOFT_MASK ? shadronFillGlyphMask : shadronFillGlyphSdf); if (imageFilename) - fprintf(file, "image Atlas = file(\"%s\")", relativizePath(outputFilename, imageFilename).c_str()); + fprintf(file, "image Atlas = file(\"%s\")", escapeString(relativizePath(outputFilename, imageFilename)).c_str()); else fprintf(file, "image Atlas = file()"); fprintf(file, " : %sfilter(%s), map(repeat);\n", fullRange ? "full_range(true), " : "", atlasType == ImageType::HARD_MASK ? "nearest" : "linear");