umya_spreadsheet/structs/drawing/
camera.rs1use std::io::Cursor;
3
4use quick_xml::{
5 Reader,
6 Writer,
7 events::{
8 BytesStart,
9 Event,
10 },
11};
12
13use super::{
14 super::EnumValue,
15 PresetCameraValues,
16 Rotation,
17};
18use crate::{
19 reader::driver::{
20 get_attribute,
21 set_string_from_xml,
22 xml_read_loop,
23 },
24 writer::driver::{
25 write_end_tag,
26 write_start_tag,
27 },
28};
29
30#[derive(Clone, Default, Debug)]
31pub struct Camera {
32 preset: EnumValue<PresetCameraValues>,
33 rotation: Option<Box<Rotation>>,
34}
35
36impl Camera {
37 #[inline]
38 #[must_use]
39 pub fn preset(&self) -> &PresetCameraValues {
40 self.preset.value()
41 }
42
43 #[inline]
44 #[must_use]
45 #[deprecated(since = "3.0.0", note = "Use preset()")]
46 pub fn get_preset(&self) -> &PresetCameraValues {
47 self.preset()
48 }
49
50 #[inline]
51 pub fn set_preset(&mut self, value: PresetCameraValues) -> &mut Self {
52 self.preset.set_value(value);
53 self
54 }
55
56 #[inline]
57 #[must_use]
58 pub fn rotation(&self) -> Option<&Rotation> {
59 self.rotation.as_deref()
60 }
61
62 #[inline]
63 #[must_use]
64 #[deprecated(since = "3.0.0", note = "Use rotation()")]
65 pub fn get_rotation(&self) -> Option<&Rotation> {
66 self.rotation()
67 }
68
69 #[inline]
70 pub fn rotation_mut(&mut self) -> Option<&mut Rotation> {
71 self.rotation.as_deref_mut()
72 }
73
74 #[inline]
75 #[deprecated(since = "3.0.0", note = "Use rotation_mut()")]
76 pub fn get_rotation_mut(&mut self) -> Option<&mut Rotation> {
77 self.rotation_mut()
78 }
79
80 #[inline]
81 pub fn set_rotation(&mut self, value: Rotation) -> &mut Self {
82 self.rotation = Some(Box::new(value));
83 self
84 }
85
86 pub(crate) fn set_attributes<R: std::io::BufRead>(
87 &mut self,
88 reader: &mut Reader<R>,
89 e: &BytesStart,
90 empty_flag: bool,
91 ) {
92 set_string_from_xml!(self, e, preset, "prst");
93
94 if empty_flag {
95 return;
96 }
97
98 xml_read_loop!(
99 reader,
100 Event::Empty(ref e) => {
101 if e.name().into_inner() == b"a:rot" {
102 let mut obj = Rotation::default();
103 obj.set_attributes(reader, e);
104 self.rotation = Some(Box::new(obj));
105 }
106 },
107 Event::End(ref e) => {
108 if e.name().into_inner() == b"a:camera" {
109 return
110 }
111 },
112 Event::Eof => panic!("Error: Could not find {} end element", "a:camera")
113 );
114 }
115
116 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
117 let with_inner = self.rotation.is_some();
118 write_start_tag(
120 writer,
121 "a:camera",
122 vec![("prst", self.preset.value_string()).into()],
123 !with_inner,
124 );
125
126 if with_inner {
127 if let Some(v) = &self.rotation {
129 v.write_to(writer);
130 }
131 write_end_tag(writer, "a:camera");
132 }
133 }
134}