typography/
typography.rs

1use aoer_plotty_rs::context::typography::{TextAlignment, Typography};
2use aoer_plotty_rs::context::Context;
3use aoer_plotty_rs::geo_types::svg::Arrangement;
4use aoer_plotty_rs::prelude::NoHatch;
5use geo_types::{coord, Rect};
6use std::path::Path;
7use std::sync::Arc;
8
9fn main() {
10    let mut ctx = Context::new();
11    let mut typ = Typography::new();
12    typ.size(2.0);
13    typ.close(true);
14
15    ctx.stroke("black")
16        .fill("red")
17        .pen(0.5)
18        .pattern(Arc::new(Box::new(NoHatch {})))
19        // .pattern(LineHatch::gen())
20        // .typography(&"i".to_string(), 50.0, 50.0, &typ);
21        .typography(&"Left".to_string(), 50.0, 50.0, &typ);
22    typ.align(TextAlignment::Right);
23    ctx.typography(&"Right".to_string(), 50.0, 90.0, &typ);
24    typ.align(TextAlignment::Center);
25    ctx.typography(&"Center".to_string(), 50.0, 70.0, &typ);
26
27    let svg = ctx
28        .to_svg(&Arrangement::<f64>::unit(&Rect::<f64>::new(
29            coord! {x:0.0, y:0.0},
30            coord! {x:100.0, y:100.0},
31        )))
32        .unwrap();
33    // Write it to the images folder, so we can use it as an example!
34    // Write it out to /images/$THIS_EXAMPLE_FILE.svg
35    let fname = Path::new(file!()).file_stem().unwrap().to_str().unwrap();
36    svg::save(format!("images/{}.svg", fname), &svg).unwrap();
37}