umya_spreadsheet/structs/drawing/
format_scheme.rs

1// a:fontScheme
2use super::super::StringValue;
3use super::BackgroundFillStyleList;
4use super::EffectStyleList;
5use super::FillStyleList;
6use super::LineStyleList;
7use crate::reader::driver::*;
8use crate::writer::driver::*;
9use quick_xml::events::{BytesStart, Event};
10use quick_xml::Reader;
11use quick_xml::Writer;
12use std::io::Cursor;
13
14#[derive(Clone, Default, Debug)]
15pub struct FormatScheme {
16    name: StringValue,
17    fill_style_list: FillStyleList,
18    line_style_list: LineStyleList,
19    effect_style_list: EffectStyleList,
20    background_fill_style_list: BackgroundFillStyleList,
21}
22
23impl FormatScheme {
24    #[inline]
25    pub fn get_name(&self) -> &str {
26        self.name.get_value_str()
27    }
28
29    #[inline]
30    pub fn set_name<S: Into<String>>(&mut self, value: S) -> &mut Self {
31        self.name.set_value(value);
32        self
33    }
34
35    #[inline]
36    pub fn get_fill_style_list(&self) -> &FillStyleList {
37        &self.fill_style_list
38    }
39
40    #[inline]
41    pub fn get_fill_style_list_mut(&mut self) -> &mut FillStyleList {
42        &mut self.fill_style_list
43    }
44
45    #[inline]
46    pub fn set_fill_style_list(&mut self, value: FillStyleList) {
47        self.fill_style_list = value;
48    }
49
50    #[inline]
51    pub fn get_line_style_list(&self) -> &LineStyleList {
52        &self.line_style_list
53    }
54
55    #[inline]
56    pub fn get_line_style_list_mut(&mut self) -> &mut LineStyleList {
57        &mut self.line_style_list
58    }
59
60    #[inline]
61    pub fn set_line_style_list(&mut self, value: LineStyleList) {
62        self.line_style_list = value;
63    }
64
65    #[inline]
66    pub fn get_effect_style_list(&self) -> &EffectStyleList {
67        &self.effect_style_list
68    }
69
70    #[inline]
71    pub fn get_effect_style_list_mut(&mut self) -> &mut EffectStyleList {
72        &mut self.effect_style_list
73    }
74
75    #[inline]
76    pub fn set_effect_style_list(&mut self, value: EffectStyleList) {
77        self.effect_style_list = value;
78    }
79
80    #[inline]
81    pub fn get_background_fill_style_list(&self) -> &BackgroundFillStyleList {
82        &self.background_fill_style_list
83    }
84
85    #[inline]
86    pub fn get_background_fill_style_list_mut(&mut self) -> &mut BackgroundFillStyleList {
87        &mut self.background_fill_style_list
88    }
89
90    #[inline]
91    pub fn set_background_fill_style_list_list(&mut self, value: BackgroundFillStyleList) {
92        self.background_fill_style_list = value;
93    }
94
95    pub(crate) fn set_attributes<R: std::io::BufRead>(
96        &mut self,
97        reader: &mut Reader<R>,
98        e: &BytesStart,
99    ) {
100        if let Some(v) = get_attribute(e, b"name") {
101            self.name.set_value(v);
102        }
103
104        xml_read_loop!(
105            reader,
106            Event::Start(ref e) => {
107                match e.name().into_inner() {
108                    b"a:fillStyleLst" => {
109                        let mut obj = FillStyleList::default();
110                        obj.set_attributes(reader, e);
111                        self.fill_style_list = obj;
112                    }
113                    b"a:lnStyleLst" => {
114                        let mut obj = LineStyleList::default();
115                        obj.set_attributes(reader, e);
116                        self.line_style_list = obj;
117                    }
118                    b"a:effectStyleLst" => {
119                        let mut obj = EffectStyleList::default();
120                        obj.set_attributes(reader, e);
121                        self.effect_style_list = obj;
122                    }
123                    b"a:bgFillStyleLst" => {
124                        let mut obj = BackgroundFillStyleList::default();
125                        obj.set_attributes(reader, e);
126                        self.background_fill_style_list = obj;
127                    }
128                    _ => (),
129                }
130            },
131            Event::End(ref e) => {
132                if e.name().into_inner() == b"a:fmtScheme" {
133                    return
134                }
135            },
136            Event::Eof => panic!("Error: Could not find {} end element", "a:fmtScheme")
137        );
138    }
139
140    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
141        // a:fmtScheme
142        let mut attributes: Vec<(&str, &str)> = Vec::new();
143        if self.name.has_value() {
144            attributes.push(("name", self.name.get_value_str()));
145        }
146        write_start_tag(writer, "a:fmtScheme", attributes, false);
147
148        // a:fillStyleLst
149        self.fill_style_list.write_to(writer);
150
151        // a:lnStyleLst
152        self.line_style_list.write_to(writer);
153
154        // a:effectStyleLst
155        self.effect_style_list.write_to(writer);
156
157        // a:bgFillStyleLst
158        self.background_fill_style_list.write_to(writer);
159
160        write_end_tag(writer, "a:fmtScheme");
161    }
162}