From 0286aeb6eb452ec1cd9636b43cf303d33f61eb31 Mon Sep 17 00:00:00 2001 From: Chlumsky Date: Sat, 15 Apr 2023 17:33:32 +0200 Subject: [PATCH] Advanced SVG decoding --- CMakeLists.txt | 15 ++ core/MSDFErrorCorrection.cpp | 4 +- ext/import-svg.cpp | 302 ++++++++++++++++++++++++++++++--- ext/import-svg.h | 16 +- ext/resolve-shape-geometry.cpp | 12 +- ext/save-png.cpp | 1 + main.cpp | 30 ++-- 7 files changed, 338 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e39e593..5ddf9da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,14 @@ endif() # Version is specified in vcpkg.json project(msdfgen VERSION ${MSDFGEN_VERSION} LANGUAGES CXX) +if(MAX_WARNING_LEVEL) + if (MSVC) + add_compile_options(/W4) + else() + add_compile_options(-Wall -Wextra -Wpedantic) + endif() +endif() + file(GLOB_RECURSE MSDFGEN_CORE_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "core/*.h" "core/*.hpp") file(GLOB_RECURSE MSDFGEN_CORE_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "core/*.cpp") file(GLOB_RECURSE MSDFGEN_EXT_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "ext/*.h" "ext/*.hpp") @@ -178,6 +186,13 @@ if(NOT MSDFGEN_CORE_ONLY) target_link_libraries(msdfgen-ext PRIVATE Threads::Threads ${MSDFGEN_SKIA_LIB}) endif() + if(BUILD_SHARED_LIBS AND WIN32) + target_compile_definitions(msdfgen-ext PRIVATE "MSDFGEN_EXT_PUBLIC=__declspec(dllexport)") + target_compile_definitions(msdfgen-ext INTERFACE "MSDFGEN_EXT_PUBLIC=__declspec(dllimport)") + else() + target_compile_definitions(msdfgen-ext PUBLIC MSDFGEN_EXT_PUBLIC=) + endif() + add_library(msdfgen-full INTERFACE) add_library(msdfgen::msdfgen ALIAS msdfgen-full) target_link_libraries(msdfgen-full INTERFACE msdfgen::msdfgen-core msdfgen::msdfgen-ext) diff --git a/core/MSDFErrorCorrection.cpp b/core/MSDFErrorCorrection.cpp index 7918597..437069b 100644 --- a/core/MSDFErrorCorrection.cpp +++ b/core/MSDFErrorCorrection.cpp @@ -19,8 +19,8 @@ namespace msdfgen { #define CLASSIFIER_FLAG_CANDIDATE 0x01 #define CLASSIFIER_FLAG_ARTIFACT 0x02 -const double ErrorCorrectionConfig::defaultMinDeviationRatio = 1.11111111111111111; -const double ErrorCorrectionConfig::defaultMinImproveRatio = 1.11111111111111111; +MSDFGEN_PUBLIC const double ErrorCorrectionConfig::defaultMinDeviationRatio = 1.11111111111111111; +MSDFGEN_PUBLIC const double ErrorCorrectionConfig::defaultMinImproveRatio = 1.11111111111111111; /// The base artifact classifier recognizes artifacts based on the contents of the SDF alone. class BaseArtifactClassifier { diff --git a/ext/import-svg.cpp b/ext/import-svg.cpp index 86f2ef4..1e1ff5f 100644 --- a/ext/import-svg.cpp +++ b/ext/import-svg.cpp @@ -5,8 +5,17 @@ #ifndef MSDFGEN_DISABLE_SVG +#include #include +#include #include + +#ifdef MSDFGEN_USE_SKIA +#include +#include +#include +#endif + #include "../core/arithmetics.hpp" #define ARC_SEGMENTS_PER_PI 2 @@ -20,6 +29,13 @@ namespace msdfgen { #define REQUIRE(cond) { if (!(cond)) return false; } #endif +MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_FAILURE = 0x00; +MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_SUCCESS_FLAG = 0x01; +MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_PARTIAL_FAILURE_FLAG = 0x02; +MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_INCOMPLETE_FLAG = 0x04; +MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_UNSUPPORTED_FEATURE_FLAG = 0x08; +MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_TRANSFORMATION_IGNORED_FLAG = 0x10; + static void skipExtraChars(const char *&pathDef) { while (*pathDef == ',' || *pathDef == ' ' || *pathDef == '\t' || *pathDef == '\r' || *pathDef == '\n') ++pathDef; @@ -131,6 +147,46 @@ static void addArcApproximate(Contour &contour, Point2 startPoint, Point2 endPoi } } +#define FLAGS_FINAL(flags) (((flags)&(SVG_IMPORT_SUCCESS_FLAG|SVG_IMPORT_INCOMPLETE_FLAG|SVG_IMPORT_UNSUPPORTED_FEATURE_FLAG)) == (SVG_IMPORT_SUCCESS_FLAG|SVG_IMPORT_INCOMPLETE_FLAG|SVG_IMPORT_UNSUPPORTED_FEATURE_FLAG)) + +static void findPathByForwardIndex(tinyxml2::XMLElement *&path, int &flags, int &skips, tinyxml2::XMLElement *parent, bool hasTransformation) { + for (tinyxml2::XMLElement *cur = parent->FirstChildElement(); cur && !FLAGS_FINAL(flags); cur = cur->NextSiblingElement()) { + if (!strcmp(cur->Name(), "path")) { + if (!skips--) { + path = cur; + flags |= SVG_IMPORT_SUCCESS_FLAG; + if (hasTransformation || cur->Attribute("transform")) + flags |= SVG_IMPORT_TRANSFORMATION_IGNORED_FLAG; + } else if (flags&SVG_IMPORT_SUCCESS_FLAG) + flags |= SVG_IMPORT_INCOMPLETE_FLAG; + } else if (!strcmp(cur->Name(), "g")) + findPathByForwardIndex(path, flags, skips, cur, hasTransformation || cur->Attribute("transform")); + else if (!strcmp(cur->Name(), "rect") || !strcmp(cur->Name(), "circle") || !strcmp(cur->Name(), "ellipse") || !strcmp(cur->Name(), "polygon")) + flags |= SVG_IMPORT_INCOMPLETE_FLAG; + else if (!strcmp(cur->Name(), "mask") || !strcmp(cur->Name(), "use")) + flags |= SVG_IMPORT_UNSUPPORTED_FEATURE_FLAG; + } +} + +static void findPathByBackwardIndex(tinyxml2::XMLElement *&path, int &flags, int &skips, tinyxml2::XMLElement *parent, bool hasTransformation) { + for (tinyxml2::XMLElement *cur = parent->LastChildElement(); cur && !FLAGS_FINAL(flags); cur = cur->PreviousSiblingElement()) { + if (!strcmp(cur->Name(), "path")) { + if (!skips--) { + path = cur; + flags |= SVG_IMPORT_SUCCESS_FLAG; + if (hasTransformation || cur->Attribute("transform")) + flags |= SVG_IMPORT_TRANSFORMATION_IGNORED_FLAG; + } else if (flags&SVG_IMPORT_SUCCESS_FLAG) + flags |= SVG_IMPORT_INCOMPLETE_FLAG; + } else if (!strcmp(cur->Name(), "g")) + findPathByBackwardIndex(path, flags, skips, cur, hasTransformation || cur->Attribute("transform")); + else if (!strcmp(cur->Name(), "rect") || !strcmp(cur->Name(), "circle") || !strcmp(cur->Name(), "ellipse") || !strcmp(cur->Name(), "polygon")) + flags |= SVG_IMPORT_INCOMPLETE_FLAG; + else if (!strcmp(cur->Name(), "mask") || !strcmp(cur->Name(), "use")) + flags |= SVG_IMPORT_UNSUPPORTED_FEATURE_FLAG; + } +} + bool buildShapeFromSvgPath(Shape &shape, const char *pathDef, double endpointSnapRange) { char nodeType = '\0'; char prevNodeType = '\0'; @@ -270,45 +326,237 @@ bool loadSvgShape(Shape &output, const char *filename, int pathIndex, Vector2 *d return false; tinyxml2::XMLElement *path = NULL; - if (pathIndex > 0) { - path = root->FirstChildElement("path"); - if (!path) { - tinyxml2::XMLElement *g = root->FirstChildElement("g"); - if (g) - path = g->FirstChildElement("path"); - } - while (path && --pathIndex > 0) - path = path->NextSiblingElement("path"); - } else { - path = root->LastChildElement("path"); - if (!path) { - tinyxml2::XMLElement *g = root->LastChildElement("g"); - if (g) - path = g->LastChildElement("path"); - } - while (path && ++pathIndex < 0) - path = path->PreviousSiblingElement("path"); - } + int flags = 0; + int skippedPaths = abs(pathIndex)-(pathIndex != 0); + if (pathIndex > 0) + findPathByForwardIndex(path, flags, skippedPaths, root, false); + else + findPathByBackwardIndex(path, flags, skippedPaths, root, false); if (!path) return false; const char *pd = path->Attribute("d"); if (!pd) return false; - output.contours.clear(); - output.inverseYAxis = true; Vector2 dims(root->DoubleAttribute("width"), root->DoubleAttribute("height")); - if (!dims) { - double left, top; - const char *viewBox = root->Attribute("viewBox"); - if (viewBox) - sscanf(viewBox, "%lf %lf %lf %lf", &left, &top, &dims.x, &dims.y); - } + double left, top; + const char *viewBox = root->Attribute("viewBox"); + if (viewBox) + sscanf(viewBox, "%lf %lf %lf %lf", &left, &top, &dims.x, &dims.y); if (dimensions) *dimensions = dims; + output.contours.clear(); + output.inverseYAxis = true; return buildShapeFromSvgPath(output, pd, ENDPOINT_SNAP_RANGE_PROPORTION*dims.length()); } +#ifndef MSDFGEN_USE_SKIA + +int loadSvgShape(Shape &output, Shape::Bounds &viewBox, const char *filename) { + tinyxml2::XMLDocument doc; + if (doc.LoadFile(filename)) + return SVG_IMPORT_FAILURE; + tinyxml2::XMLElement *root = doc.FirstChildElement("svg"); + if (!root) + return SVG_IMPORT_FAILURE; + + tinyxml2::XMLElement *path = NULL; + int flags = 0; + int skippedPaths = 0; + findPathByBackwardIndex(path, flags, skippedPaths, root, false); + if (!(path && (flags&SVG_IMPORT_SUCCESS_FLAG))) + return SVG_IMPORT_FAILURE; + const char *pd = path->Attribute("d"); + if (!pd) + return SVG_IMPORT_FAILURE; + + viewBox.l = 0, viewBox.b = 0; + Vector2 dims(root->DoubleAttribute("width"), root->DoubleAttribute("height")); + const char *viewBoxStr = root->Attribute("viewBox"); + if (viewBoxStr) + sscanf(viewBoxStr, "%lf %lf %lf %lf", &viewBox.l, &viewBox.b, &dims.x, &dims.y); + viewBox.r = viewBox.l+dims.x; + viewBox.t = viewBox.b+dims.y; + output.contours.clear(); + output.inverseYAxis = true; + if (!buildShapeFromSvgPath(output, pd, ENDPOINT_SNAP_RANGE_PROPORTION*dims.length())) + return SVG_IMPORT_FAILURE; + return flags; +} + +#else + +void shapeFromSkiaPath(Shape &shape, const SkPath &skPath); // defined in resolve-shape-geometry.cpp + +static bool readTransformationOp(SkScalar dst[6], int &count, const char *&str, const char *name) { + int nameLen = int(strlen(name)); + if (!memcmp(str, name, nameLen)) { + const char *curStr = str+nameLen; + skipExtraChars(curStr); + if (*curStr == '(') { + skipExtraChars(++curStr); + count = 0; + while (*curStr && *curStr != ')') { + double x; + if (!(count < 6 && readDouble(x, curStr))) + return false; + dst[count++] = SkScalar(x); + skipExtraChars(curStr); + } + if (*curStr == ')') { + str = curStr+1; + return true; + } + } + } + return false; +} + +static SkMatrix parseTransformation(int &flags, const char *str) { + SkMatrix transformation; + skipExtraChars(str); + while (*str) { + SkScalar values[6]; + int count; + SkMatrix partial; + if (readTransformationOp(values, count, str, "matrix") && count == 6) { + partial.setAll(values[0], values[2], values[4], values[1], values[3], values[5], SkScalar(0), SkScalar(0), SkScalar(1)); + } else if (readTransformationOp(values, count, str, "translate") && (count == 1 || count == 2)) { + if (count == 1) + values[1] = SkScalar(0); + partial.setTranslate(values[0], values[1]); + } else if (readTransformationOp(values, count, str, "scale") && (count == 1 || count == 2)) { + if (count == 1) + values[1] = values[0]; + partial.setScale(values[0], values[1]); + } else if (readTransformationOp(values, count, str, "rotate") && (count == 1 || count == 3)) { + if (count == 3) + partial.setRotate(values[0], values[1], values[2]); + else + partial.setRotate(values[0]); + } else if (readTransformationOp(values, count, str, "skewX") && count == 1) { + partial.setSkewX(SkScalar(tan(M_PI/180*values[0]))); + } else if (readTransformationOp(values, count, str, "skewY") && count == 1) { + partial.setSkewY(SkScalar(tan(M_PI/180*values[0]))); + } else { + flags |= SVG_IMPORT_PARTIAL_FAILURE_FLAG; + break; + } + transformation = transformation*partial; + skipExtraChars(str); + } + return transformation; +} + +static SkMatrix combineTransformation(int &flags, const SkMatrix &parentTransformation, const char *transformationString, const char *transformationOriginString) { + if (transformationString) { + SkMatrix transformation = parseTransformation(flags, transformationString); + if (transformationOriginString) { + Point2 origin; + if (readCoord(origin, transformationOriginString)) + transformation = SkMatrix::Translate(SkScalar(origin.x), SkScalar(origin.y))*transformation*SkMatrix::Translate(SkScalar(-origin.x), SkScalar(-origin.y)); + else + flags |= SVG_IMPORT_PARTIAL_FAILURE_FLAG; + } + return parentTransformation*transformation; + } + return parentTransformation; +} + +static void gatherPaths(SkPath &fullPath, int &flags, tinyxml2::XMLElement *parent, const SkMatrix &transformation) { + for (tinyxml2::XMLElement *cur = parent->FirstChildElement(); cur && !FLAGS_FINAL(flags); cur = cur->NextSiblingElement()) { + if (!strcmp(cur->Name(), "g")) + gatherPaths(fullPath, flags, cur, combineTransformation(flags, transformation, cur->Attribute("transform"), cur->Attribute("transform-origin"))); + else if (!strcmp(cur->Name(), "mask") || !strcmp(cur->Name(), "use")) + flags |= SVG_IMPORT_UNSUPPORTED_FEATURE_FLAG; + else { + SkPath curPath; + if (!strcmp(cur->Name(), "path")) { + const char *pd = cur->Attribute("d"); + if (!(pd && SkParsePath::FromSVGString(pd, &curPath))) { + flags |= SVG_IMPORT_PARTIAL_FAILURE_FLAG; + continue; + } + } else if (!strcmp(cur->Name(), "rect")) { + SkScalar x = SkScalar(cur->DoubleAttribute("x")), y = SkScalar(cur->DoubleAttribute("y")); + SkScalar width = SkScalar(cur->DoubleAttribute("width")), height = SkScalar(cur->DoubleAttribute("height")); + SkScalar rx = SkScalar(cur->DoubleAttribute("rx")), ry = SkScalar(cur->DoubleAttribute("ry")); + if (!(width && height)) + continue; + SkRect rect = SkRect::MakeLTRB(x, y, x+width, y+height); + if (rx || ry) { + SkScalar radii[] = { rx, ry, rx, ry, rx, ry, rx, ry }; + curPath.addRoundRect(rect, radii); + } else + curPath.addRect(rect); + } else if (!strcmp(cur->Name(), "circle")) { + SkScalar cx = SkScalar(cur->DoubleAttribute("cx")), cy = SkScalar(cur->DoubleAttribute("cy")); + SkScalar r = SkScalar(cur->DoubleAttribute("r")); + if (!r) + continue; + curPath.addCircle(cx, cy, r); + } else if (!strcmp(cur->Name(), "ellipse")) { + SkScalar cx = SkScalar(cur->DoubleAttribute("cx")), cy = SkScalar(cur->DoubleAttribute("cy")); + SkScalar rx = SkScalar(cur->DoubleAttribute("rx")), ry = SkScalar(cur->DoubleAttribute("ry")); + if (!(rx && ry)) + continue; + curPath.addOval(SkRect::MakeLTRB(cx-rx, cy-ry, cx+rx, cy+ry)); + } else if (!strcmp(cur->Name(), "polygon")) { + const char *pd = cur->Attribute("points"); + if (!pd) { + flags |= SVG_IMPORT_PARTIAL_FAILURE_FLAG; + continue; + } + Point2 point; + if (!readCoord(point, pd)) + continue; + curPath.moveTo(SkScalar(point.x), SkScalar(point.y)); + if (!readCoord(point, pd)) + continue; + do { + curPath.lineTo(SkScalar(point.x), SkScalar(point.y)); + } while (readCoord(point, pd)); + curPath.close(); + } else + continue; + curPath.transform(combineTransformation(flags, transformation, cur->Attribute("transform"), cur->Attribute("transform-origin"))); + if (Op(fullPath, curPath, kUnion_SkPathOp, &fullPath)) + flags |= SVG_IMPORT_SUCCESS_FLAG; + else + flags |= SVG_IMPORT_PARTIAL_FAILURE_FLAG; + } + } +} + +int loadSvgShape(Shape &output, Shape::Bounds &viewBox, const char *filename) { + tinyxml2::XMLDocument doc; + if (doc.LoadFile(filename)) + return SVG_IMPORT_FAILURE; + tinyxml2::XMLElement *root = doc.FirstChildElement("svg"); + if (!root) + return SVG_IMPORT_FAILURE; + + SkPath fullPath; + int flags = 0; + gatherPaths(fullPath, flags, root, SkMatrix()); + if (!((flags&SVG_IMPORT_SUCCESS_FLAG) && Simplify(fullPath, &fullPath))) + return SVG_IMPORT_FAILURE; + shapeFromSkiaPath(output, fullPath); + output.inverseYAxis = true; + output.orientContours(); + + viewBox.l = 0, viewBox.b = 0; + Vector2 dims(root->DoubleAttribute("width"), root->DoubleAttribute("height")); + const char *viewBoxStr = root->Attribute("viewBox"); + if (viewBoxStr) + sscanf(viewBoxStr, "%lf %lf %lf %lf", &viewBox.l, &viewBox.b, &dims.x, &dims.y); + viewBox.r = viewBox.l+dims.x; + viewBox.t = viewBox.b+dims.y; + return flags; +} + +#endif + } #endif diff --git a/ext/import-svg.h b/ext/import-svg.h index 2e0761e..6be61ad 100644 --- a/ext/import-svg.h +++ b/ext/import-svg.h @@ -6,14 +6,28 @@ #ifndef MSDFGEN_DISABLE_SVG +#ifndef MSDFGEN_EXT_PUBLIC +#define MSDFGEN_EXT_PUBLIC // for DLL import/export +#endif + namespace msdfgen { +extern MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_FAILURE; +extern MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_SUCCESS_FLAG; +extern MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_PARTIAL_FAILURE_FLAG; +extern MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_INCOMPLETE_FLAG; +extern MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_UNSUPPORTED_FEATURE_FLAG; +extern MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_TRANSFORMATION_IGNORED_FLAG; + /// Builds a shape from an SVG path string bool buildShapeFromSvgPath(Shape &shape, const char *pathDef, double endpointSnapRange = 0); -/// Reads the first path found in the specified SVG file and stores it as a Shape in output. +/// Reads a single element found in the specified SVG file and converts it to output Shape bool loadSvgShape(Shape &output, const char *filename, int pathIndex = 0, Vector2 *dimensions = NULL); +/// New version - if Skia is available, reads the entire geometry of the SVG file into the output Shape, otherwise may only read one path, returns SVG import flags +int loadSvgShape(Shape &output, Shape::Bounds &viewBox, const char *filename); + } #endif diff --git a/ext/resolve-shape-geometry.cpp b/ext/resolve-shape-geometry.cpp index 56b8595..cd78d48 100644 --- a/ext/resolve-shape-geometry.cpp +++ b/ext/resolve-shape-geometry.cpp @@ -55,7 +55,17 @@ void shapeFromSkiaPath(Shape &shape, const SkPath &skPath) { case SkPath::kCubic_Verb: contour->addEdge(new CubicSegment(pointFromSkiaPoint(edgePoints[0]), pointFromSkiaPoint(edgePoints[1]), pointFromSkiaPoint(edgePoints[2]), pointFromSkiaPoint(edgePoints[3]))); break; - default:; + case SkPath::kConic_Verb: + { + SkPoint quadPoints[5]; + SkPath::ConvertConicToQuads(edgePoints[0], edgePoints[1], edgePoints[2], pathIterator.conicWeight(), quadPoints, 1); + contour->addEdge(new QuadraticSegment(pointFromSkiaPoint(quadPoints[0]), pointFromSkiaPoint(quadPoints[1]), pointFromSkiaPoint(quadPoints[2]))); + contour->addEdge(new QuadraticSegment(pointFromSkiaPoint(quadPoints[2]), pointFromSkiaPoint(quadPoints[3]), pointFromSkiaPoint(quadPoints[4]))); + } + break; + case SkPath::kClose_Verb: + case SkPath::kDone_Verb: + break; } } if (contour->edges.empty()) diff --git a/ext/save-png.cpp b/ext/save-png.cpp index 3fa8e96..3c84cbf 100644 --- a/ext/save-png.cpp +++ b/ext/save-png.cpp @@ -1,4 +1,5 @@ +#define _CRT_SECURE_NO_WARNINGS #include "save-png.h" #include diff --git a/main.cpp b/main.cpp index 9d6c165..05317b9 100644 --- a/main.cpp +++ b/main.cpp @@ -532,7 +532,6 @@ int main(int argc, const char * const *argv) { bool glyphIndexSpecified = false; GlyphIndex glyphIndex; unicode_t unicode = 0; - int svgPathIndex = 0; #endif int width = 64, height = 64; @@ -947,7 +946,7 @@ int main(int argc, const char * const *argv) { fprintf(stderr, "Use -help for more information.\n"); // Load input - Vector2 svgDims; + Shape::Bounds svgViewBox = { }; double glyphAdvance = 0; if (!inputType || !input) { #ifdef MSDFGEN_EXTENSIONS @@ -966,8 +965,17 @@ int main(int argc, const char * const *argv) { switch (inputType) { #if defined(MSDFGEN_EXTENSIONS) && !defined(MSDFGEN_DISABLE_SVG) case SVG: { - if (!loadSvgShape(shape, input, svgPathIndex, &svgDims)) + int svgImportFlags = loadSvgShape(shape, svgViewBox, input); + if (!(svgImportFlags&SVG_IMPORT_SUCCESS_FLAG)) ABORT("Failed to load shape from SVG file."); + if (svgImportFlags&SVG_IMPORT_PARTIAL_FAILURE_FLAG) + fputs("Warning: Failed to load part of SVG file.\n", stderr); + if (svgImportFlags&SVG_IMPORT_INCOMPLETE_FLAG) + fputs("Warning: SVG file contains multiple paths or shapes but this version is only able to load one.\n", stderr); + else if (svgImportFlags&SVG_IMPORT_UNSUPPORTED_FEATURE_FLAG) + fputs("Warning: SVG file likely contains elements that are unsupported.\n", stderr); + if (svgImportFlags&SVG_IMPORT_TRANSFORMATION_IGNORED_FLAG) + fputs("Warning: SVG path transformation ignored.\n", stderr); break; } #endif @@ -1096,19 +1104,19 @@ int main(int argc, const char * const *argv) { ABORT("Failed to write output file."); if (shape.inverseYAxis) fprintf(out, "inverseY = true\n"); - if (bounds.r >= bounds.l && bounds.t >= bounds.b) - fprintf(out, "bounds = %.12g, %.12g, %.12g, %.12g\n", bounds.l, bounds.b, bounds.r, bounds.t); - if (svgDims.x != 0 && svgDims.y != 0) - fprintf(out, "dimensions = %.12g, %.12g\n", svgDims.x, svgDims.y); + if (svgViewBox.l < svgViewBox.r && svgViewBox.b < svgViewBox.t) + fprintf(out, "view box = %.17g, %.17g, %.17g, %.17g\n", svgViewBox.l, svgViewBox.b, svgViewBox.r, svgViewBox.t); + if (bounds.l < bounds.r && bounds.b < bounds.t) + fprintf(out, "bounds = %.17g, %.17g, %.17g, %.17g\n", bounds.l, bounds.b, bounds.r, bounds.t); if (glyphAdvance != 0) - fprintf(out, "advance = %.12g\n", glyphAdvance); + fprintf(out, "advance = %.17g\n", glyphAdvance); if (autoFrame) { if (!scaleSpecified) - fprintf(out, "scale = %.12g\n", avgScale); - fprintf(out, "translate = %.12g, %.12g\n", translate.x, translate.y); + fprintf(out, "scale = %.17g\n", avgScale); + fprintf(out, "translate = %.17g, %.17g\n", translate.x, translate.y); } if (rangeMode == RANGE_PX) - fprintf(out, "range = %.12g\n", range); + fprintf(out, "range = %.17g\n", range); if (mode == METRICS && outputSpecified) fclose(out); }