Added keepRepeatCommandNames option to .toString() method #11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With this PR I've added the ability to drop the optimization regarding repeat command names in the string output.
I also wanted to start a discussion on whether this is the right approach here. As per the SVG 1.2 spec (SVG 2 is similar):
So it's not correct to automatically transform
M 10 10 M 10 100 M 100 100 M 100 10 Z
toM 10 10 10 100 100 100 100 10 Z
, as seen in this example (notice the difference in rendering): http://jsfiddle.net/u0eym6d7/While it would be better to treat all the specific cases where removing repeat command names does not result in equivalent paths, this is a quick fix to disable that optimization.
Edit: I fixed it through the extra parameter so that existing behavior is not changed. I've checked the SVG spec and the M seems to be the only command affected by this, so the alternative can be changing the condition to:
skipCmd = i > 0 && (this.segments[i][0] === this.segments[i - 1][0] && this.segments[i][0].toLowerCase() !== 'm');
Waiting for your thoughts on this :-)