aboutsummaryrefslogtreecommitdiff
path: root/svg-flatten/src/svg_path.cpp
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-10-26 00:03:27 +0200
committerjaseg <git@jaseg.de>2023-10-26 00:04:17 +0200
commit00eb9594d6089640cbdfe242da3a16c6bdf1f73f (patch)
tree86a40a5471d1686cd80d3a54cfcbc3ffefc3f880 /svg-flatten/src/svg_path.cpp
parent8ab0c9fa017b5ead2e3f5cfc892b242cd0bbc908 (diff)
downloadgerbolyze-00eb9594d6089640cbdfe242da3a16c6bdf1f73f.tar.gz
gerbolyze-00eb9594d6089640cbdfe242da3a16c6bdf1f73f.tar.bz2
gerbolyze-00eb9594d6089640cbdfe242da3a16c6bdf1f73f.zip
svg-flatten: Add cubic bezier support for newer usvg versions
Diffstat (limited to 'svg-flatten/src/svg_path.cpp')
-rw-r--r--svg-flatten/src/svg_path.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/svg-flatten/src/svg_path.cpp b/svg-flatten/src/svg_path.cpp
index 70d346d..b592ab0 100644
--- a/svg-flatten/src/svg_path.cpp
+++ b/svg-flatten/src/svg_path.cpp
@@ -77,8 +77,7 @@ static pair<bool, bool> flatten_path(ClipperLib::Paths &stroke_open, ClipperLib:
(ClipperLib::cInt)round(a[1]*clipper_scale)
});
- } else { /* Curve to */
- assert(cmd == "C"); /* guaranteed by usvg */
+ } else if (cmd == "C") { /* Curve to */
in >> b[0] >> b[1]; /* first control point */
in >> c[0] >> c[1]; /* second control point */
in >> d[0] >> d[1]; /* end point */
@@ -95,6 +94,24 @@ static pair<bool, bool> flatten_path(ClipperLib::Paths &stroke_open, ClipperLib:
}
a = d; /* set last point to curve end point */
+
+ } else { /* Curve to */
+ assert(cmd == "Q"); /* guaranteed by usvg */
+ in >> b[0] >> b[1]; /* control point */
+ in >> c[0] >> c[1]; /* end point */
+ assert (!in.fail()); /* guaranteed by usvg */
+
+ gerbolyze::curve3_div c3div(distance_tolerance_px);
+ c3div.run(a[0], a[1], b[0], b[1], c[0], c[1]);
+
+ for (auto &pt : c3div.points()) {
+ in_poly.emplace_back(ClipperLib::IntPoint{
+ (ClipperLib::cInt)round(pt[0]*clipper_scale),
+ (ClipperLib::cInt)round(pt[1]*clipper_scale)
+ });
+ }
+
+ a = c; /* set last point to curve end point */
}
first = false;