Conversation
|
Hi @idrassi! However, we need to refactor this. SVG support should be outside of A better approach, aligned with the NAppGUI architecture, would be:
This achieves three things:
|
Move SVG handling out of draw2d Image internals into a dedicated nsvg library. Expose parsing, Pixbuf rasterization, and vector drawing APIs built on NanoSVG. Extend draw2d with path drawing, fill rules, radial gradients, dash offset, and miter-limit support across GTK, macOS, and Windows, and update DrawHello to use the new nsvg API.
|
I updated the PR to align with your suggested architecture. I added a new
I also updated DrawHello to use One important point: while implementing So I extended draw2d with backend-agnostic drawing capabilities that are useful beyond SVG:
These are generic draw2d features needed to render NanoSVG paths through the public drawing API while preserving compound paths, even-odd fills, radial gradients, dashed strokes and miter behavior. I also kept I tested the new implementation on Windows, Linux and macOS. |
Closes #222.
Summary
This adds a new
nsvglibrary for lightweight SVG support in NAppGUI, based on NanoSVG.Instead of extending the existing
Imageloaders, this keeps SVG support in a dedicated module that can either:PixbufDCtxas vector contentWhat changed
nsvgmodule:src/nsvg/nsvg.hsrc/nsvg/nsvg.hxxsrc/nsvg/nsvg.hdfsrc/nsvg/nsvg.csrc/nsvg/depend/nanosvg.hsrc/nsvg/depend/nanosvgrast.hnsvg_from_data()nsvg_pixbuf()nsvg_draw()draw2dso SVG vector rendering can preserve the expected path/paint behavior:draw_path_begin/move/line/bezier/close/end)drawhellowith anImage/SVGdemo and a bundled SVG resourcensvg_pixbuf()nsvg_draw()to show live vector scalingWhy NanoSVG / limitations
NanoSVG was chosen because it is small, easy to vendor, permissively licensed, and fits this change well without adding a large dependency.
This is still intentionally scoped support, not full browser-level SVG rendering. NanoSVG does not implement the entire SVG specification, but it has enough coverage for most commonly used SVG images. More advanced SVG features may still render differently from a browser.
Tested on macOS, Linux and Windows. Below are screenshots of the updated
DrawHelloImage/SVGpanel.macOS
Windows
Linux Ubuntu 24.04