SVG gradient example 1 - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Official Links (https://qb64phoenix.com/forum/forumdisplay.php?fid=16) +--- Forum: Learning Resources and Archives (https://qb64phoenix.com/forum/forumdisplay.php?fid=13) +--- Thread: SVG gradient example 1 (/showthread.php?tid=2178) |
SVG gradient example 1 - James D Jarvis - 11-16-2023 A simple example showing how to make use of the SVG library in QB64 PE 3.9.0 and higher. There are some peculiarities in how SVG and XML tags used to define the SVG graphics are parsed and rendered. I'm still learning how they all work myself and want to share as I go along. The _LOADIMAGE command is doing a lot of work here and the ability to load a SVG file from a string buffer out of memory let's us treat SVGs as an alternative and more power version of DRAW. Go review _LOADIMAGE - QB64 Phoenix Edition Wiki when you get a chance. The example program here will draw a big rounded-corner rectangle with a gradient fill in the middle of the screen. Press any key to exit. Read the comments for a hopefully useful description of what is going on in the program. Code: (Select All)
RE: SVG gradient example 1 - bplus - 11-16-2023 @James D Jarvis I guess we have a fan of SVG RE: SVG gradient example 1 - James D Jarvis - 11-16-2023 (11-16-2023, 09:34 PM)bplus Wrote: @James D Jarvis I guess we have a fan of SVG Yes. Yes we do. Being able to create vector images in a high-end illustration program and import them is useful. But being able to create such graphics inside a QB64 program itself is fantastic. Anyone know if there's any decent documentation for the SVG library being used? I've discovered some quirks but nothing bad. I'm not a real SVG guru but I was using them years back for animations and interface elements professionally and am delighted to be able to use them in my QB64 programs. RE: SVG gradient example 1 - mnrvovrfc - 11-17-2023 Must get into Inkscape, create or load SVG file and save as "plain SVG". By default, the program saves as "sodipodi", that is, what it claims is its own format. It adds a lot more XML junk. That's why I warn here to save as "plain SVG", must choose it from the file types in the save file dialog. This is to study other ins and outs of the SVG format. Doing bezier curves could be tricky. Some pictures switch back and forth between absolute and relative coordinates so one has to look out for that when trying to parse an SVG. The "sodipodi" format tends to have a lot of transformations too, which could be a PITA to get the true absolute coordinates. I should have checked if QB64PE could load one of my Inkscape "projects". Another thing to watch out for is that in "plain" SVG, there are no layers like what Inkscape supports. Every "layer" in a "plain" SVG file is a group. Indeed, a "plain" SVG is loaded by Inkscape into a single layer, which might have more than one group. This is for people who think SVG is "yet another cryptic XML-like format" but it really isn't. RE: SVG gradient example 1 - James D Jarvis - 11-17-2023 (11-17-2023, 01:08 AM)mnrvovrfc Wrote: Must get into Inkscape, create or load SVG file and save as "plain SVG". By default, the program saves as "sodipodi", that is, what it claims is its own format. It adds a lot more XML junk. That's why I warn here to save as "plain SVG", must choose it from the file types in the save file dialog.Most of my experience with it is with Adobe Illustrator and I have the best results bringing it into QB64 after saving as a Tiny SVG (??). What I like is how editable they can be from within QB64 itself since they are just strings. RE: SVG gradient example 1 - a740g - 11-17-2023 (11-16-2023, 09:45 PM)James D Jarvis Wrote:(11-16-2023, 09:34 PM)bplus Wrote: @James D Jarvis I guess we have a fan of SVG We are using the NanoSVG library to implement SVG support in QB64-PE. The NanoSVG rasterizer can only render flat filled shapes. Notably, SVG text rendering is absent. See memononen/nanosvg: Simple stupid SVG parser (github.com) RE: SVG gradient example 1 - James D Jarvis - 11-17-2023 (11-17-2023, 05:05 AM)a740g Wrote: James D Jarvis... Thanks, from looking there is seems digging into the headers will be my best option for looking for the setting the library pays attention to (unless there's something I'm missing). In just a couple minutes it's already been effective. |