Skip to content

Commit

Permalink
Added -coloringstrategy option, version 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Chlumsky committed May 29, 2021
1 parent 0e81034 commit a49bf0d
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ x64/
*.suo
*.VC.opendb
*.VC.db
bin/msdf-atlas-gen
bin/*.lib
output.png
out/
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

## Version 1.2 (2021-05-29)

- Updated to MSDFgen 1.9.
- Multiple fonts or font sizes can now be compiled into a single atlas.
- Added `-yorigin` option to choose if Y-coordinates increase from bottom to top or from top to bottom.
- Added `-coloringstrategy` option to select MSDF edge coloring heuristic.
- Shadron preview now properly loads floating-point image outputs in full range mode.

## Version 1.1 (2020-10-18)

- Updated to MSDFgen 1.8.
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,17 @@ Any non-empty subset of the following may be specified:
### Distance field generator settings

- `-angle <angle>` &ndash; sets the minimum angle between adjacent edges to be considered a corner. Append D for degrees (`msdf` / `mtsdf` only)
- `-errorcorrection <threshold>` &ndash; sets the threshold used to detect and correct potential artifacts. 0 disables error correction (`msdf` / `mtsdf` only)
- `-coloringstrategy <simple / inktrap / distance>` &ndash; selects the edge coloring heuristic (`msdf` / `mtsdf` only)
- `-errorcorrection <mode>` &ndash; selects the error correction algorithm. Use `help` as mode for more information (`msdf` / `mtsdf` only)
- `-miterlimit <value>` &ndash; sets the miter limit that limits the extension of each glyph's bounding box due to very sharp corners (`psdf` / `msdf` / `mtsdf` only)
- `-overlap` &ndash; switches to distance field generator with support for overlapping contours
- `-nopreprocess` &ndash; disables path preprocessing which resolves self-intersections and overlapping contours
- `-scanline` &ndash; performs an additional scanline pass to fix the signs of the distances
- `-seed <N>` &ndash; sets the initial seed for the edge coloring heuristic
- `-threads <N>` &ndash; sets the number of threads for the parallel computation (0 = auto)

Use `-help` for an exhaustive list of options.

## Character set specification syntax

The character set file is a text file with UTF-8 or ASCII encoding.
Expand Down
Binary file modified msdf-atlas-gen.aps
Binary file not shown.
Binary file modified msdf-atlas-gen.rc
Binary file not shown.
4 changes: 2 additions & 2 deletions msdf-atlas-gen/GlyphGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ bool GlyphGeometry::load(msdfgen::FontHandle *font, double geometryScale, unicod
return false;
}

void GlyphGeometry::edgeColoring(double angleThreshold, unsigned long long seed) {
msdfgen::edgeColoringInkTrap(shape, angleThreshold, seed);
void GlyphGeometry::edgeColoring(void (*fn)(msdfgen::Shape &, double, unsigned long long), double angleThreshold, unsigned long long seed) {
fn(shape, angleThreshold, seed);
}

void GlyphGeometry::wrapBox(double scale, double range, double miterLimit) {
Expand Down
2 changes: 1 addition & 1 deletion msdf-atlas-gen/GlyphGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GlyphGeometry {
bool load(msdfgen::FontHandle *font, double geometryScale, msdfgen::GlyphIndex index, bool preprocessGeometry = true);
bool load(msdfgen::FontHandle *font, double geometryScale, unicode_t codepoint, bool preprocessGeometry = true);
/// Applies edge coloring to glyph shape
void edgeColoring(double angleThreshold, unsigned long long seed);
void edgeColoring(void (*fn)(msdfgen::Shape &, double, unsigned long long), double angleThreshold, unsigned long long seed);
/// Computes the dimensions of the glyph's box as well as the transformation for the generator function
void wrapBox(double scale, double range, double miterLimit);
/// Sets the glyph's box's position in the atlas
Expand Down
37 changes: 30 additions & 7 deletions msdf-atlas-gen/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

/*
* MULTI-CHANNEL SIGNED DISTANCE FIELD ATLAS GENERATOR v1.1 (2020-10-18) - standalone console program
* MULTI-CHANNEL SIGNED DISTANCE FIELD ATLAS GENERATOR v1.2 (2021-05-29) - standalone console program
* --------------------------------------------------------------------------------------------------
* A utility by Viktor Chlumsky, (c) 2020
* A utility by Viktor Chlumsky, (c) 2020 - 2021
*
*/

