Skip to main content

umya_spreadsheet/structs/drawing/
picture_locks.rs

1// a:picLocks
2use std::io::Cursor;
3
4use quick_xml::{
5    Reader,
6    Writer,
7    events::BytesStart,
8};
9
10use crate::{
11    reader::driver::get_attribute,
12    writer::driver::write_start_tag,
13};
14
15#[derive(Clone, Default, Debug)]
16pub struct PictureLocks {
17    no_change_aspect: bool,
18}
19
20impl PictureLocks {
21    #[inline]
22    #[must_use]
23    pub fn no_change_aspect(&self) -> bool {
24        self.no_change_aspect
25    }
26
27    #[inline]
28    #[must_use]
29    #[deprecated(since = "3.0.0", note = "Use no_change_aspect()")]
30    pub fn get_no_change_aspect(&self) -> bool {
31        self.no_change_aspect()
32    }
33
34    #[inline]
35    pub fn set_no_change_aspect(&mut self, value: bool) -> &mut Self {
36        self.no_change_aspect = value;
37        self
38    }
39
40    #[inline]
41    pub(crate) fn set_attributes<R: std::io::BufRead>(
42        &mut self,
43        _reader: &mut Reader<R>,
44        e: &BytesStart,
45    ) {
46        if let Some(v) = get_attribute(e, b"noChangeAspect") {
47            if v == "1" {
48                self.set_no_change_aspect(true);
49            }
50        }
51    }
52
53    #[inline]
54    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
55        // a:picLocks
56        let no_change_aspect = if self.no_change_aspect { "1" } else { "2" };
57        write_start_tag(
58            writer,
59            "a:picLocks",
60            vec![("noChangeAspect", no_change_aspect).into()],
61            true,
62        );
63    }
64}