text/
text.rs

1use font_kit::family_name::FamilyName;
2use font_kit::properties::{Properties, Weight};
3use font_kit::source::SystemSource;
4use raqote::*;
5
6fn main() {
7    let mut dt = DrawTarget::new(300, 100);
8    dt.clear(SolidSource::from_unpremultiplied_argb(
9        0xff, 0xcf, 0xcf, 0xcf,
10    ));
11
12    let font = SystemSource::new()
13        .select_best_match(
14            &[FamilyName::Title("Roboto".into())],
15            &Properties::new().weight(Weight::MEDIUM),
16        )
17        .unwrap()
18        .load()
19        .unwrap();
20    println!("{:?}", font);
21
22    //dt.set_transform(&Transform::create_translation(50.0, 0.0));
23    dt.set_transform(&Transform::rotation(euclid::Angle::degrees(15.0)));
24    let font = font_kit::loader::Loader::from_file(&mut std::fs::File::open("res/Box3.ttf").unwrap(), 0).unwrap();
25    dt.draw_text(
26        &font,
27        30.,
28        "3",
29        Point::new(0., 30.),
30        &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
31        &DrawOptions::new(),
32    );
33    dt.fill_rect(0., 35., 40., 5., &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
34    &DrawOptions::new() );
35
36    dt.write_png("out.png").unwrap();
37}