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