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

load PShape from String, instead of URI #316

Closed
processing-bugs opened this issue Feb 10, 2013 · 9 comments
Closed

load PShape from String, instead of URI #316

processing-bugs opened this issue Feb 10, 2013 · 9 comments

Comments

@processing-bugs
Copy link

Original author: niho...@gmail.com (June 23, 2010 19:41:09)

It would be extremely useful if there was a way to construct a PShape from a valid SVG string, rather than from URI, because this would make it possible to have write Processing code that dynamically generates a legal SVG string and then turn it into a PShape for use in the sketch.

Since this functionality is technically already in the code (because PShape has to call the string-parsing methods after it resolves the svg URI), could it be made public?

Might I request something like:

String svg = "<svg ...><path d='...'/>...</svg>";
PShape s = loadShapeFromString(svg);
shape(s, 0, 0, 50, 50);

Original issue: http://code.google.com/p/processing/issues/detail?id=277

@processing-bugs
Copy link
Author

From f...@processing.org on June 23, 2010 19:46:53
We try to avoid lots of top-level API like that, but in the meantime you can use:

loadShape(new XMLElement(svg))

...which is about as many characters as loadShapeFromString(svg).

@processing-bugs
Copy link
Author

From niho...@gmail.com on June 23, 2010 20:00:33
Nice, although then it might be a good idea to add a bit to the documentation to say that loadShape() can also take an XMLElement as constructor argument, rather than only the URI string that is listed now.

@processing-bugs
Copy link
Author

From niho...@gmail.com on July 16, 2010 17:30:32
I tried the following in Processing 1.2 but it does not work:

XMLElement x = new XMLElement("");
s = loadShape(x);

it cites the error "method loadShape(String) in PApplet is not applicable to arguments (XMLElement)", so it would look like either this functionality got removed (which would be horrible!) or it was never there (equally horrible!).

Can I reopen the request for building a PShape from an SVG string in some manner? I like the idea of doing it via XMLElement, so if that can be made to work, all the better.

@processing-bugs
Copy link
Author

From f...@processing.org on July 16, 2010 20:42:58
PShape s = new PShapeSVG(new XMLElement("..."));

@processing-bugs
Copy link
Author

From niho...@gmail.com on July 16, 2010 21:48:43
ahh, thanks!

@processing-bugs
Copy link
Author

From niho...@gmail.com on April 08, 2011 17:42:11
Update on this ticket due to #608: the XMLElement constructor constructs an empty XML element with the passed string as full name, rather than parsing it as XML. In order to build an XMLElement from an XML string, the following should be used instead:

PShape s = new PShapeSVG(XMLElement.parse("..."));

@processing-bugs
Copy link
Author

From niho...@gmail.com on April 08, 2011 18:01:47
(note that the old approach is valid up to and including 1.2.1 - the new approach is valid as (at least) prerelease 0194)

@processing-bugs
Copy link
Author

From f...@processing.org on June 20, 2011 20:06:50
Closing this issue; for 2.0, we've decided it'll remain essentially the method seen in comment #7, though XMLElement will have a new name.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant