xdot/xdot_parse/
ops.rs

1//! xdot drawing and pen manipulation operation
2use super::{
3    draw::{FontCharacteristics, Rgba, Style},
4    shapes::*,
5};
6
7/// An operation to draw a shape or modify drawing attributes like color or line style.
8#[derive(Debug, Clone, PartialEq)]
9pub(super) enum Op {
10    DrawShape(Shape),
11    SetFontCharacteristics(FontCharacteristics),
12    SetFillColor(Rgba),
13    SetPenColor(Rgba),
14    SetFont { size: f32, name: String },
15    SetStyle(Style), // TODO: is it just one?
16    ExternalImage(ExternalImage),
17}
18
19// shapes
20
21impl From<Shape> for Op {
22    fn from(val: Shape) -> Self {
23        Op::DrawShape(val)
24    }
25}
26
27impl From<Ellipse> for Op {
28    fn from(val: Ellipse) -> Self {
29        Into::<Shape>::into(val).into()
30    }
31}
32impl From<Points> for Op {
33    fn from(val: Points) -> Self {
34        Into::<Shape>::into(val).into()
35    }
36}
37impl From<Text> for Op {
38    fn from(val: Text) -> Self {
39        Into::<Shape>::into(val).into()
40    }
41}
42
43// rest
44
45impl From<FontCharacteristics> for Op {
46    fn from(val: FontCharacteristics) -> Self {
47        Op::SetFontCharacteristics(val)
48    }
49}
50
51impl From<Style> for Op {
52    fn from(val: Style) -> Self {
53        Op::SetStyle(val)
54    }
55}
56
57impl From<ExternalImage> for Op {
58    fn from(val: ExternalImage) -> Self {
59        Op::ExternalImage(val)
60    }
61}