Miscellaneous fixes

This commit is contained in:
Chlumsky 2023-01-25 22:32:35 +01:00
parent 132c3af316
commit f6a1bc9f76
4 changed files with 37 additions and 3 deletions

View File

@ -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)

View File

@ -2,11 +2,22 @@
#include "bitmap-blit.h"
#include <cstring>
#include <algorithm>
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 <typename T, int N>
void blitSameType(const msdfgen::BitmapRef<T, N> &dst, const msdfgen::BitmapConstRef<T, N> &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<byte, 1> &dst, const msdfgen::BitmapConstRef<float, 1> &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<byte, 1> &dst, const msdfgen::BitmapConstRef<
}
void blit(const msdfgen::BitmapRef<byte, 3> &dst, const msdfgen::BitmapConstRef<float, 3> &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<byte, 3> &dst, const msdfgen::BitmapConstRef<
}
void blit(const msdfgen::BitmapRef<byte, 4> &dst, const msdfgen::BitmapConstRef<float, 4> &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) {

View File

@ -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;

View File

@ -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");