Skip to content

432-Technologies/dessin

Repository files navigation

dessin is library aimed at building complex drawings, combine them, move them and export them as PDF or SVG.

Getting started

Add dessin and dessin-svg to your project dependencies

cargo add dessin dessin-svg

or if you need PDF:

cargo add dessin dessin-pdf

Documentation on docs.rs

Overview

use dessin::prelude::*;

#[derive(Default, Shape)]
struct MyShape {
  text: String,
}
impl MyShape {
  fn say_this(&mut self, what: &str) {
    self.text = format!("{} And check this out: `{what}`", self.text);
  }
}
impl From<MyShape> for Shape {
  fn from(MyShape { text }: MyShape) -> Self {
    dessin2!(Text!(fill = Color::RED, { text })).into()
  }
}

fn main() {
  let dessin = dessin2!(for x in 0..10 {
    let radius = x as f32 * 10.;

    dessin2!([
      Circle!(
        fill = Color::RED,
        { radius },
        translate = [x as f32 * 5., 10.],
      ),
      Text!(fill = Color::BLACK, font_size = 10., text = "Hi !",),
    ])
  });

  let dessin = dessin2!([
    { dessin }(scale = [2., 2.]),
    MyShape(say_this = "Hello world"),
  ]);

  let svg = dessin_svg::to_string(&dessin).unwrap();
}

About

Generate complex drawing for PDF, SVG, and many more to come !

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •