Odin bindings for nanosvg.
git clone --recurse-submodules https://git.sr.ht/~jackmordaunt/odin-nanosvg
You can rely on the pre-built release binaries shipped with this repo,
or you can build them yourself using the script build_libs.sh.
nanosvg contains only the parsing logic.
nanosvgrast additionally contains a simple cpu rasterizer.
By default we link to nanosvgrast. If you don't need the rasterizer you can trim it out with -define:ENABLE_RASTERIZER=false.
For debug symbols call build_libs.sh debug.
NOTE: the build script uses zig for easy cross compilation.
package main
import "core:c"
import "core:fmt"
import "core:math"
import "vendor:stb/image"
import nanosvg "../"
main :: proc() {
// Parse the svg.
img := nanosvg.ParseFromFile("sample.svg", "px", 96)
defer nanosvg.Delete(img)
r := nanosvg.CreateRasterizer()
defer nanosvg.DeleteRasterizer(r)
buf := make([]byte, int(math.ceil(img.width) * img.height) * 4)
defer delete(buf)
// Rasterize the svg.
nanosvg.Rasterize(
r,
img,
0,
0,
1,
raw_data(buf),
c.int(img.width),
c.int(img.height),
c.int(math.ceil(img.width) * 4),
)
// Write rasterized png to disk.
image.write_png(
"out.png",
c.int(img.width),
c.int(img.height),
4,
raw_data(buf),
c.int(math.ceil(img.width) * 4),
)
}