https://github.com/msrd0/svgwriter
Typed SVG Writer
https://github.com/msrd0/svgwriter
Last synced: 2 months ago
JSON representation
Typed SVG Writer
- Host: GitHub
- URL: https://github.com/msrd0/svgwriter
- Owner: msrd0
- License: other
- Created: 2022-07-25T17:00:06.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-13T21:49:58.000Z (9 months ago)
- Last Synced: 2025-02-28T12:33:57.364Z (3 months ago)
- Language: Rust
- Homepage:
- Size: 540 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# svgwriter  [](https://crates.io/crates/svgwriter) [](https://docs.rs/svgwriter) [](https://codeberg.org/msrd0/svgwriter)
`svgwriter` is a typed library for writing correct SVG files. It includes SVG
specification and documentation from [mdn][__link0].### Example
```rust
use svgwriter::{
tags::{Path, TagWithPresentationAttributes as _},
Data, Graphic
};let mut svg = Graphic::new();
let size = 100;
svg.set_width(size);
svg.set_height(size);
svg.set_view_box(format!("0 0 {size} {size}"));// draw a heart, inspired by https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#example
let d = 40;
let padding = size / 2 - d;
let mut heart = Data::new();
heart
.move_to(padding, padding + d / 2)
.arc_by(d / 2, d / 2, 0, false, true, d, 0)
.arc_by(d / 2, d / 2, 0, false, true, d, 0)
.quad_by(0, d * 3 / 4, -d, d * 3 / 2)
.quad_by(-d,-d * 3 / 4, -d, -d * 3 / 2);
svg.push(
Path::new()
.with_d(heart)
.with_fill("#A919FA")
.with_fill_opacity(0.5)
.with_stroke("#A919FA")
.with_stroke_width(3)
);// write the svg to a file
write!(file, "{}", svg.to_string());
```This code produces the following image:

[__link0]: https://developer.mozilla.org