umya_spreadsheet/structs/vml/
fill.rs1use crate::reader::driver::*;
2use crate::structs::raw::RawRelationships;
3use crate::structs::MediaObject;
4use crate::structs::StringValue;
5use crate::structs::TrueFalseValue;
6use crate::writer::driver::*;
7use quick_xml::events::BytesStart;
8use quick_xml::Reader;
9use quick_xml::Writer;
10use std::io::Cursor;
11
12#[derive(Clone, Default, Debug)]
13pub struct Fill {
14 color: StringValue,
15 color_2: StringValue,
16 on: TrueFalseValue,
17 focus_size: StringValue,
18 image: Option<MediaObject>,
19}
20
21impl Fill {
22 #[inline]
23 pub fn get_color(&self) -> &str {
24 self.color.get_value_str()
25 }
26
27 #[inline]
28 pub fn set_color<S: Into<String>>(&mut self, value: S) -> &mut Self {
29 self.color.set_value(value);
30 self
31 }
32
33 #[inline]
34 pub fn get_color_2(&self) -> &str {
35 self.color_2.get_value_str()
36 }
37
38 #[inline]
39 pub fn set_color_2<S: Into<String>>(&mut self, value: S) -> &mut Self {
40 self.color_2.set_value(value);
41 self
42 }
43
44 #[inline]
45 pub fn get_on(&self) -> &bool {
46 self.on.get_value()
47 }
48
49 #[inline]
50 pub fn set_on(&mut self, value: bool) -> &mut Self {
51 self.on.set_value(value);
52 self
53 }
54
55 #[inline]
56 pub fn get_focus_size(&self) -> &str {
57 self.focus_size.get_value_str()
58 }
59
60 #[inline]
61 pub fn set_focus_size<S: Into<String>>(&mut self, value: S) -> &mut Self {
62 self.focus_size.set_value(value);
63 self
64 }
65
66 #[inline]
67 pub fn get_image(&self) -> Option<&MediaObject> {
68 self.image.as_ref()
69 }
70
71 #[inline]
72 pub fn get_image_mut(&mut self) -> Option<&mut MediaObject> {
73 self.image.as_mut()
74 }
75
76 #[inline]
77 pub fn set_image(&mut self, value: MediaObject) -> &mut Self {
78 self.image = Some(value);
79 self
80 }
81
82 #[inline]
83 pub(crate) fn set_attributes<R: std::io::BufRead>(
84 &mut self,
85 _reader: &mut Reader<R>,
86 e: &BytesStart,
87 drawing_relationships: Option<&RawRelationships>,
88 ) {
89 set_string_from_xml!(self, e, color, "color");
90 set_string_from_xml!(self, e, color_2, "color2");
91 set_string_from_xml!(self, e, on, "on");
92 set_string_from_xml!(self, e, focus_size, "focussize");
93
94 if let Some(relid) = get_attribute(e, b"o:relid") {
95 if let Some(rel) = drawing_relationships {
96 let relationship = rel.get_relationship_by_rid(&relid);
97 let mut obj = MediaObject::default();
98 obj.set_image_title(get_attribute(e, b"o:title").unwrap());
99 obj.set_image_name(relationship.get_raw_file().get_file_name());
100 obj.set_image_data(relationship.get_raw_file().get_file_data());
101 self.set_image(obj);
102 }
103 }
104 }
105
106 #[inline]
107 pub(crate) fn write_to(
108 &self,
109 writer: &mut Writer<Cursor<Vec<u8>>>,
110 rel_list: &mut Vec<(String, String)>,
111 ) {
112 let mut attributes: Vec<(&str, &str)> = Vec::new();
114 if self.color.has_value() {
115 attributes.push(("color", self.color.get_value_str()));
116 }
117 if self.color_2.has_value() {
118 attributes.push(("color2", self.color_2.get_value_str()));
119 }
120 if self.on.has_value() {
121 attributes.push(("on", self.on.get_value_string()));
122 }
123 if self.focus_size.has_value() {
124 attributes.push(("focussize", self.focus_size.get_value_str()));
125 }
126 let mut r_id_str = String::new();
127 if let Some(image) = &self.image {
128 let r_id = image.get_rid(rel_list);
129 r_id_str = format!("rId{}", r_id);
130 attributes.push(("o:title", image.get_image_title()));
131 attributes.push(("o:relid", &r_id_str));
132 attributes.push(("recolor", "t"));
133 attributes.push(("rotate", "t"));
134 attributes.push(("type", "frame"));
135 }
136 write_start_tag(writer, "v:fill", attributes, true);
137 }
138}