Skip to content

Commit e1a3d0c

Browse files
authored
Merge pull request #3 from privatenumber/trim-path
fix: trim "path"
2 parents edf6bd6 + 4e9535d commit e1a3d0c

21 files changed

+55
-49
lines changed

lib/Potrace.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,9 +1097,9 @@ Potrace.prototype = {
10971097

10981098
var tag = '<path d="';
10991099

1100-
this._pathlist.forEach(function(path) {
1101-
tag += utils.renderCurve(path.curve, scale);
1102-
});
1100+
tag += this._pathlist.map(function(path) {
1101+
return utils.renderCurve(path.curve, scale);
1102+
}).join(' ');
11031103

11041104
tag += '" stroke="none" fill="' + fillColor + '" fill-rule="evenodd"/>';
11051105

lib/utils.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ module.exports = {
166166

167167
var startingPoint = curve.c[(curve.n - 1) * 3 + 2];
168168

169-
var path = 'M '
169+
var path = [
170+
'M '
170171
+ fixed(startingPoint.x * scale.x) + ' '
171-
+ fixed(startingPoint.y * scale.y) + ' ';
172+
+ fixed(startingPoint.y * scale.y)
173+
];
172174

173175
curve.tag.forEach(function(tag, i) {
174176
var i3 = i * 3;
@@ -177,18 +179,22 @@ module.exports = {
177179
var p2 = curve.c[i3 + 2];
178180

179181
if (tag === "CURVE") {
180-
path += 'C ';
181-
path += fixed(p0.x * scale.x) + ' ' + fixed(p0.y * scale.y) + ', ';
182-
path += fixed(p1.x * scale.x) + ' ' + fixed(p1.y * scale.y) + ', ';
183-
path += fixed(p2.x * scale.x) + ' ' + fixed(p2.y * scale.y) + ' ';
182+
path.push(
183+
'C '
184+
+ fixed(p0.x * scale.x) + ' ' + fixed(p0.y * scale.y) + ', '
185+
+ fixed(p1.x * scale.x) + ' ' + fixed(p1.y * scale.y) + ', '
186+
+ fixed(p2.x * scale.x) + ' ' + fixed(p2.y * scale.y)
187+
);
184188
} else if (tag === "CORNER") {
185-
path += 'L ';
186-
path += fixed(p1.x * scale.x) + ' ' + fixed(p1.y * scale.y) + ' ';
187-
path += fixed(p2.x * scale.x) + ' ' + fixed(p2.y * scale.y) + ' ';
189+
path.push(
190+
'L '
191+
+ fixed(p1.x * scale.x) + ' ' + fixed(p1.y * scale.y) + ' '
192+
+ fixed(p2.x * scale.x) + ' ' + fixed(p2.y * scale.y)
193+
);
188194
}
189195
});
190196

191-
return path;
197+
return path.join(' ');
192198
},
193199

194200
bezier: function bezier(t, p0, p1, p2, p3) {

test/example-output-posterized.svg

Lines changed: 5 additions & 5 deletions
Loading

test/example-output.svg

Lines changed: 1 addition & 1 deletion
Loading

test/reference-copies/output-posterized.svg

Lines changed: 4 additions & 4 deletions
Loading

test/reference-copies/output.svg

Lines changed: 1 addition & 1 deletion
Loading

test/reference-copies/posterized-bw-threshold-170.svg

Lines changed: 3 additions & 3 deletions
Loading

test/reference-copies/posterized-clouds-white-40.svg

Lines changed: 3 additions & 3 deletions
Loading

test/reference-copies/posterized-yao-black-threshold-128.svg

Lines changed: 3 additions & 3 deletions
Loading

test/reference-copies/posterized-yao-black-threshold-170.svg

Lines changed: 3 additions & 3 deletions
Loading

0 commit comments

Comments
 (0)