1use crate::attrmap2::AttrMap2;
6use crate::style::units::RelativeScale;
7use crate::style::{GraphicStyleRef, ParagraphStyleRef};
8use crate::text::{TextP, TextTag};
9use crate::xlink::{XLinkActuate, XLinkShow, XLinkType};
10use crate::{CellRef, Length, OdsError};
11use base64::Engine;
12use chrono::NaiveDateTime;
13use get_size::GetSize;
14use get_size_derive::GetSize;
15
16#[derive(Debug, Clone)]
19pub struct Annotation {
20 name: String,
22 display: bool,
24 creator: Option<String>,
26 date: Option<NaiveDateTime>,
27 text: Vec<TextTag>,
28 attr: AttrMap2,
30}
31
32impl GetSize for Annotation {
33 fn get_heap_size(&self) -> usize {
34 self.name.get_heap_size()
35 + self.creator.get_heap_size()
36 + self.text.get_heap_size()
37 + self.attr.get_heap_size()
38 }
39}
40
41impl Annotation {
42 pub fn new_empty() -> Self {
44 Self {
45 name: Default::default(),
46 display: false,
47 creator: None,
48 date: None,
49 text: Default::default(),
50 attr: Default::default(),
51 }
52 }
53
54 pub fn new<S: Into<String>>(annotation: S) -> Self {
56 let mut r = Self {
57 name: Default::default(),
58 display: true,
59 creator: None,
60 date: None,
61 text: Default::default(),
62 attr: Default::default(),
63 };
64 r.push_text(TextP::new().text(annotation).into_xmltag());
65 r
66 }
67
68 pub fn attrmap(&self) -> &AttrMap2 {
70 &self.attr
71 }
72
73 pub fn attrmap_mut(&mut self) -> &mut AttrMap2 {
75 &mut self.attr
76 }
77
78 pub fn name(&self) -> &str {
80 &self.name
81 }
82
83 pub fn set_name<S: Into<String>>(&mut self, name: S) {
85 self.name = name.into();
86 }
87
88 pub fn display(&self) -> bool {
90 self.display
91 }
92
93 pub fn set_display(&mut self, display: bool) {
95 self.display = display;
96 }
97
98 pub fn creator(&self) -> Option<&String> {
100 self.creator.as_ref()
101 }
102
103 pub fn set_creator<S: Into<String>>(&mut self, creator: Option<S>) {
105 self.creator = creator.map(|v| v.into())
106 }
107
108 pub fn date(&self) -> Option<&NaiveDateTime> {
110 self.date.as_ref()
111 }
112
113 pub fn set_date(&mut self, date: Option<NaiveDateTime>) {
115 self.date = date;
116 }
117
118 pub fn text(&self) -> &Vec<TextTag> {
120 &self.text
121 }
122
123 pub fn push_text(&mut self, text: TextTag) {
125 self.text.push(text);
126 }
127
128 pub fn push_text_str<S: Into<String>>(&mut self, text: S) {
130 self.text.push(TextP::new().text(text).into_xmltag());
131 }
132
133 pub fn set_text(&mut self, text: Vec<TextTag>) {
135 self.text = text;
136 }
137
138 draw_caption_point_x!(attr);
139 draw_caption_point_y!(attr);
140 draw_class_names!(attr);
141 draw_corner_radius!(attr);
142 draw_id!(attr);
143 draw_layer!(attr);
144 draw_style_name!(attr);
145 draw_text_style_name!(attr);
146 draw_transform!(attr);
147 draw_z_index!(attr);
148 svg_height!(attr);
149 svg_width!(attr);
150 svg_x!(attr);
151 svg_y!(attr);
152 table_end_cell_address!(attr);
153 table_end_x!(attr);
154 table_end_y!(attr);
155 table_table_background!(attr);
156 xml_id!(attr);
157}
158
159#[derive(Debug, Clone, Default, GetSize)]
229pub struct DrawFrame {
230 title: Option<String>,
232 desc: Option<String>,
235 attr: AttrMap2,
237 content: Vec<DrawFrameContent>,
239}
240
241#[derive(Debug, Clone, GetSize)]
243pub enum DrawFrameContent {
244 Image(DrawImage),
246}
247
248impl DrawFrame {
249 pub fn new() -> Self {
251 Default::default()
252 }
253
254 pub fn attrmap(&self) -> &AttrMap2 {
256 &self.attr
257 }
258
259 pub fn attrmap_mut(&mut self) -> &mut AttrMap2 {
261 &mut self.attr
262 }
263
264 pub fn desc(&self) -> Option<&String> {
266 self.desc.as_ref()
267 }
268
269 pub fn set_desc<S: Into<String>>(&mut self, desc: S) {
271 self.desc = Some(desc.into())
272 }
273
274 pub fn clear_desc(&mut self) {
276 self.desc = None;
277 }
278
279 pub fn title(&self) -> Option<&String> {
281 self.title.as_ref()
282 }
283
284 pub fn set_title<S: Into<String>>(&mut self, title: S) {
286 self.title = Some(title.into());
287 }
288
289 pub fn clear_title(&mut self) {
291 self.title = None;
292 }
293
294 pub fn set_content(&mut self, content: Vec<DrawFrameContent>) {
296 self.content = content;
297 }
298
299 pub fn push_content(&mut self, content: DrawFrameContent) {
301 self.content.push(content);
302 }
303
304 pub fn clear_content(&mut self) {
306 self.content.clear();
307 }
308
309 pub fn content_ref(&self) -> &Vec<DrawFrameContent> {
311 &self.content
312 }
313
314 pub fn content_mut(&mut self) -> &mut Vec<DrawFrameContent> {
316 &mut self.content
317 }
318
319 draw_name!(attr);
320 draw_caption_id!(attr);
321 draw_class_names!(attr);
322 draw_corner_radius!(attr);
323 draw_copy_of!(attr);
324 draw_id!(attr);
325 draw_layer!(attr);
326 draw_style_name!(attr);
327 draw_text_style_name!(attr);
328 draw_transform!(attr);
329 draw_z_index!(attr);
330 style_rel_height!(attr);
331 style_rel_width!(attr);
332 svg_height!(attr);
333 svg_width!(attr);
334 svg_x!(attr);
335 svg_y!(attr);
336 table_end_cell_address!(attr);
337 table_end_x!(attr);
338 table_end_y!(attr);
339 table_table_background!(attr);
340 xml_id!(attr);
341}
342
343#[derive(Debug, Clone, Default, GetSize)]
352pub struct DrawImage {
353 attr: AttrMap2,
354 binary_data: Option<String>,
355 text: Vec<TextTag>,
356}
357
358impl DrawImage {
359 pub fn new() -> Self {
361 Default::default()
362 }
363
364 pub fn attrmap(&self) -> &AttrMap2 {
366 &self.attr
367 }
368
369 pub fn attrmap_mut(&mut self) -> &mut AttrMap2 {
371 &mut self.attr
372 }
373
374 pub fn get_binary_base64(&self) -> Option<&String> {
376 self.binary_data.as_ref()
377 }
378
379 pub fn set_binary_base64(&mut self, binary: String) {
381 self.binary_data = Some(binary);
382 }
383
384 pub fn get_binary(&self) -> Result<Vec<u8>, OdsError> {
386 let ng = base64::engine::GeneralPurpose::new(
387 &base64::alphabet::STANDARD,
388 base64::engine::general_purpose::NO_PAD,
389 );
390
391 if let Some(binary_data) = &self.binary_data {
392 Ok(ng.decode(binary_data)?)
393 } else {
394 Ok(Default::default())
395 }
396 }
397
398 pub fn set_binary(&mut self, binary: &[u8]) {
402 let ng = base64::engine::GeneralPurpose::new(
403 &base64::alphabet::STANDARD,
404 base64::engine::general_purpose::NO_PAD,
405 );
406
407 self.binary_data = Some(ng.encode(binary));
408 }
409
410 pub fn clear_binary(&mut self) {
412 self.binary_data = None;
413 }
414
415 pub fn get_text(&self) -> &Vec<TextTag> {
417 &self.text
418 }
419
420 pub fn push_text(&mut self, text: TextTag) {
422 self.text.push(text);
423 }
424
425 pub fn push_text_str<S: Into<String>>(&mut self, text: S) {
427 self.text.push(TextP::new().text(text).into_xmltag());
428 }
429
430 pub fn set_text(&mut self, text: Vec<TextTag>) {
432 self.text = text;
433 }
434
435 draw_filter_name!(attr);
436 draw_mime_type!(attr);
437 xlink_actuate!(attr);
438 xlink_href!(attr);
439 xlink_show!(attr);
440 xlink_type!(attr);
441 xml_id!(attr);
442}