diff --git a/svg/pathdata.go b/svg/pathdata.go index 9e6adb134b..01a8444779 100644 --- a/svg/pathdata.go +++ b/svg/pathdata.go @@ -105,11 +105,10 @@ func (p *PathData) ShortenPathData(b []byte) []byte { i += n - 1 } } - if cmd != 0 { - j += p.copyInstruction(b[j:], cmd) - } else { - j = len(b) + if cmd == 0 { + return b } + j += p.copyInstruction(b[j:], cmd) return b[:j] } @@ -219,7 +218,7 @@ func (p *PathData) copyInstruction(b []byte, cmd byte) int { // if control points overlap begin/end points, this is a straight line // even though if the control points would be along the straight line, we won't minify that as the control points influence the speed along the curve (important for dashes for example) // only change to a lines if we are sure no 'S' or 's' follows - if (cmd == 'C' || cmd == 'c' || i+di >= n) && (cp1x == p.x || cp1x == ax) && (cp1y == p.y || cp1y == ay) && (cp2x == p.x || cp2x == ax) && (cp2y == p.y || cp2y == ay) { + if (cmd == 'C' || cmd == 'c' || i+di >= n) && (cp1x == p.x && cp1y == p.y || cp1x == ax && cp1y == ay) && (cp2x == p.x && cp2y == p.y || cp2x == ax && cp2y == ay) { if isRelCmd { cmd = 'l' } else { @@ -265,7 +264,7 @@ func (p *PathData) copyInstruction(b []byte, cmd byte) int { // if control point overlaps begin/end points, this is a straight line // even though if the control point would be along the straight line, we won't minify that as the control point influences the speed along the curve (important for dashes for example) // only change to a lines if we are sure no 'T' or 't' follows - if (cmd == 'Q' || cmd == 'q' || i+di >= n) && (cpx == p.x || cpx == ax) && (cpy == p.y || cpy == ay) { + if (cmd == 'Q' || cmd == 'q' || i+di >= n) && (cpx == p.x && cpy == p.y || cpx == ax && cpy == ay) { if isRelCmd { cmd = 'l' } else { diff --git a/svg/pathdata_test.go b/svg/pathdata_test.go index 305aaa09fd..5127d1fd7b 100644 --- a/svg/pathdata_test.go +++ b/svg/pathdata_test.go @@ -39,6 +39,10 @@ func TestPathData(t *testing.T) { { "q6.55 0 10.56-2.93a9.36 9.36 0 004-8 10 10 0 00-3.37-7.83q-3.37-3-9.9-4.79A25.38 25.38 0 0137.76 44", "q6.55.0 10.56-2.93a9.36 9.36.0 004-8 10 10 0 00-3.37-7.83q-3.37-3-9.9-4.79A25.38 25.38.0 0137.76 44"}, // #275 + { + "m-3.5498-0.0882q0-5.1924-4.5861-5.1924h-1.819v10.495h1.4662q4.9389-0+4.9389-5.3027z", + "m-3.5498-.0882q0-5.1924-4.5861-5.1924h-1.819v10.495h1.4662q4.9389.0 4.9389-5.3027z"}, // #284 + {"C10 0 0 10 10 10", "C10 0 0 10 10 10"}, // change/remove commands {"M10 10L10 10L20 10z", "M10 10H20z"},