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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Define the paragraph related structs and enums

use crate::tokens::ControlWord;

#[derive(Debug, Default, Clone, PartialEq)]
pub struct Paragraph {
    pub alignment: Alignment,
    pub spacing: Spacing,
    pub indent: Indentation,
    pub tab_width: i32,
}

#[derive(Debug, Default, Clone, Copy, PartialEq)]
pub enum Alignment {
    #[default]
    LeftAligned,
    RightAligned,
    Center,
    Justify,
}

impl From<&ControlWord<'_>> for Alignment {
    fn from(cw: &ControlWord) -> Self {
        return match cw {
            ControlWord::LeftAligned  => Alignment::LeftAligned,
            ControlWord::RightAligned => Alignment::RightAligned,
            ControlWord::Center       => Alignment::Center,
            ControlWord::Justify      => Alignment::Justify,
            _  /* default */          => Alignment::LeftAligned,
        };
    }
}

#[derive(Debug, Default, Clone, PartialEq)]
pub struct Spacing {
    pub before: i32,
    pub after: i32,
    pub between_line: SpaceBetweenLine,
    pub line_multiplier: i32,
}

#[derive(Default, Debug, Clone, PartialEq)]
pub enum SpaceBetweenLine {
    Value(i32),
    #[default]
    Auto,
    Invalid,
}

//Space between lines. If this control word is missing or if \sl1000 is used, the line spacing is automatically determined by the tallest character in the line; if N is a positive value, this size is used only if it is taller than the tallest character (otherwise, the tallest character is used); if N is a negative value, the absolute value of N is used, even if it is shorter than the tallest character.
impl From<i32> for SpaceBetweenLine {
    fn from(value: i32) -> Self {
        return match value {
            1000 => SpaceBetweenLine::Auto,
            val if val < 0 => SpaceBetweenLine::Value(val.abs()),
            val => SpaceBetweenLine::Value(val),
        };
    }
}

// Could not be an enum because left-indent and right-ident can both be defined at the same time
#[derive(Default, Debug, Clone, PartialEq)]
pub struct Indentation {
    pub left: i32,
    pub right: i32,
    pub first_line: i32,
}