5 unstable releases

0.3.2 Dec 3, 2022
0.3.1 Nov 12, 2021
0.3.0 Mar 21, 2020
0.2.0 Mar 4, 2020
0.1.0 Feb 24, 2020

#416 in Graphics APIs


Used in wasm_svg_graphics

MIT license

97KB
1.5K SLoC

Hello fellow Rustacians! Here is a crate with SVG Definitions. This was mostly created to serve as a backend crate for wasm_svg_graphics, but feel free to use it!

I am open to pull requests so please contribute!

Example

Creating a group with a triangle

use svg_definitions::prelude::*;

let triangle = SVGElem::new(Tag::Path)
    .set(Attr::StrokeWidth, 1)
    .set(Attr::Stroke, "#000")
    .set(Attr::Fill, "transparent")
    .set(Attr::D, PathData::new()
        .move_to((0.0, 0.0))
        .line_to((10.0, 0.0))
        .line_to((0.0, 10.0))
        .line_to((0.0, 0.0))
        .close_path()
    );

let group = SVGElem::new(Tag::G)
    .append(triangle);

lib.rs:

Hello fellow Rustacians! Here is a crate with SVG Definitions. This was mostly created to serve as a backend crate for wasm_svg_graphics, but feel free to use it!

I am open to pull requests so please contribute!

Example

Creating a group with a triangle

use svg_definitions::prelude::*;

let triangle = SVGElem::new(Tag::Path)
    .set(Attr::StrokeWidth, 1)
    .set(Attr::Stroke, "#000")
    .set(Attr::Fill, "transparent")
    .set(Attr::D, PathData::new()
        .move_to((0.0, 0.0))
        .line_to((10.0, 0.0))
        .line_to((0.0, 10.0))
        .line_to((0.0, 0.0))
        .close_path()
    );

let group = SVGElem::new(Tag::G)
    .append(triangle);

Getting a svg from a file

The feature "parsing" needs to be enabled for this

use svg_definitions::prelude::*;

let shape = SVGParseFile("/path/to/file.svg");

// ...

Getting a svg from text

The feature "parsing" needs to be enabled for this

use svg_definitions::prelude::*;

let rect = SVGParseText("<rect width=\"50px\" height=\"50\" fill=\"black\" />");

// ...

Dependencies

~52KB