umya_spreadsheet/structs/drawing/
tail_end.rs1use std::io::Cursor;
3
4use quick_xml::{
5 Reader,
6 Writer,
7 events::{
8 BytesStart,
9 Event,
10 },
11};
12
13use crate::{
14 reader::driver::{
15 get_attribute,
16 xml_read_loop,
17 },
18 structs::StringValue,
19 writer::driver::write_start_tag,
20};
21
22#[derive(Clone, Default, Debug)]
23pub struct TailEnd {
24 t_type: StringValue,
25 width: StringValue,
26 length: StringValue,
27}
28
29impl TailEnd {
30 #[inline]
31 #[must_use]
32 pub fn get_type(&self) -> &str {
33 self.t_type.value_str()
34 }
35
36 #[inline]
37 pub fn set_type<S: Into<String>>(&mut self, value: S) -> &mut Self {
38 self.t_type.set_value(value.into());
39 self
40 }
41
42 #[inline]
43 #[must_use]
44 pub fn width(&self) -> &str {
45 self.width.value_str()
46 }
47
48 #[inline]
49 #[must_use]
50 #[deprecated(since = "3.0.0", note = "Use width()")]
51 pub fn get_width(&self) -> &str {
52 self.width()
53 }
54
55 #[inline]
56 pub fn set_width<S: Into<String>>(&mut self, value: S) -> &mut Self {
57 self.width.set_value(value.into());
58 self
59 }
60
61 #[inline]
62 #[must_use]
63 pub fn length(&self) -> &str {
64 self.length.value_str()
65 }
66
67 #[inline]
68 #[must_use]
69 #[deprecated(since = "3.0.0", note = "Use length()")]
70 pub fn get_length(&self) -> &str {
71 self.length()
72 }
73
74 #[inline]
75 pub fn set_length<S: Into<String>>(&mut self, value: S) -> &mut Self {
76 self.length.set_value(value.into());
77 self
78 }
79
80 pub(crate) fn set_attributes<R: std::io::BufRead>(
81 &mut self,
82 reader: &mut Reader<R>,
83 e: &BytesStart,
84 empty_flag: bool,
85 ) {
86 if let Some(v) = get_attribute(e, b"type") {
87 self.set_type(v);
88 }
89
90 if let Some(v) = get_attribute(e, b"w") {
91 self.set_width(v);
92 }
93
94 if let Some(v) = get_attribute(e, b"len") {
95 self.set_length(v);
96 }
97
98 if empty_flag {
99 return;
100 }
101
102 xml_read_loop!(
103 reader,
104 Event::End(ref e) => {
105 if e.name().into_inner() == b"a:tailEnd" {
106 return;
107 }
108 },
109 Event::Eof => panic!("Error: Could not find {} end element", "a:tailEnd")
110 );
111 }
112
113 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
114 let mut attributes: crate::structs::AttrCollection = Vec::new();
116 if self.t_type.has_value() {
117 attributes.push(("type", (self.t_type.value_str())).into());
118 }
119 if self.width.has_value() {
120 attributes.push(("w", (self.width.value_str())).into());
121 }
122 if self.length.has_value() {
123 attributes.push(("len", (self.length.value_str())).into());
124 }
125 write_start_tag(writer, "a:tailEnd", attributes, true);
126 }
127}