umya_spreadsheet/structs/drawing/spreadsheet/
text_body.rs1use super::super::BodyProperties;
2use super::super::ListStyle;
3use super::super::Paragraph;
4use crate::reader::driver::*;
5use crate::writer::driver::*;
6use quick_xml::events::{BytesStart, Event};
7use quick_xml::Reader;
8use quick_xml::Writer;
9use std::io::Cursor;
10use thin_vec::ThinVec;
11
12#[derive(Clone, Default, Debug)]
13pub struct TextBody {
14 body_properties: BodyProperties,
15 list_style: ListStyle,
16 paragraph: ThinVec<Paragraph>,
17}
18
19impl TextBody {
20 #[inline]
21 pub fn get_body_properties(&self) -> &BodyProperties {
22 &self.body_properties
23 }
24
25 #[inline]
26 pub fn get_body_properties_mut(&mut self) -> &mut BodyProperties {
27 &mut self.body_properties
28 }
29
30 #[inline]
31 pub fn set_body_properties(&mut self, value: BodyProperties) {
32 self.body_properties = value;
33 }
34
35 #[inline]
36 pub fn get_list_style(&self) -> &ListStyle {
37 &self.list_style
38 }
39
40 #[inline]
41 pub fn get_list_style_mut(&mut self) -> &mut ListStyle {
42 &mut self.list_style
43 }
44
45 #[inline]
46 pub fn set_list_style(&mut self, value: ListStyle) {
47 self.list_style = value;
48 }
49
50 #[inline]
51 pub fn get_paragraph(&self) -> &[Paragraph] {
52 &self.paragraph
53 }
54
55 #[inline]
56 pub fn get_paragraph_mut(&mut self) -> &mut ThinVec<Paragraph> {
57 &mut self.paragraph
58 }
59
60 #[inline]
61 pub fn add_paragraph(&mut self, value: Paragraph) {
62 self.paragraph.push(value);
63 }
64
65 pub(crate) fn set_attributes<R: std::io::BufRead>(
66 &mut self,
67 reader: &mut Reader<R>,
68 _e: &BytesStart,
69 ) {
70 xml_read_loop!(
71 reader,
72 Event::Start(ref e) => {
73 match e.name().into_inner() {
74 b"a:p" => {
75 let mut paragraph = Paragraph::default();
76 paragraph.set_attributes(reader, e);
77 self.add_paragraph(paragraph);
78 }
79 b"a:bodyPr" => {
80 let mut body_properties = BodyProperties::default();
81 body_properties.set_attributes(reader, e, false);
82 self.set_body_properties(body_properties);
83 }
84 b"a:lstStyle" => {
85 let mut obj = ListStyle::default();
86 obj.set_attributes(reader, e);
87 self.set_list_style(obj);
88 }
89 _ => (),
90 }
91 },
92 Event::Empty(ref e) => {
93 if e.name().into_inner() == b"a:bodyPr" {
94 let mut body_properties = BodyProperties::default();
95 body_properties.set_attributes(reader, e, true);
96 self.set_body_properties(body_properties);
97 }
98 },
99 Event::End(ref e) => {
100 if e.name().into_inner() == b"xdr:txBody" {
101 return;
102 }
103 },
104 Event::Eof => panic!("Error: Could not find {} end element", "xdr:txBody")
105 );
106 }
107
108 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
109 write_start_tag(writer, "xdr:txBody", vec![], false);
111
112 self.body_properties.write_to(writer);
114
115 self.list_style.write_to(writer);
117
118 for content in &self.paragraph {
119 content.write_to(writer);
120 }
121
122 write_end_tag(writer, "xdr:txBody");
123 }
124}