umya_spreadsheet/structs/drawing/charts/
string_literal.rs1use super::StringPoint;
3use crate::reader::driver::*;
4use crate::writer::driver::*;
5use quick_xml::events::{BytesStart, Event};
6use quick_xml::Reader;
7use quick_xml::Writer;
8use std::io::Cursor;
9use thin_vec::ThinVec;
10
11#[derive(Clone, Default, Debug)]
12pub struct StringLiteral {
13 string_point_list: ThinVec<StringPoint>,
14}
15
16impl StringLiteral {
17 pub fn get_string_point_list(&self) -> &[StringPoint] {
18 &self.string_point_list
19 }
20
21 pub fn get_string_point_list_mut(&mut self) -> &mut ThinVec<StringPoint> {
22 &mut self.string_point_list
23 }
24
25 pub fn add_string_point_list(&mut self, value: StringPoint) -> &mut Self {
26 self.string_point_list.push(value);
27 self
28 }
29
30 pub(crate) fn set_attributes<R: std::io::BufRead>(
31 &mut self,
32 reader: &mut Reader<R>,
33 _e: &BytesStart,
34 ) {
35 xml_read_loop!(
36 reader,
37 Event::Start(ref e) => {
38 if e.name().0 == b"c:pt" {
39 let mut obj = StringPoint::default();
40 obj.set_attributes(reader, e);
41 self.add_string_point_list(obj);
42 }
43 },
44 Event::End(ref e) => {
45 if e.name().0 == b"c:strLit" {
46 return;
47 }
48 },
49 Event::Eof => panic!("Error: Could not find {} end element", "c:strLit")
50 );
51 }
52
53 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
54 write_start_tag(writer, "c:strLit", vec![], false);
56
57 let count = self.string_point_list.len().to_string();
59 write_start_tag(writer, "c:ptCount", vec![("val", &count)], true);
60
61 for (index, obj) in self.string_point_list.iter().enumerate() {
63 obj.write_to(writer, &(index as u32));
64 }
65
66 write_end_tag(writer, "c:strLit");
67 }
68}