umya_spreadsheet/structs/drawing/
solid_fill.rs1use std::io::Cursor;
3
4use quick_xml::{
5 Reader,
6 Writer,
7 events::{
8 BytesStart,
9 Event,
10 },
11};
12
13use super::{
14 rgb_color_model_hex::RgbColorModelHex,
15 scheme_color::SchemeColor,
16};
17use crate::{
18 drawing::SystemColor,
19 reader::driver::xml_read_loop,
20 writer::driver::{
21 write_end_tag,
22 write_start_tag,
23 },
24};
25
26#[derive(Clone, Default, Debug)]
27pub struct SolidFill {
28 scheme_color: Option<Box<SchemeColor>>,
29 rgb_color_model_hex: Option<Box<RgbColorModelHex>>,
30 system_color: Option<Box<SystemColor>>,
31}
32
33impl SolidFill {
34 #[inline]
35 #[must_use]
36 pub fn scheme_color(&self) -> Option<&SchemeColor> {
37 self.scheme_color.as_deref()
38 }
39
40 #[inline]
41 #[must_use]
42 #[deprecated(since = "3.0.0", note = "Use scheme_color()")]
43 pub fn get_scheme_color(&self) -> Option<&SchemeColor> {
44 self.scheme_color()
45 }
46
47 #[inline]
48 pub fn scheme_color_mut(&mut self) -> Option<&mut SchemeColor> {
49 self.scheme_color.as_deref_mut()
50 }
51
52 #[inline]
53 #[deprecated(since = "3.0.0", note = "Use scheme_color_mut()")]
54 pub fn get_scheme_color_mut(&mut self) -> Option<&mut SchemeColor> {
55 self.scheme_color_mut()
56 }
57
58 #[inline]
59 pub fn set_scheme_color(&mut self, value: SchemeColor) {
60 self.scheme_color = Some(Box::new(value));
61 }
62
63 #[inline]
64 #[must_use]
65 pub fn rgb_color_model_hex(&self) -> Option<&RgbColorModelHex> {
66 self.rgb_color_model_hex.as_deref()
67 }
68
69 #[inline]
70 #[must_use]
71 #[deprecated(since = "3.0.0", note = "Use rgb_color_model_hex()")]
72 pub fn get_rgb_color_model_hex(&self) -> Option<&RgbColorModelHex> {
73 self.rgb_color_model_hex()
74 }
75
76 #[inline]
77 pub fn rgb_color_model_hex_mut(&mut self) -> Option<&mut RgbColorModelHex> {
78 self.rgb_color_model_hex.as_deref_mut()
79 }
80
81 #[inline]
82 #[deprecated(since = "3.0.0", note = "Use rgb_color_model_hex_mut()")]
83 pub fn get_rgb_color_model_hex_mut(&mut self) -> Option<&mut RgbColorModelHex> {
84 self.rgb_color_model_hex_mut()
85 }
86
87 #[inline]
88 pub fn set_rgb_color_model_hex(&mut self, value: RgbColorModelHex) {
89 self.rgb_color_model_hex = Some(Box::new(value));
90 }
91
92 #[inline]
93 #[must_use]
94 pub fn system_color(&self) -> Option<&SystemColor> {
95 self.system_color.as_deref()
96 }
97
98 #[inline]
99 #[must_use]
100 #[deprecated(since = "3.0.0", note = "Use system_color()")]
101 pub fn get_system_color(&self) -> Option<&SystemColor> {
102 self.system_color()
103 }
104
105 #[inline]
106 pub fn system_color_mut(&mut self) -> Option<&mut SystemColor> {
107 self.system_color.as_deref_mut()
108 }
109
110 #[inline]
111 #[deprecated(since = "3.0.0", note = "Use system_color_mut()")]
112 pub fn get_system_color_mut(&mut self) -> Option<&mut SystemColor> {
113 self.system_color_mut()
114 }
115
116 #[inline]
117 pub fn set_system_color(&mut self, value: SystemColor) {
118 self.system_color = Some(Box::new(value));
119 }
120
121 pub(crate) fn set_attributes<R: std::io::BufRead>(
122 &mut self,
123 reader: &mut Reader<R>,
124 _e: &BytesStart,
125 ) {
126 xml_read_loop!(
127 reader,
128 Event::Start(ref e) => {
129 match e.name().into_inner() {
130 b"a:schemeClr" => {
131 let mut scheme_color = SchemeColor::default();
132 scheme_color.set_attributes(reader, e, false);
133 self.set_scheme_color(scheme_color);
134 }
135 b"a:srgbClr" => {
136 let mut rgb_color_model_hex = RgbColorModelHex::default();
137 rgb_color_model_hex.set_attributes(reader, e, false);
138 self.set_rgb_color_model_hex(rgb_color_model_hex);
139 }
140 b"a:sysClr" => {
141 let mut obj = SystemColor::default();
142 obj.set_attributes(reader, e, false);
143 self.set_system_color(obj);
144 }
145 _ => (),
146 }
147 },
148 Event::Empty(ref e) => {
149 match e.name().into_inner() {
150 b"a:schemeClr" => {
151 let mut scheme_color = SchemeColor::default();
152 scheme_color.set_attributes(reader, e, true);
153 self.set_scheme_color(scheme_color);
154 }
155 b"a:srgbClr" => {
156 let mut rgb_color_model_hex = RgbColorModelHex::default();
157 rgb_color_model_hex.set_attributes(reader, e, true);
158 self.set_rgb_color_model_hex(rgb_color_model_hex);
159 }
160 b"a:sysClr" => {
161 let mut obj = SystemColor::default();
162 obj.set_attributes(reader, e, true);
163 self.set_system_color(obj);
164 }
165 _ => (),
166 }
167 },
168 Event::End(ref e) => {
169 if e.name().into_inner() == b"a:solidFill" {
170 return;
171 }
172 },
173 Event::Eof => panic!("Error: Could not find {} end element", "a:solidFill")
174 );
175 }
176
177 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
178 write_start_tag(writer, "a:solidFill", vec![], false);
180 if let Some(color) = &self.scheme_color {
181 color.write_to(writer);
182 }
183
184 if let Some(hex) = &self.rgb_color_model_hex {
186 hex.write_to(writer);
187 }
188
189 if let Some(v) = &self.system_color {
191 v.write_to(writer);
192 }
193
194 write_end_tag(writer, "a:solidFill");
195 }
196}