No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
nat3 2c72af8ff0 Slim core: drop dvui/z2d renderers from src/, move z2d demo to examples/
dvui now vendors its own direct TVG->triangle renderer, so
root_dvui.zig/dvui_render.zig/earcut.zig are removed. The z2d raster
renderer (rendering.zig + stroke.zig) is example-only code, so it moves
to examples/ (as z2d_render.zig) and imports svg2tvg as an external
module instead of local root.zig.

svg2tvg core now only does SVG->TVG conversion + the TVG format; it no
longer depends on z2d at all. build.zig/build.zig.zon and
examples/build.zig updated accordingly, and examples/demo.zig is
trimmed to the z2d-only raster demo (the dvui_render vs z2d comparison
is gone since dvui hosts that renderer itself now).
2026-07-10 23:40:27 +02:00
examples Slim core: drop dvui/z2d renderers from src/, move z2d demo to examples/ 2026-07-10 23:40:27 +02:00
src Slim core: drop dvui/z2d renderers from src/, move z2d demo to examples/ 2026-07-10 23:40:27 +02:00
.gitignore (re)move example build code to subdir 2026-06-14 00:12:39 +02:00
build.zig Slim core: drop dvui/z2d renderers from src/, move z2d demo to examples/ 2026-07-10 23:40:27 +02:00
build.zig.zon Slim core: drop dvui/z2d renderers from src/, move z2d demo to examples/ 2026-07-10 23:40:27 +02:00
LICENSE add license 2025-05-10 17:06:53 +02:00
README.md Slim core: drop dvui/z2d renderers from src/, move z2d demo to examples/ 2026-07-10 23:40:27 +02:00

svg2tvg - convert svg to tvg and render tvg to image!

  • written in zig 0.16.0
  • dependency name: svg2tvg, module name: svg2tvg

status / background

  • the main goal is to convert and render icons
  • there is a z2d based renderer, that has options to overwrite color and stroke width, but its source is not vendored anymore in src/ to simplify dependencies, instead it lives in the examples/ folder, feel free to copy it from there if you need raster based rendering!
  • if you need triangle based rendering using svg2tvg, its implemented and vendored inside dvui's icon rendering pipeline
  • only a small subset of svg is supported
  • related project: zig-lib-icons
  • as of now used in the dvui project as part of rendering svg/tvg icons

api

  • tvg_from_svg(...) - convert svg to tvg
  • renderStream(...) - render tvg to an image
  • RenderOptions - Options for rendering

usage:

test "convert to tvg and render" {
    const svg2tvg = @import("svg2tvg");
    const gpa = std.testing.allocator;
    var arena = std.heap.ArenaAllocator.init(gpa);
    defer arena.deinit();
    const alloc = arena.allocator();

    const Wrapper = struct {
        width: i64,
        height: i64,
        img: *MyImage,
        pub fn setPixel(self: *@This(), x: i64, y: i64, color: [4]u8) void {
            const pix: MyPixel = .init_from_u8_slice(&color);
            self.img.set_pixel(@intCast(x), @intCast(y), pix);
        }
    };

    const width_and_height = 200;

    var myImage = try MyImageType.init(alloc, width_and_height, width_and_height);
    const my_svg_icon_data = icons.svg.feather.activity;

    var w = std.ArrayList(u8).init(alloc);
    try svg2tvg.tvg_from_svg(alloc, w.writer(), svg_bytes);

    var image_wrapper = Wrapper{
        .img = img,
        .width = @intCast(img.get_width()),
        .height = @intCast(img.get_height()),
    };

    var fb = std.io.fixedBufferStream(w.items);
    try svg2tvg.renderStream(alloc, &image_wrapper, fb.reader(), .{}); <-- you can use options here

    ...
}

Credit:

Licence