umya_spreadsheet/structs/drawing/
graphic.rs

1// a:graphic
2use super::GraphicData;
3use crate::reader::driver::*;
4use crate::structs::raw::RawRelationships;
5use crate::traits::AdjustmentCoordinateWithSheet;
6use crate::writer::driver::*;
7use quick_xml::events::{BytesStart, Event};
8use quick_xml::Reader;
9use quick_xml::Writer;
10use std::io::Cursor;
11
12#[derive(Clone, Default, Debug)]
13pub struct Graphic {
14    graphic_data: GraphicData,
15}
16
17impl Graphic {
18    #[inline]
19    pub fn get_graphic_data(&self) -> &GraphicData {
20        &self.graphic_data
21    }
22
23    #[inline]
24    pub fn get_graphic_data_mut(&mut self) -> &mut GraphicData {
25        &mut self.graphic_data
26    }
27
28    #[inline]
29    pub fn set_graphic_data(&mut self, value: GraphicData) -> &mut Self {
30        self.graphic_data = value;
31        self
32    }
33
34    pub(crate) fn set_attributes<R: std::io::BufRead>(
35        &mut self,
36        reader: &mut Reader<R>,
37        _e: &BytesStart,
38        drawing_relationships: Option<&RawRelationships>,
39    ) {
40        xml_read_loop!(
41            reader,
42            Event::Start(ref e) => {
43                if e.name().into_inner() == b"a:graphicData" {
44                    self.graphic_data
45                        .set_attributes(reader, e, drawing_relationships);
46                }
47            },
48            Event::End(ref e) => {
49                if e.name().into_inner() == b"a:graphic" {
50                    return
51                }
52            },
53            Event::Eof => panic!("Error: Could not find {} end element", "a:graphic")
54        );
55    }
56
57    pub(crate) fn write_to(
58        &self,
59        writer: &mut Writer<Cursor<Vec<u8>>>,
60        rel_list: &mut Vec<(String, String)>,
61    ) {
62        // a:graphic
63        write_start_tag(writer, "a:graphic", vec![], false);
64
65        // a:graphicData
66        self.graphic_data.write_to(writer, rel_list);
67
68        write_end_tag(writer, "a:graphic");
69    }
70}
71impl AdjustmentCoordinateWithSheet for Graphic {
72    #[inline]
73    fn adjustment_insert_coordinate_with_sheet(
74        &mut self,
75        sheet_name: &str,
76        root_col_num: &u32,
77        offset_col_num: &u32,
78        root_row_num: &u32,
79        offset_row_num: &u32,
80    ) {
81        self.graphic_data.adjustment_insert_coordinate_with_sheet(
82            sheet_name,
83            root_col_num,
84            offset_col_num,
85            root_row_num,
86            offset_row_num,
87        );
88    }
89
90    #[inline]
91    fn adjustment_remove_coordinate_with_sheet(
92        &mut self,
93        sheet_name: &str,
94        root_col_num: &u32,
95        offset_col_num: &u32,
96        root_row_num: &u32,
97        offset_row_num: &u32,
98    ) {
99        self.graphic_data.adjustment_remove_coordinate_with_sheet(
100            sheet_name,
101            root_col_num,
102            offset_col_num,
103            root_row_num,
104            offset_row_num,
105        );
106    }
107}