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