Inside a class, I define a string variable to store the content of a svg file (XML) so I can manipulate its color and opacity and then convert it to a picture object with:
Var svgPicture As Picture = Picture.FromData(svgStringWithNewColor)
so, svgPicture then displays on a DesktopCanvas (same with Canvas) on Paint method with DrawPicture. On MacOs it shows ok but not on Windows. If I drop the svg file to Xojo it displays fine on a canvas with Backdrop property.
Tryed converting XML string to memory block with this, same result:
Var m As New MemoryBlock(1024)
m.CString(0) = svgStringWithNewColor
Var svgPicture As Picture = Picture.FromData(m)
Does anyone knows what could be the cause of the problem?
macOS is doing the heavy lifting for you with SVGs, which are supported out of the box by the operating system. Windows didn’t have a native mechanism until the Windows 10 Anniversary Update. Being that it is an extension of Direct2D, I’m sure Xojo could extend the framework to support this, but you’d need to open a feature request.
As for the need to draw SVGs on Windows from your Xojo applications, there are a number of solutions available including Einhuiger’s, open source implementations ([1], [2]), and my own take (GraffitiSVG) which uses the native funcitonality on macOS and JavaScript on Windows.
I do not, and I don’t know how long it has been functional. I suspect it was added around the time of Xcode 12 to support SVGs in Asset Catalogs. So 2020 or thereabout?
Thanks you all. I’m going to try both options.
Anthony, very clear explanation. I look GraffitiSVG but I need to display the picture on the paint event of a canvas object inside a class, can’t use a DesktopHTMLViewer.
Interesting. However, the discussion suggests that Xcode renders vector formats down to a pixel format such as PNG. If this is true, Xcode could be using an internal library to do it, since I still don’t see any macOS framework support for it.
I tried both options. With option one (xojo-drawsvg) and Xojo 2023 it won’t work, I think because the need of using old GDI Plus. Option two (Xojo-SVGDocument) works but the resulting image is quite flawed, It differs quite a bit from the original.
It’s in a private OS framework called CoreSVG. Supported on both macOS and iOS/iPadOS. The OS just handles it. Here’s a Swift implementation if you want to browse it.