Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use currentDefaultPath instead of <path>'s d attribute, fixes stroke's different behavior in SVG and canvas. #20

Merged
merged 1 commit into from
May 29, 2015

Conversation

zenozeng
Copy link
Contributor

Now __addPathCommand will only update this.__currentDefaultPath. And __applyCurrentDefaultPath will be called inside stroke or fill.

The bug:

2015-05-21 10 40 01

The left image is SVG, the middle image is Canvas, and the right is diff bitmap.

The following 2 code blocks should have different result:

    ctx.beginPath();
    ctx.moveTo(10,10);
    ctx.lineTo(30, 30);
    ctx.lineTo(60, 10);
    ctx.stroke(); // currentDefaultPath not including the final Z
    ctx.closePath();
    ctx.beginPath();
    ctx.moveTo(10,10);
    ctx.lineTo(30, 30);
    ctx.lineTo(60, 10);
    ctx.closePath();
    ctx.stroke(); // currentDefaultPath including the final Z

See also: zenozeng/p5.js-svg#38

@gwwar
Copy link
Contributor

gwwar commented May 23, 2015

Good catch! 👍 Maybe add a unit test with this case to https://github.com/gliffy/canvas2svg/blob/master/jasmine-tests/spec/canvas2svgspec.js

@zenozeng
Copy link
Contributor Author

BTW, what about adding a bitmap diff based unit tests?
I think it's hard to tests the behavior without using pixels.

Just like this test: http://zenozeng.github.io/p5.js-svg/test/

@gwwar
Copy link
Contributor

gwwar commented May 23, 2015

Image diffs are great for smoke tests. Nice trick with the data:image/svg+xml. It looks like canvas is happy accepting drawImage with an uri of data:image/svg+xml. http://jsfiddle.net/gwwar/n4sgo9ao/

We have had some smoke tests in the past with a clunkier set up of taking screenshots in a headless browser, and then passing that through imagemagick to get a diff, but this looks a lot simpler.

If I have time I might whip something up. Perhaps something more interactive like the example/issue reporter in canvg? http://gabelerner.github.io/canvg/examples/index.htm

clintjd pushed a commit that referenced this pull request May 29, 2015
use currentDefaultPath instead of <path>'s d attribute, fixes stroke's different behavior in SVG and canvas.
@clintjd clintjd merged commit bc53ac5 into gliffy:master May 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants