Using image object SVG Support to display an image in a widget?

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
pthirkell
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 93
Joined: Tue Nov 17, 2009 6:47 pm
Location: Wellington, New Zealand

Using image object SVG Support to display an image in a widget?

Post by pthirkell » Thu Jan 04, 2018 2:21 am

The SVG support in DP 11 works exactly as advertised. There are many instances however when it would be really helpful to display an SVG image from within a widget as well.

LCB has the command: put image from data tData into tImage

... but I can't quite figure out how to access the data (text) of an SVG image from within the widget so that it can be displayed.

Is there an easy way to have the widget display an SVG image - not unlike the way in which a button icon simply points to the id of an SVG image?

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Using image object SVG Support to display an image in a widget?

Post by [-hh] » Thu Jan 04, 2018 3:07 am

Hi Peter,
data tData is raw imagedata (binary, 4 bytes argb per pixel).

You can, for example, write the imageData compiled from SVG in LCS to a file and then read in that file to your widget (image from file) in LCB. Or you make a property and fill that property with the imageData in LCS, but all the conversion is slower than the transport via a (temporary) file.

You can then access the pixels of tImage for processing if needed. (This is slow, even for small images, better to do that in LCS.)

Hermann
shiftLock happens

pthirkell
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 93
Joined: Tue Nov 17, 2009 6:47 pm
Location: Wellington, New Zealand

Re: Using image object SVG Support to display an image in a widget?

Post by pthirkell » Thu Jan 04, 2018 3:40 am

Thanks Hermann :D

I have been playing around with the property idea ... but writing out image data to a temporary file and then reading back into the widget seems more straightforward. I'll give it a go!

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Using image object SVG Support to display an image in a widget?

Post by PaulDaMacMan » Thu Jan 04, 2018 7:53 pm

SVG support does not behave as expected. If there is text in the SVG with a specific font assigned to it the text is not rendered at all, whereas a web browser would substitute a different font and render it anyway. A simple work around is to create outlines in your vector illustrations for the text (which then becomes path information and is no longer useful as editable text).
Last edited by PaulDaMacMan on Thu Jan 04, 2018 10:09 pm, edited 1 time in total.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: Using image object SVG Support to display an image in a widget?

Post by LCMark » Thu Jan 04, 2018 8:17 pm

@pthirkell: The 'image with data' form would be the one to use here - but there's an issue I've just noticed there... It won't currently work with drawing data (internally its using too specific a class) - could you file a bug? :)

One missing image constructor in LCB is one which creates an image from an image id - that would be a useful thing to be able to do - although the only slight wrinkle is that icons - i.e. images referenced from other controls via id - inherit the size and opacity etc. from the image. Perhaps we need an 'icon' abstraction, and then allow you to get the 'image' of the 'icon'. Well worth an enhancement request :)

@PaulDaMacMan: The SVG compiler nor drawing format does not support text yet - there's a list of supported SVG elements in the drawingSvgCompile pages in the dictionary.

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Using image object SVG Support to display an image in a widget?

Post by PaulDaMacMan » Thu Jan 04, 2018 10:15 pm

Thanks Mark, I was thinking I'd file a bug report but obviously you guys are aware of it. Admittedly, I didn't even bother to look it up in the dictionary :oops: .

So there is text support to come in a future iteration then?
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

pthirkell
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 93
Joined: Tue Nov 17, 2009 6:47 pm
Location: Wellington, New Zealand

Re: Using image object SVG Support to display an image in a widget?

Post by pthirkell » Fri Jan 05, 2018 9:42 am

Thanks Mark. I wrote a simple LCB widget script with a single property which was the image data, and then a couple of lines of LC script when the widget was running to copy across the text from an SVG widget into the property ... but as you have already realised it didn't work. I will file a bug report.

Your other idea would be brilliant, so yes I will file an enhancement request. Inheriting the attributes of the image isn't necessarily a bad thing ... the present image to button icon functionality for example means that changing say the size of the image is an easy way to resize the icon displayed in the button through an essentially infinite range. It may also of course create other limitations of which I am not yet fully aware.

The main immediate priority from my perspective is simply being able to harness the power of the SVG complier for display in widgets as well as images/buttons. Anything to help this along will be greatly appreciated.

Post Reply

Return to “LiveCode Builder”