[][src]Crate svg_definitions

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\" />");

// ...

Modules

attributes

This module provides an easy and safe way to interact with attributes of Elements

path

This module provides an nicer and easier way to interact with SVG Path Definition Strings.

prelude

Prelude for this crate, this contains a lot of useful exports

tag_name

Structs

Element

Element provides a way to simulate DOM SVG elements

Type Definitions

Point2D