Expand All @@ -26,7 +26,8 @@ using namespace msdf_atlas;
#define DEFAULT_PIXEL_RANGE 2.0
#define SDF_ERROR_ESTIMATE_PRECISION 19
#define GLYPH_FILL_RULE msdfgen::FILL_NONZERO
#define MCG_MULTIPLIER 6364136223846793005ull
#define LCG_MULTIPLIER 6364136223846793005ull
#define LCG_INCREMENT 1442695040888963407ull

#ifdef MSDFGEN_USE_SKIA
#define TITLE_SUFFIX " & Skia"
Expand Down Expand Up @@ -94,6 +95,8 @@ GLYPH CONFIGURATION
DISTANCE FIELD GENERATOR SETTINGS
-angle <angle>
Specifies the minimum angle between adjacent edges to be considered a corner. Append D for degrees. (msdf / mtsdf only)
-coloringstrategy <simple / inktrap / distance>
Selects the strategy of the edge coloring heuristic.
-errorcorrection <mode>
Changes the MSDF/MTSDF error correction mode. Use -errorcorrection help for a list of valid modes.
-errordeviationratio <ratio>
Expand Down Expand Up @@ -201,6 +204,8 @@ struct Configuration {
double pxRange;
double angleThreshold;
double miterLimit;
void (*edgeColoring)(msdfgen::Shape &, double, unsigned long long);
bool expensiveColoring;
unsigned long long coloringSeed;
GeneratorAttributes generatorAttributes;
bool preprocessGeometry;
Expand Down Expand Up @@ -263,6 +268,7 @@ int main(int argc, const char * const *argv) {
config.imageType = ImageType::MSDF;
config.imageFormat = ImageFormat::UNSPECIFIED;
config.yDirection = YDirection::BOTTOM_UP;
config.edgeColoring = msdfgen::edgeColoringInkTrap;
config.kerning = true;
const char *imageFormatName = nullptr;
int fixedWidth = -1, fixedHeight = -1;
Expand Down Expand Up @@ -547,6 +553,15 @@ int main(int argc, const char * const *argv) {
argPos += 2;
continue;
}
ARG_CASE("-coloringstrategy", 1) {
if (!strcmp(argv[argPos+1], "simple")) config.edgeColoring = msdfgen::edgeColoringSimple, config.expensiveColoring = false;
else if (!strcmp(argv[argPos+1], "inktrap")) config.edgeColoring = msdfgen::edgeColoringInkTrap, config.expensiveColoring = false;
else if (!strcmp(argv[argPos+1], "distance")) config.edgeColoring = msdfgen::edgeColoringByDistance, config.expensiveColoring = true;
else
puts("Unknown coloring strategy specified.");
argPos += 2;
continue;
}
ARG_CASE("-miterlimit", 1) {
double m;
if (!(parseDouble(m, argv[++argPos]) && m >= 0))
Expand Down Expand Up @@ -891,10 +906,18 @@ int main(int argc, const char * const *argv) {

// Edge coloring
if (config.imageType == ImageType::MSDF || config.imageType == ImageType::MTSDF) {
unsigned long long glyphSeed = config.coloringSeed;
for (GlyphGeometry &glyph : glyphs) {
glyphSeed *= MCG_MULTIPLIER;
glyph.edgeColoring(config.angleThreshold, glyphSeed);
if (config.expensiveColoring) {
Workload([&glyphs, &config](int i, int threadNo) -> bool {
unsigned long long glyphSeed = (LCG_MULTIPLIER*(config.coloringSeed^i)+LCG_INCREMENT)*!!config.coloringSeed;
glyphs[i].edgeColoring(config.edgeColoring, config.angleThreshold, glyphSeed);
return true;
}, glyphs.size()).finish(config.threadCount);
} else {
unsigned long long glyphSeed = config.coloringSeed;
for (GlyphGeometry &glyph : glyphs) {
glyphSeed *= LCG_MULTIPLIER;
glyph.edgeColoring(config.edgeColoring, config.angleThreshold, glyphSeed);
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions msdf-atlas-gen/msdf-atlas-gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#pragma once

/*
* MULTI-CHANNEL SIGNED DISTANCE FIELD ATLAS GENERATOR v1.1 (2020-10-18)
* MULTI-CHANNEL SIGNED DISTANCE FIELD ATLAS GENERATOR v1.2 (2021-05-29)
* ---------------------------------------------------------------------
* A utility by Viktor Chlumsky, (c) 2020
* A utility by Viktor Chlumsky, (c) 2020 - 2021
*
* Generates compact bitmap font atlases using MSDFGEN.
*
Expand Down Expand Up @@ -39,4 +39,4 @@
#include "json-export.h"
#include "shadron-preview-generator.h"

#define MSDF_ATLAS_VERSION "1.1"
#define MSDF_ATLAS_VERSION "1.2"

0 comments on commit a49bf0d

Please sign in to comment.