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
68
69
70
71
72
73
74
75
use crate::xml::common::FromFormat;

#[derive(Copy, Clone, Debug)]
pub enum FormatAlignType {
    Top,
    Center,
    Bottom,
    Left,
    VerticalCenter,
    Right,
}

impl Default for FormatAlignType {
    fn default() -> Self {
        FormatAlignType::Center
    }
}

impl FormatAlignType {
    pub(crate) fn to_str(&self) -> &str {
        match self {
            FormatAlignType::Top => "top",
            FormatAlignType::Center => "center",
            FormatAlignType::Bottom => "bottom",
            FormatAlignType::Left => "left",
            FormatAlignType::VerticalCenter => "center",
            FormatAlignType::Right => "right",
        }
    }

    pub(crate) fn from_str(format_align_type: Option<&String>, is_horizontal: bool) -> Option<FormatAlignType> {
        if let Some(format_align_type) = format_align_type {
            let format_align_type = format_align_type.as_str();
            Some(match format_align_type {
                "top" => FormatAlignType::Top,
                "center" => if is_horizontal { FormatAlignType::Center } else { FormatAlignType::VerticalCenter },
                "bottom" => FormatAlignType::Bottom,
                "left" => FormatAlignType::Left,
                "right" => FormatAlignType::Right,
                _ => FormatAlignType::default()
            })
        } else {
            None
        }
    }
}

impl FromFormat<FormatAlignType> for String {
    fn set_attrs_by_format(&mut self, format: &FormatAlignType) {
        *self = format.to_str().to_string();
    }

    fn set_format(&self, format: &mut FormatAlignType) {
        todo!()
    }
}

#[derive(Clone, Debug)]
pub struct FormatAlign {
    pub(crate) horizontal: Option<FormatAlignType>,
    pub(crate) vertical: Option<FormatAlignType>,
    pub(crate) reading_order: Option<u8>,
    pub(crate) indent: Option<u8>,
}

impl Default for FormatAlign {
    fn default() -> Self {
        Self {
            horizontal: None,// FormatAlignType::Right,
            vertical: None,// FormatAlignType::Bottom,
            reading_order: None,
            indent: None,
        }
    }
}