Skip to content

Commit

Permalink
Apply scale to stroke-dasharray and stroke-dashoffset
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Feb 25, 2021
1 parent 83a03ec commit dd37fcf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
14 changes: 13 additions & 1 deletion plugins/_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var rNumber = String.raw`[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?\s*`,
var regPathInstructions = /([MmLlHhVvCcSsQqTtAaZz])\s*/,
regCoordinateSequence = new RegExp(rNumber, 'g'),
regArcArgumentSequence = new RegExp(rArcSeq, 'g'),
regNumericValues = /[-+]?(\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/,
regNumericValues = /[-+]?(\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g,
transform2js = require('./_transforms').transform2js,
transformsMultiply = require('./_transforms').transformsMultiply,
transformArc = require('./_transforms').transformArc,
Expand Down Expand Up @@ -240,6 +240,18 @@ exports.applyTransforms = function(elem, path, params) {
})
});
}

if (elem.hasAttr('stroke-dashoffset')) {
elem.attrs['stroke-dashoffset'].value = elem.attrs['stroke-dashoffset'].value
.trim()
.replace(regNumericValues, (num) => removeLeadingZero(num * scale));
}

if (elem.hasAttr('stroke-dasharray')) {
elem.attrs['stroke-dasharray'].value = elem.attrs['stroke-dasharray'].value
.trim()
.replace(regNumericValues, (num) => removeLeadingZero(num * scale));
}
}
}
} else if (id) { // Stroke and stroke-width can be redefined with <use>
Expand Down
19 changes: 19 additions & 0 deletions test/plugins/convertPathData.22.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 dd37fcf

Please sign in to comment.