commit a6ebe761aa0acb1949c9e7bd0d22edb3c9b0d587
parent c527a753aca14569d4261e89eb60175264ee8f3f
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Mon, 7 Jul 2025 12:43:38 -0300
readme: include raster details
Describe how to omit the raster logic during compilation and how to
invoke it in the example.
Diffstat:
| M | README.md | | | 46 | +++++++++++++++++++++++++++++++++++++++------- |
1 file changed, 39 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
@@ -11,29 +11,61 @@ Odin bindings for [nanosvg](https://github.com/memononen/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.
## usage
+
```odin
package main
+import "core:c"
import "core:fmt"
-import "core:os/os2"
-import "core:path/filepath"
+import "core:math"
-import "nanosvg"
+import "vendor:stb/image"
+
+import nanosvg "../"
main :: proc() {
+ // Parse the svg.
img := nanosvg.ParseFromFile("sample.svg", "px", 96)
defer nanosvg.Delete(img)
- fmt.println(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),
+ )
- for shape := img.shapes; shape != nil; shape = shape.next {
- fmt.println(shape)
- }
+ // 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),
+ )
}
```