Skip to content

Commit

Permalink
Don't transform paths with id without stroke-width since it can be ov…
Browse files Browse the repository at this point in the history
…errided.

Fixes svg#483
  • Loading branch information
GreLI committed Mar 8, 2016
1 parent a62176e commit a55dc25
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
17 changes: 16 additions & 1 deletion plugins/_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,28 @@ exports.applyTransforms = function(elem, path, params) {

var matrix = transformsMultiply(transform2js(elem.attr('transform').value)),
stroke = elem.computedAttr('stroke'),
id = elem.computedAttr('id'),
transformPrecision = params.transformPrecision,
newPoint, scale;

if (stroke && stroke.value != 'none') {
if (stroke && stroke != 'none') {
if (!params.applyTransformsStroked ||
(matrix.data[0] != matrix.data[3] || matrix.data[1] != -matrix.data[2]) &&
(matrix.data[0] != -matrix.data[3] || matrix.data[1] != matrix.data[2]))
return path;

// "stroke-width" should be inside the part with ID, otherwise it can be overrided in <use>
if (id) {
var idElem = elem,
hasStrokeWidth = false;

do {
if (idElem.hasAttr('stroke-width')) hasStrokeWidth = true;
} while (!idElem.hasAttr('id', id) && !hasStrokeWidth && (idElem = idElem.parentNode));

if (!hasStrokeWidth) return path;
}

scale = +Math.sqrt(matrix.data[0] * matrix.data[0] + matrix.data[1] * matrix.data[1]).toFixed(transformPrecision);

if (scale !== 1) {
Expand All @@ -209,6 +222,8 @@ exports.applyTransforms = function(elem, path, params) {
});
}
}
} else if (id) { // Stroke and stroke-width can be redefined with <use>
return path;
}

path.forEach(function(pathItem) {
Expand Down
12 changes: 12 additions & 0 deletions test/plugins/convertPathData.11.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a55dc25

Please sign in to comment.