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

canvas.toDatalessJSON doesn't work with canvas.loadFromDatalessJSON when SVG sourcePath is set. #4560

Closed
smansker opened this issue Dec 14, 2017 · 5 comments · Fixed by #5970

Comments

@smansker
Copy link

Version

2.0.0-rc.3

Test Case

https://jsfiddle.net/smansker/j81Lrg5c/

Steps to reproduce

I am unable to use the datalessJSON serialize/deserialize methods with SVGs. Basically, it doesn't work if I include the sourcePath property, as per the tutorials.

First, I load an SVG into the canvas like so:

fabric.loadSVGFromURL(svgSrc, (objects, options) => {
  var group = fabric.util.groupSVGElements(objects, options, svgSrc);
  
  group.set({
    selectable: true,
    originX: 'center',
    originY: 'center',
    left: 250,
    top: 250,
    scaleX: 0.5,
    scaleY: 0.5
  });
  
  canvas.add(group);
  canvas.renderAll();
});

Now, if I call JSON.stringify(canvas.toDatalessJSON()) the json that it outputs has the objects property set to the string that I passed in for the sourcePath property.

If you pass the json into the canvas.loadFromDatalessJSON(jsonStr, canvas.renderAll.bind(canvas)), it throws an error: "objects.forEach is not a function."

Expected Behavior

The serialized canvas data should be able to be deserialized back into the canvas, using toDatalessJSON and loadFromDatalessJSON, when my canvas contains SVG graphics.

Actual Behavior

It fails to load the serialized data into the canvas and generates an error.

@smansker smansker changed the title canvas.toDatalessJSON creates invalid JSON when SVG sourcePath is set. canvas.toDatalessJSON doesn't work with canvas.loadFromDatalessJSON when SVG sourcePath is set. Dec 14, 2017
@smansker
Copy link
Author

The original title of this bug was misleading. Hopefully it makes more sense now.

@asturur
Copy link
Member

asturur commented Feb 6, 2018

@smansker sorry for not replying.
does your issue look similar to #4598 ?

@smansker
Copy link
Author

smansker commented Feb 6, 2018

Yes, they appear to be the same issue.

@zealotrahl
Copy link

Facing same issue, as i see in jsoned object, attribute name is seemed to be changed, "objects":"/cliparts/svg/file.svg" now, and in your tutroial it was "path":"/assets/dragon.svg"

@asturur
Copy link
Member

asturur commented Nov 15, 2019

duplicate of #4598

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 a pull request may close this issue.

3 participants