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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
use hard_xml::{XmlRead, XmlWrite};
use std::borrow::Cow;

use crate::{__string_enum, __xml_test_suites};

/// Text Color
///
/// Specifies the color to be used to display text.
///
/// ```rust
/// use docx_rust::formatting::Color;
///
/// let color = Color::from("000000");
/// let color = Color::from(String::from("000000"));
/// let color = Color::from(0u32); // "000000"
/// let color = Color::from((0u8, 0u8, 0u8)); // "000000"
/// ```
#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:color")]
pub struct Color<'a> {
    #[xml(attr = "w:val")]
    pub value: Cow<'a, str>,
}

impl<'a> From<&'a str> for Color<'a> {
    fn from(val: &'a str) -> Self {
        Color {
            value: Cow::Borrowed(val),
        }
    }
}

impl From<String> for Color<'_> {
    fn from(val: String) -> Self {
        Color {
            value: Cow::Owned(val),
        }
    }
}

impl From<u32> for Color<'_> {
    fn from(val: u32) -> Self {
        Color {
            value: Cow::Owned(format!("{:06x}", val)),
        }
    }
}

impl From<(u8, u8, u8)> for Color<'_> {
    fn from(val: (u8, u8, u8)) -> Self {
        Color {
            value: Cow::Owned(format!("{:02x}{:02x}{:02x}", val.0, val.1, val.2)),
        }
    }
}

#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:highlight")]
pub struct Highlight {
    #[xml(attr = "w:val")]
    pub value: Option<HighlightType>,
}

#[derive(Debug, Clone)]
#[cfg_attr(test, derive(PartialEq))]
pub enum HighlightType {
    Black,       //Black Highlighting Color
    Blue,        //Blue Highlighting Color
    Cyan,        //Cyan Highlighting Color
    Green,       //Green Highlighting Color
    Magenta,     //Magenta Highlighting Color
    Red,         //Red Highlighting Color
    Yellow,      //Yellow Highlighting Color
    White,       //White Highlighting Color
    DarkBlue,    //Dark Blue Highlighting Color
    DarkCyan,    //Dark Cyan Highlighting Color
    DarkGreen,   //Dark Green Highlighting Color
    DarkMagenta, //Dark Magenta Highlighting Color
    DarkRed,     //Dark Red Highlighting Color
    DarkYellow,  //Dark Yellow Highlighting Color
    DarkGray,    //Dark Gray Highlighting Color
    LightGray,   //Light Gray Highlighting Color
    None,        //No Text Highlighting
}

__string_enum! {
    HighlightType {
        Black = "black",
        Blue = "blue",
        Cyan = "cyan",
        Green = "green",
        Magenta = "magenta",
        Red = "red",
        Yellow = "yellow",
        White = "white",
        DarkBlue = "darkBlue",
        DarkCyan = "darkCyan",
        DarkGreen = "darkGreen",
        DarkMagenta = "darkMagenta",
        DarkRed = "darkRed",
        DarkYellow = "darkYellow",
        DarkGray = "darkGray",
        LightGray = "lightGray",
        None = "none",
    }
}

#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:vertAlign")]
pub struct VertAlign {
    #[xml(attr = "w:val")]
    pub value: Option<VertAlignType>,
}

#[derive(Debug, Clone)]
#[cfg_attr(test, derive(PartialEq))]
pub enum VertAlignType {
    Baseline,    //Regular Vertical Positioning
    Superscript, //	Superscript
    Subscript,   //	Subscript
}

__string_enum! {
    VertAlignType {
        Baseline = "baseline",
        Subscript = "subscript",
        Superscript = "superscript",
    }
}

__xml_test_suites!(
    Color,
    Color::from("000000"),
    r#"<w:color w:val="000000"/>"#,
    Color::from(0u32),
    r#"<w:color w:val="000000"/>"#,
    Color::from((0u8, 0u8, 0u8)),
    r#"<w:color w:val="000000"/>"#,
);