Embedding an SVG element in a view/layer

24 views
Skip to first unread message

Simon

unread,
Jan 28, 2020, 11:09:24 AM1/28/20
to Cappuccino & Objective-J
Hi all,

So, for a project idea, I want to be write a template-based layout editor for a small-ish number of elements (say 5 lines of text and a graphic for each object, between 20 and 40 objects on a page). Ideally I'd like to be able to let people upload SVG elements for the graphic component, but I don't *think* SVG is available as an image type in CPImage.

First question: Am I wrong with that ? The manual does say "CPImage is used to represent images in the Cappuccino framework. It supports loading all image types supported by the browser." which is promising, but I also find things like this  which would seem to suggest otherwise, unless that's now out of date...

Assuming CPImage doesn't support SVG (because otherwise this is easy :), is my best bet to try and do something similar to what Robert was doing (his github changes are still available) or am I better off just using a CPWebView and loading the HTML as: "render this SVG", bounded by the CPWebView bounds of course ?

Presumably I could apply an affine transform to the CPWebView to allow for rotation handles etc.

These SVGs are going to be relatively simple (think: icons rather than drawings) but as I said above, there will possibly be 40 or so on-screen at once. That seems like a lot of webviews...

Any thoughts very welcome :)

The reason for using SVG rather than generating something internally using paths is that this web-app will be a front-end that lets people create project files that can then be loaded into a third-party program, which natively supports SVG for vector import. If I have to, I'll write the [internal representation using paths] => [svg file as part of project file bundle] but I'd really rather not put a translation stage in unless it's absolutely necessary. Using the native format seems much less error prone. 

Cheers
 Simon

Martin Carlberg

unread,
Jan 28, 2020, 1:18:44 PM1/28/20
to Cappuccino & Objective-J
Hi Simon,

I don't think you should use web views. It will create iframes for you and I don't think that is a good solution.

Using something like Robert did will probably be much easier. Every CPView will create a div and your svg object will be inside it. You can apply an affine transform to the CPView to rotate and alter the svg.

Happy coding,

- Martin

--
You received this message because you are subscribed to the Google Groups "Cappuccino & Objective-J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objectivej+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/objectivej/06979ee9-5cd2-409a-a831-b6d9cffce12a%40googlegroups.com.

Simon

unread,
Jan 29, 2020, 11:41:23 PM1/29/20
to Cappuccino & Objective-J
Thanks Martin - now that I'm feeling better about it being possible, I'm happier to give it a go :)

Cheers
   Simon
- Martin

To unsubscribe from this group and stop receiving emails from it, send an email to objec...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages