1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::tess;
use crate::types::{Color, Transform};

#[derive(Debug, Copy, Clone)]
pub enum AnchorMode {
    First,
    Center,
}

#[derive(Debug, Copy, Clone)]
pub struct Context {
    pub anchor_mode: AnchorMode,
    pub transform: Transform,
    pub fill: Option<Color>,
    pub stroke: Option<Color>,
    pub stroke_weight: f32,
}

impl Context {
    pub fn get_fill_options(&self) -> tess::FillOptions {
        tess::FillOptions::default() //.with_fill_rule(self.fill_rule.into())
    }

    pub fn get_stroke_options(&self) -> tess::StrokeOptions {
        // get_stroke_options should only be used when there is a
        // stroke defined.
        let width = self.stroke_weight;

        tess::StrokeOptions::default().with_line_width(width)
    }
}

impl Default for Context {
    fn default() -> Self {
        Self {
            anchor_mode: AnchorMode::Center,
            transform: Transform::identity(),
            fill: Some(Color::new(0.0, 0.0, 0.0, 1.0)),
            stroke: Some(Color::new(0.0, 0.0, 0.0, 1.0)),
            stroke_weight: 1.0,
        }
    }
}