Added -windingpreprocess option

This commit is contained in:
Chlumsky 2021-11-14 13:20:41 +01:00
parent 0b633e75f7
commit 64a91eec3c
1 changed files with 38 additions and 20 deletions

View File

@ -371,6 +371,8 @@ static const char *helpText =
"\tRenders an image preview without flattening the color channels.\n" "\tRenders an image preview without flattening the color channels.\n"
" -translate <x> <y>\n" " -translate <x> <y>\n"
"\tSets the translation of the shape in shape units.\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" " -yflip\n"
"\tInverts the Y axis in the output distance field. The default order is bottom to top.\n" "\tInverts the Y axis in the output distance field. The default order is bottom to top.\n"
"\n"; "\n";
@ -417,17 +419,21 @@ int main(int argc, const char * const *argv) {
MULTI_AND_TRUE, MULTI_AND_TRUE,
METRICS METRICS
} mode = MULTI; } mode = MULTI;
bool legacyMode = false; enum {
bool geometryPreproc = ( NO_PREPROCESS,
WINDING_PREPROCESS,
FULL_PREPROCESS
} geometryPreproc = (
#ifdef MSDFGEN_USE_SKIA #ifdef MSDFGEN_USE_SKIA
true FULL_PREPROCESS
#else #else
false NO_PREPROCESS
#endif #endif
); );
bool legacyMode = false;
MSDFGeneratorConfig generatorConfig; MSDFGeneratorConfig generatorConfig;
generatorConfig.overlapSupport = !geometryPreproc; generatorConfig.overlapSupport = geometryPreproc == NO_PREPROCESS;
bool scanlinePass = !geometryPreproc; bool scanlinePass = geometryPreproc == NO_PREPROCESS;
FillRule fillRule = FILL_NONZERO; FillRule fillRule = FILL_NONZERO;
Format format = AUTO; Format format = AUTO;
const char *input = NULL; const char *input = NULL;
@ -542,12 +548,17 @@ int main(int argc, const char * const *argv) {
continue; continue;
} }
ARG_CASE("-nopreprocess", 0) { ARG_CASE("-nopreprocess", 0) {
geometryPreproc = false; geometryPreproc = NO_PREPROCESS;
argPos += 1;
continue;
}
ARG_CASE("-windingpreprocess", 0) {
geometryPreproc = WINDING_PREPROCESS;
argPos += 1; argPos += 1;
continue; continue;
} }
ARG_CASE("-preprocess", 0) { ARG_CASE("-preprocess", 0) {
geometryPreproc = true; geometryPreproc = FULL_PREPROCESS;
argPos += 1; argPos += 1;
continue; continue;
} }
@ -872,17 +883,24 @@ int main(int argc, const char * const *argv) {
// Validate and normalize shape // Validate and normalize shape
if (!shape.validate()) if (!shape.validate())
ABORT("The geometry of the loaded shape is invalid."); ABORT("The geometry of the loaded shape is invalid.");
if (geometryPreproc) { switch (geometryPreproc) {
#ifdef MSDFGEN_USE_SKIA case NO_PREPROCESS:
if (!resolveShapeGeometry(shape)) break;
puts("Shape geometry preprocessing failed, skipping."); case WINDING_PREPROCESS:
else if (skipColoring) { shape.orientContours();
skipColoring = false; break;
puts("Note: Input shape coloring won't be preserved due to geometry preprocessing"); case FULL_PREPROCESS:
} #ifdef MSDFGEN_USE_SKIA
#else if (!resolveShapeGeometry(shape))
ABORT("Shape geometry preprocessing (-preprocess) is not available in this version because the Skia library is not present."); puts("Shape geometry preprocessing failed, skipping.");
#endif 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(); shape.normalize();
if (yFlip) if (yFlip)
@ -968,7 +986,7 @@ int main(int argc, const char * const *argv) {
case ErrorCorrectionConfig::EDGE_PRIORITY: fallbackModeName = "auto-fast"; break; case ErrorCorrectionConfig::EDGE_PRIORITY: fallbackModeName = "auto-fast"; break;
case ErrorCorrectionConfig::EDGE_ONLY: fallbackModeName = "edge-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; generatorConfig.errorCorrection.mode = ErrorCorrectionConfig::DISABLED;
postErrorCorrectionConfig.errorCorrection.distanceCheckMode = ErrorCorrectionConfig::DO_NOT_CHECK_DISTANCE; postErrorCorrectionConfig.errorCorrection.distanceCheckMode = ErrorCorrectionConfig::DO_NOT_CHECK_DISTANCE;