Page 1 of 1

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

Posted: Thu Jan 04, 2018 2:21 am
by pthirkell
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?

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

Posted: Thu Jan 04, 2018 3:07 am
by [-hh]
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

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

Posted: Thu Jan 04, 2018 3:40 am
by pthirkell
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!

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

Posted: Thu Jan 04, 2018 7:53 pm
by PaulDaMacMan
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).

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

Posted: Thu Jan 04, 2018 8:17 pm
by LCMark
@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.

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

Posted: Thu Jan 04, 2018 10:15 pm
by PaulDaMacMan
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?

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

Posted: Fri Jan 05, 2018 9:42 am
by pthirkell
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.