umya_spreadsheet/structs/drawing/
scheme_color.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::EnumValue,
15 PercentageType,
16 PositiveFixedPercentageType,
17 SchemeColorValues,
18};
19use crate::{
20 reader::driver::{
21 get_attribute,
22 xml_read_loop,
23 },
24 writer::driver::{
25 write_end_tag,
26 write_start_tag,
27 },
28};
29
30#[derive(Clone, Default, Debug)]
31pub struct SchemeColor {
32 val: EnumValue<SchemeColorValues>,
33 luminance: Option<PercentageType>,
34 luminance_modulation: Option<PercentageType>,
35 luminance_offset: Option<PercentageType>,
36 saturation: Option<PercentageType>,
37 saturation_modulation: Option<PercentageType>,
38 shade: Option<PositiveFixedPercentageType>,
39 alpha: Option<PositiveFixedPercentageType>,
40 tint: Option<PositiveFixedPercentageType>,
41}
42
43impl SchemeColor {
44 #[inline]
45 #[must_use]
46 pub fn val(&self) -> &SchemeColorValues {
47 self.val.value()
48 }
49
50 #[inline]
51 #[must_use]
52 #[deprecated(since = "3.0.0", note = "Use val()")]
53 pub fn get_val(&self) -> &SchemeColorValues {
54 self.val()
55 }
56
57 #[inline]
58 pub fn set_val(&mut self, value: SchemeColorValues) -> &mut Self {
59 self.val.set_value(value);
60 self
61 }
62
63 #[inline]
64 #[must_use]
65 pub fn luminance(&self) -> Option<&PercentageType> {
66 self.luminance.as_ref()
67 }
68
69 #[inline]
70 #[must_use]
71 #[deprecated(since = "3.0.0", note = "Use luminance()")]
72 pub fn get_luminance(&self) -> Option<&PercentageType> {
73 self.luminance()
74 }
75
76 #[inline]
77 pub fn luminance_mut(&mut self) -> Option<&mut PercentageType> {
78 self.luminance.as_mut()
79 }
80
81 #[inline]
82 #[deprecated(since = "3.0.0", note = "Use luminance_mut()")]
83 pub fn get_luminance_mut(&mut self) -> Option<&mut PercentageType> {
84 self.luminance_mut()
85 }
86
87 #[inline]
88 pub fn set_luminance(&mut self, value: PercentageType) {
89 self.luminance = Some(value);
90 }
91
92 #[inline]
93 #[must_use]
94 pub fn luminance_modulation(&self) -> Option<&PercentageType> {
95 self.luminance_modulation.as_ref()
96 }
97
98 #[inline]
99 #[must_use]
100 #[deprecated(since = "3.0.0", note = "Use luminance_modulation()")]
101 pub fn get_luminance_modulation(&self) -> Option<&PercentageType> {
102 self.luminance_modulation()
103 }
104
105 #[inline]
106 pub fn luminance_modulation_mut(&mut self) -> Option<&mut PercentageType> {
107 self.luminance_modulation.as_mut()
108 }
109
110 #[inline]
111 #[deprecated(since = "3.0.0", note = "Use luminance_modulation_mut()")]
112 pub fn get_luminance_modulation_mut(&mut self) -> Option<&mut PercentageType> {
113 self.luminance_modulation_mut()
114 }
115
116 #[inline]
117 pub fn set_luminance_modulation(&mut self, value: PercentageType) {
118 self.luminance_modulation = Some(value);
119 }
120
121 #[inline]
122 #[must_use]
123 pub fn luminance_offset(&self) -> Option<&PercentageType> {
124 self.luminance_offset.as_ref()
125 }
126
127 #[inline]
128 #[must_use]
129 #[deprecated(since = "3.0.0", note = "Use luminance_offset()")]
130 pub fn get_luminance_offset(&self) -> Option<&PercentageType> {
131 self.luminance_offset()
132 }
133
134 #[inline]
135 pub fn luminance_offset_mut(&mut self) -> Option<&mut PercentageType> {
136 self.luminance_offset.as_mut()
137 }
138
139 #[inline]
140 #[deprecated(since = "3.0.0", note = "Use luminance_offset_mut()")]
141 pub fn get_luminance_offset_mut(&mut self) -> Option<&mut PercentageType> {
142 self.luminance_offset_mut()
143 }
144
145 #[inline]
146 pub fn set_luminance_offset(&mut self, value: PercentageType) {
147 self.luminance_offset = Some(value);
148 }
149
150 #[inline]
151 #[must_use]
152 pub fn saturation(&self) -> Option<&PercentageType> {
153 self.saturation.as_ref()
154 }
155
156 #[inline]
157 #[must_use]
158 #[deprecated(since = "3.0.0", note = "Use saturation()")]
159 pub fn get_saturation(&self) -> Option<&PercentageType> {
160 self.saturation()
161 }
162
163 #[inline]
164 pub fn saturation_mut(&mut self) -> Option<&mut PercentageType> {
165 self.saturation.as_mut()
166 }
167
168 #[inline]
169 #[deprecated(since = "3.0.0", note = "Use saturation_mut()")]
170 pub fn get_saturation_mut(&mut self) -> Option<&mut PercentageType> {
171 self.saturation_mut()
172 }
173
174 #[inline]
175 pub fn set_saturation(&mut self, value: PercentageType) {
176 self.saturation = Some(value);
177 }
178
179 #[inline]
180 #[must_use]
181 pub fn saturation_modulation(&self) -> Option<&PercentageType> {
182 self.saturation_modulation.as_ref()
183 }
184
185 #[inline]
186 #[must_use]
187 #[deprecated(since = "3.0.0", note = "Use saturation_modulation()")]
188 pub fn get_saturation_modulation(&self) -> Option<&PercentageType> {
189 self.saturation_modulation()
190 }
191
192 #[inline]
193 pub fn saturation_modulation_mut(&mut self) -> Option<&mut PercentageType> {
194 self.saturation_modulation.as_mut()
195 }
196
197 #[inline]
198 #[deprecated(since = "3.0.0", note = "Use saturation_modulation_mut()")]
199 pub fn get_saturation_modulation_mut(&mut self) -> Option<&mut PercentageType> {
200 self.saturation_modulation_mut()
201 }
202
203 #[inline]
204 pub fn set_saturation_modulation(&mut self, value: PercentageType) {
205 self.saturation_modulation = Some(value);
206 }
207
208 #[inline]
209 #[must_use]
210 pub fn shade(&self) -> Option<&PositiveFixedPercentageType> {
211 self.shade.as_ref()
212 }
213
214 #[inline]
215 #[must_use]
216 #[deprecated(since = "3.0.0", note = "Use shade()")]
217 pub fn get_shade(&self) -> Option<&PositiveFixedPercentageType> {
218 self.shade()
219 }
220
221 #[inline]
222 pub fn shade_mut(&mut self) -> Option<&mut PositiveFixedPercentageType> {
223 self.shade.as_mut()
224 }
225
226 #[inline]
227 #[deprecated(since = "3.0.0", note = "Use shade_mut()")]
228 pub fn get_shade_mut(&mut self) -> Option<&mut PositiveFixedPercentageType> {
229 self.shade_mut()
230 }
231
232 #[inline]
233 pub fn set_shade(&mut self, value: PositiveFixedPercentageType) {
234 self.shade = Some(value);
235 }
236
237 #[inline]
238 #[must_use]
239 pub fn alpha(&self) -> Option<&PositiveFixedPercentageType> {
240 self.alpha.as_ref()
241 }
242
243 #[inline]
244 #[must_use]
245 #[deprecated(since = "3.0.0", note = "Use alpha()")]
246 pub fn get_alpha(&self) -> Option<&PositiveFixedPercentageType> {
247 self.alpha()
248 }
249
250 #[inline]
251 pub fn alpha_mut(&mut self) -> Option<&mut PositiveFixedPercentageType> {
252 self.alpha.as_mut()
253 }
254
255 #[inline]
256 #[deprecated(since = "3.0.0", note = "Use alpha_mut()")]
257 pub fn get_alpha_mut(&mut self) -> Option<&mut PositiveFixedPercentageType> {
258 self.alpha_mut()
259 }
260
261 #[inline]
262 pub fn set_alpha(&mut self, value: PositiveFixedPercentageType) {
263 self.alpha = Some(value);
264 }
265
266 #[inline]
267 #[must_use]
268 pub fn tint(&self) -> Option<&PositiveFixedPercentageType> {
269 self.tint.as_ref()
270 }
271
272 #[inline]
273 #[must_use]
274 #[deprecated(since = "3.0.0", note = "Use tint()")]
275 pub fn get_tint(&self) -> Option<&PositiveFixedPercentageType> {
276 self.tint()
277 }
278
279 #[inline]
280 pub fn tint_mut(&mut self) -> Option<&mut PositiveFixedPercentageType> {
281 self.tint.as_mut()
282 }
283
284 #[inline]
285 #[deprecated(since = "3.0.0", note = "Use tint_mut()")]
286 pub fn get_tint_mut(&mut self) -> Option<&mut PositiveFixedPercentageType> {
287 self.tint_mut()
288 }
289
290 #[inline]
291 pub fn set_tint(&mut self, value: PositiveFixedPercentageType) {
292 self.tint = Some(value);
293 }
294
295 #[inline]
296 pub(crate) fn with_inner_params(&self) -> bool {
297 self.luminance.is_some()
298 || self.luminance_modulation.is_some()
299 || self.luminance_offset.is_some()
300 || self.saturation.is_some()
301 || self.saturation_modulation.is_some()
302 || self.shade.is_some()
303 || self.alpha.is_some()
304 || self.tint.is_some()
305 }
306
307 pub(crate) fn set_attributes<R: std::io::BufRead>(
308 &mut self,
309 reader: &mut Reader<R>,
310 e: &BytesStart,
311 empty_flag: bool,
312 ) {
313 self.val.set_value_string(get_attribute(e, b"val").unwrap());
314
315 if empty_flag {
316 return;
317 }
318
319 xml_read_loop!(
320 reader,
321 Event::Empty(ref e) => {
322 match e.name().into_inner() {
323 b"a:lum" => {
324 let mut obj = PercentageType::default();
325 obj.set_attributes(reader, e, true);
326 self.luminance = Some(obj);
327 }
328 b"a:lumMod" => {
329 let mut obj = PercentageType::default();
330 obj.set_attributes(reader, e, true);
331 self.luminance_modulation = Some(obj);
332 }
333 b"a:lumOff" => {
334 let mut obj = PercentageType::default();
335 obj.set_attributes(reader, e, true);
336 self.luminance_offset = Some(obj);
337 }
338 b"a:sat" => {
339 let mut obj = PercentageType::default();
340 obj.set_attributes(reader, e, true);
341 self.saturation = Some(obj);
342 }
343 b"a:satMod" => {
344 let mut obj = PercentageType::default();
345 obj.set_attributes(reader, e, true);
346 self.saturation_modulation = Some(obj);
347 }
348 b"a:shade" => {
349 let mut obj = PositiveFixedPercentageType::default();
350 obj.set_attributes(reader, e, true);
351 self.shade = Some(obj);
352 }
353 b"a:alpha" => {
354 let mut obj = PositiveFixedPercentageType::default();
355 obj.set_attributes(reader, e, true);
356 self.alpha = Some(obj);
357 }
358 b"a:tint" => {
359 let mut obj = PositiveFixedPercentageType::default();
360 obj.set_attributes(reader, e, true);
361 self.tint = Some(obj);
362 }
363 _ => (),
364 }
365 },
366 Event::Start(ref e) => {
367 match e.name().into_inner() {
368 b"a:lum" => {
369 let mut obj = PercentageType::default();
370 obj.set_attributes(reader, e, false);
371 self.luminance = Some(obj);
372 }
373 b"a:lumMod" => {
374 let mut obj = PercentageType::default();
375 obj.set_attributes(reader, e, false);
376 self.luminance_modulation = Some(obj);
377 }
378 b"a:lumOff" => {
379 let mut obj = PercentageType::default();
380 obj.set_attributes(reader, e, false);
381 self.luminance_offset = Some(obj);
382 }
383 b"a:sat" => {
384 let mut obj = PercentageType::default();
385 obj.set_attributes(reader, e, false);
386 self.saturation = Some(obj);
387 }
388 b"a:satMod" => {
389 let mut obj = PercentageType::default();
390 obj.set_attributes(reader, e, false);
391 self.saturation_modulation = Some(obj);
392 }
393 b"a:shade" => {
394 let mut obj = PositiveFixedPercentageType::default();
395 obj.set_attributes(reader, e, false);
396 self.shade = Some(obj);
397 }
398 b"a:alpha" => {
399 let mut obj = PositiveFixedPercentageType::default();
400 obj.set_attributes(reader, e, false);
401 self.alpha = Some(obj);
402 }
403 b"a:tint" => {
404 let mut obj = PositiveFixedPercentageType::default();
405 obj.set_attributes(reader, e, false);
406 self.tint = Some(obj);
407 }
408 _ => (),
409 }
410 },
411 Event::End(ref e) => {
412 if e.name().into_inner() == b"a:schemeClr" {
413 return;
414 }
415 },
416 Event::Eof => panic!("Error: Could not find {} end element", "a:schemeClr")
417 );
418 }
419
420 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
421 if self.with_inner_params() {
423 write_start_tag(
424 writer,
425 "a:schemeClr",
426 vec![("val", self.val.value_string()).into()],
427 false,
428 );
429
430 if let Some(v) = &self.luminance {
432 v.write_to_lum(writer);
433 }
434
435 if let Some(v) = &self.luminance_modulation {
437 v.write_to_lum_mod(writer);
438 }
439
440 if let Some(v) = &self.luminance_offset {
442 v.write_to_lum_off(writer);
443 }
444
445 if let Some(v) = &self.saturation {
447 v.write_to_sat(writer);
448 }
449
450 if let Some(v) = &self.saturation_modulation {
452 v.write_to_sat_mod(writer);
453 }
454
455 if let Some(v) = &self.shade {
457 v.write_to_shade(writer);
458 }
459
460 if let Some(v) = &self.alpha {
462 v.write_to_alpha(writer);
463 }
464
465 if let Some(v) = &self.tint {
467 v.write_to_tint(writer);
468 }
469
470 write_end_tag(writer, "a:schemeClr");
471 } else {
472 write_start_tag(
473 writer,
474 "a:schemeClr",
475 vec![("val", self.val.value_string()).into()],
476 true,
477 );
478 }
479 }
480}