Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Fix svg stroke thickness (#2358)

Calabaraburus7e96bc7566cb
diff --git a/toonz/sources/image/svg/tiio_svg.cpp b/toonz/sources/image/svg/tiio_svg.cpp
index 55182be92..d52738525 100644
--- a/toonz/sources/image/svg/tiio_svg.cpp
+++ b/toonz/sources/image/svg/tiio_svg.cpp
@@ -1320,6 +1320,8 @@ void nsvg__parsePath(struct NSVGParser *p, const char **attr) {
char closedFlag;
int i;
char item[64];
+ float prev_m_cpx, prev_m_cpy;
+ bool prev_m_exists;
for (i = 0; attr[i]; i += 2) {
if (strcmp(attr[i], "d") == 0) {
@@ -1330,6 +1332,7 @@ void nsvg__parsePath(struct NSVGParser *p, const char **attr) {
cpy = 0;
closedFlag = 0;
nargs = 0;
+ prev_m_exists = false;
while (*s) {
s = nsvg__getNextPathItem(s, item);
@@ -1340,7 +1343,19 @@ void nsvg__parsePath(struct NSVGParser *p, const char **attr) {
switch (cmd) {
case 'm':
case 'M':
+
+ // If moveto is relative it relative to previous moveto point
+ if (cmd == 'm' && prev_m_exists) {
+ cpx = prev_m_cpx;
+ cpy = prev_m_cpy;
+ }
+
nsvg__pathMoveTo(p, &cpx, &cpy, args, cmd == 'm' ? 1 : 0);
+
+ prev_m_cpx = cpx;
+ prev_m_cpy = cpy;
+ prev_m_exists = true;
+
// Moveto can be followed by multiple coordinate pairs,
// which should be treated as linetos.
cmd = (cmd == 'm') ? 'l' : 'L';
@@ -2073,6 +2088,15 @@ TStroke *buildStroke(NSVGpath *path, float width) {
s->setSelfLoop(path->closed);
+ std::vector<TThickPoint> tpoints;
+ s->getControlPoints(tpoints);
+
+ for (int j = 0; j < tpoints.size(); j++) {
+ tpoints[j].thick = width;
+ }
+
+ s->reshape(&tpoints[0], tpoints.size());
+
return s;
}