umya_spreadsheet/structs/drawing/
format_scheme.rs1use std::io::Cursor;
3
4use quick_xml::{
5 Reader,
6 Writer,
7 events::{
8 BytesStart,
9 Event,
10 },
11};
12
13use super::{
14 super::StringValue,
15 BackgroundFillStyleList,
16 EffectStyleList,
17 FillStyleList,
18 LineStyleList,
19};
20use crate::{
21 reader::driver::{
22 get_attribute,
23 xml_read_loop,
24 },
25 writer::driver::{
26 write_end_tag,
27 write_start_tag,
28 },
29};
30
31#[derive(Clone, Default, Debug)]
32pub struct FormatScheme {
33 name: StringValue,
34 fill_style_list: FillStyleList,
35 line_style_list: LineStyleList,
36 effect_style_list: EffectStyleList,
37 background_fill_style_list: BackgroundFillStyleList,
38}
39
40impl FormatScheme {
41 #[inline]
42 #[must_use]
43 pub fn name(&self) -> &str {
44 self.name.value_str()
45 }
46
47 #[inline]
48 #[must_use]
49 #[deprecated(since = "3.0.0", note = "Use name()")]
50 pub fn get_name(&self) -> &str {
51 self.name()
52 }
53
54 #[inline]
55 pub fn set_name<S: Into<String>>(&mut self, value: S) -> &mut Self {
56 self.name.set_value(value);
57 self
58 }
59
60 #[inline]
61 #[must_use]
62 pub fn fill_style_list(&self) -> &FillStyleList {
63 &self.fill_style_list
64 }
65
66 #[inline]
67 #[must_use]
68 #[deprecated(since = "3.0.0", note = "Use fill_style_list()")]
69 pub fn get_fill_style_list(&self) -> &FillStyleList {
70 self.fill_style_list()
71 }
72
73 #[inline]
74 pub fn fill_style_list_mut(&mut self) -> &mut FillStyleList {
75 &mut self.fill_style_list
76 }
77
78 #[inline]
79 #[deprecated(since = "3.0.0", note = "Use fill_style_list_mut()")]
80 pub fn get_fill_style_list_mut(&mut self) -> &mut FillStyleList {
81 self.fill_style_list_mut()
82 }
83
84 #[inline]
85 pub fn set_fill_style_list(&mut self, value: FillStyleList) {
86 self.fill_style_list = value;
87 }
88
89 #[inline]
90 #[must_use]
91 pub fn line_style_list(&self) -> &LineStyleList {
92 &self.line_style_list
93 }
94
95 #[inline]
96 #[must_use]
97 #[deprecated(since = "3.0.0", note = "Use line_style_list()")]
98 pub fn get_line_style_list(&self) -> &LineStyleList {
99 self.line_style_list()
100 }
101
102 #[inline]
103 pub fn line_style_list_mut(&mut self) -> &mut LineStyleList {
104 &mut self.line_style_list
105 }
106
107 #[inline]
108 #[deprecated(since = "3.0.0", note = "Use line_style_list_mut()")]
109 pub fn get_line_style_list_mut(&mut self) -> &mut LineStyleList {
110 self.line_style_list_mut()
111 }
112
113 #[inline]
114 pub fn set_line_style_list(&mut self, value: LineStyleList) {
115 self.line_style_list = value;
116 }
117
118 #[inline]
119 #[must_use]
120 pub fn effect_style_list(&self) -> &EffectStyleList {
121 &self.effect_style_list
122 }
123
124 #[inline]
125 #[must_use]
126 #[deprecated(since = "3.0.0", note = "Use effect_style_list()")]
127 pub fn get_effect_style_list(&self) -> &EffectStyleList {
128 self.effect_style_list()
129 }
130
131 #[inline]
132 pub fn effect_style_list_mut(&mut self) -> &mut EffectStyleList {
133 &mut self.effect_style_list
134 }
135
136 #[inline]
137 #[deprecated(since = "3.0.0", note = "Use effect_style_list_mut()")]
138 pub fn get_effect_style_list_mut(&mut self) -> &mut EffectStyleList {
139 self.effect_style_list_mut()
140 }
141
142 #[inline]
143 pub fn set_effect_style_list(&mut self, value: EffectStyleList) {
144 self.effect_style_list = value;
145 }
146
147 #[inline]
148 #[must_use]
149 pub fn background_fill_style_list(&self) -> &BackgroundFillStyleList {
150 &self.background_fill_style_list
151 }
152
153 #[inline]
154 #[must_use]
155 #[deprecated(since = "3.0.0", note = "Use background_fill_style_list()")]
156 pub fn get_background_fill_style_list(&self) -> &BackgroundFillStyleList {
157 self.background_fill_style_list()
158 }
159
160 #[inline]
161 pub fn background_fill_style_list_mut(&mut self) -> &mut BackgroundFillStyleList {
162 &mut self.background_fill_style_list
163 }
164
165 #[inline]
166 #[deprecated(since = "3.0.0", note = "Use background_fill_style_list_mut()")]
167 pub fn get_background_fill_style_list_mut(&mut self) -> &mut BackgroundFillStyleList {
168 self.background_fill_style_list_mut()
169 }
170
171 #[inline]
172 pub fn set_background_fill_style_list_list(&mut self, value: BackgroundFillStyleList) {
173 self.background_fill_style_list = value;
174 }
175
176 pub(crate) fn set_attributes<R: std::io::BufRead>(
177 &mut self,
178 reader: &mut Reader<R>,
179 e: &BytesStart,
180 ) {
181 if let Some(v) = get_attribute(e, b"name") {
182 self.name.set_value(v);
183 }
184
185 xml_read_loop!(
186 reader,
187 Event::Start(ref e) => {
188 match e.name().into_inner() {
189 b"a:fillStyleLst" => {
190 let mut obj = FillStyleList::default();
191 obj.set_attributes(reader, e);
192 self.fill_style_list = obj;
193 }
194 b"a:lnStyleLst" => {
195 let mut obj = LineStyleList::default();
196 obj.set_attributes(reader, e);
197 self.line_style_list = obj;
198 }
199 b"a:effectStyleLst" => {
200 let mut obj = EffectStyleList::default();
201 obj.set_attributes(reader, e);
202 self.effect_style_list = obj;
203 }
204 b"a:bgFillStyleLst" => {
205 let mut obj = BackgroundFillStyleList::default();
206 obj.set_attributes(reader, e);
207 self.background_fill_style_list = obj;
208 }
209 _ => (),
210 }
211 },
212 Event::End(ref e) => {
213 if e.name().into_inner() == b"a:fmtScheme" {
214 return
215 }
216 },
217 Event::Eof => panic!("Error: Could not find {} end element", "a:fmtScheme")
218 );
219 }
220
221 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
222 let mut attributes: crate::structs::AttrCollection = Vec::new();
224 if self.name.has_value() {
225 attributes.push(("name", self.name.value_str()).into());
226 }
227 write_start_tag(writer, "a:fmtScheme", attributes, false);
228
229 self.fill_style_list.write_to(writer);
231
232 self.line_style_list.write_to(writer);
234
235 self.effect_style_list.write_to(writer);
237
238 self.background_fill_style_list.write_to(writer);
240
241 write_end_tag(writer, "a:fmtScheme");
242 }
243}