Skip to content

Commit

Permalink
Added -windingpreprocess option
Browse files Browse the repository at this point in the history
  • Loading branch information
Chlumsky committed Nov 14, 2021
1 parent 0b633e7 commit 64a91ee
Showing 1 changed file with 38 additions and 20 deletions.
58 changes: 38 additions & 20 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ static const char *helpText =
"\tRenders an image preview without flattening the color channels.\n"
" -translate <x> <y>\n"
"\tSets the translation of the shape in shape units.\n"
" -windingpreprocess\n"
"\tAttempts to fix only the contour windings assuming no self-intersections and even-odd fill rule.\n"
" -yflip\n"
"\tInverts the Y axis in the output distance field. The default order is bottom to top.\n"
"\n";
Expand Down Expand Up @@ -417,17 +419,21 @@ int main(int argc, const char * const *argv) {
MULTI_AND_TRUE,
METRICS
} mode = MULTI;
bool legacyMode = false;
bool geometryPreproc = (
enum {
NO_PREPROCESS,
WINDING_PREPROCESS,
FULL_PREPROCESS
} geometryPreproc = (
#ifdef MSDFGEN_USE_SKIA
true
FULL_PREPROCESS
#else
false
NO_PREPROCESS
#endif
);
bool legacyMode = false;
MSDFGeneratorConfig generatorConfig;
generatorConfig.overlapSupport = !geometryPreproc;
bool scanlinePass = !geometryPreproc;
generatorConfig.overlapSupport = geometryPreproc == NO_PREPROCESS;
bool scanlinePass = geometryPreproc == NO_PREPROCESS;
FillRule fillRule = FILL_NONZERO;
Format format = AUTO;
const char *input = NULL;
Expand Down Expand Up @@ -542,12 +548,17 @@ int main(int argc, const char * const *argv) {
continue;
}
ARG_CASE("-nopreprocess", 0) {
geometryPreproc = false;
geometryPreproc = NO_PREPROCESS;
argPos += 1;
continue;
}
ARG_CASE("-windingpreprocess", 0) {
geometryPreproc = WINDING_PREPROCESS;
argPos += 1;
continue;
}
ARG_CASE("-preprocess", 0) {
geometryPreproc = true;
geometryPreproc = FULL_PREPROCESS;
argPos += 1;
continue;
}
Expand Down Expand Up @@ -872,17 +883,24 @@ int main(int argc, const char * const *argv) {
// Validate and normalize shape
if (!shape.validate())
ABORT("The geometry of the loaded shape is invalid.");
if (geometryPreproc) {
#ifdef MSDFGEN_USE_SKIA
if (!resolveShapeGeometry(shape))
puts("Shape geometry preprocessing failed, skipping.");
else if (skipColoring) {
skipColoring = false;
puts("Note: Input shape coloring won't be preserved due to geometry preprocessing");
}
#else
ABORT("Shape geometry preprocessing (-preprocess) is not available in this version because the Skia library is not present.");
#endif
switch (geometryPreproc) {
case NO_PREPROCESS:
break;
case WINDING_PREPROCESS:
shape.orientContours();
break;
case FULL_PREPROCESS:
#ifdef MSDFGEN_USE_SKIA
if (!resolveShapeGeometry(shape))
puts("Shape geometry preprocessing failed, skipping.");
else if (skipColoring) {
skipColoring = false;
puts("Note: Input shape coloring won't be preserved due to geometry preprocessing");
}
#else
ABORT("Shape geometry preprocessing (-preprocess) is not available in this version because the Skia library is not present.");
#endif
break;
}
shape.normalize();
if (yFlip)
Expand Down Expand Up @@ -968,7 +986,7 @@ int main(int argc, const char * const *argv) {
case ErrorCorrectionConfig::EDGE_PRIORITY: fallbackModeName = "auto-fast"; break;
case ErrorCorrectionConfig::EDGE_ONLY: fallbackModeName = "edge-fast"; break;
}
printf("Selected error correction mode not compatible with scanline mode, falling back to %s.\n", fallbackModeName);
printf("Selected error correction mode not compatible with scanline pass, falling back to %s.\n", fallbackModeName);
}
generatorConfig.errorCorrection.mode = ErrorCorrectionConfig::DISABLED;
postErrorCorrectionConfig.errorCorrection.distanceCheckMode = ErrorCorrectionConfig::DO_NOT_CHECK_DISTANCE;
Expand Down

0 comments on commit 64a91ee

Please sign in to comment.