Fix: fix a bug of convertPath function when convert H and V to relative

master
cuixiping 2020-01-16 14:15:53 +08:00
parent f9cc6821c7
commit 5c21127791
1 changed files with 7 additions and 3 deletions

View File

@ -1538,7 +1538,7 @@ export const convertPath = function (pth, toRel) {
y2 = seg.y2 || 0; y2 = seg.y2 || 0;
const type = seg.pathSegType; const type = seg.pathSegType;
let letter = pathMap[type]['to' + (toRel ? 'Lower' : 'Upper') + 'Case'](); let letter = pathMap[type][toRel ? 'toLowerCase' : 'toUpperCase']();
switch (type) { switch (type) {
case 1: // z,Z closepath (Z/z) case 1: // z,Z closepath (Z/z)
@ -1553,30 +1553,34 @@ export const convertPath = function (pth, toRel) {
// Fallthrough // Fallthrough
case 13: // relative horizontal line (h) case 13: // relative horizontal line (h)
if (toRel) { if (toRel) {
y = 0;
curx += x; curx += x;
letter = 'l'; letter = 'l';
} else { } else {
y = cury;
x += curx; x += curx;
curx = x; curx = x;
letter = 'L'; letter = 'L';
} }
// Convert to "line" for easier editing // Convert to "line" for easier editing
d += pathDSegment(letter, [[x, cury]]); d += pathDSegment(letter, [[x, y]]);
break; break;
case 14: // absolute vertical line (V) case 14: // absolute vertical line (V)
y -= cury; y -= cury;
// Fallthrough // Fallthrough
case 15: // relative vertical line (v) case 15: // relative vertical line (v)
if (toRel) { if (toRel) {
x = 0;
cury += y; cury += y;
letter = 'l'; letter = 'l';
} else { } else {
x = curx;
y += cury; y += cury;
cury = y; cury = y;
letter = 'L'; letter = 'L';
} }
// Convert to "line" for easier editing // Convert to "line" for easier editing
d += pathDSegment(letter, [[curx, y]]); d += pathDSegment(letter, [[x, y]]);
break; break;
case 2: // absolute move (M) case 2: // absolute move (M)
case 4: // absolute line (L) case 4: // absolute line (L)