Skip to main content

umya_spreadsheet/structs/drawing/
graphic.rs

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