use crate::attrmap2::AttrMap2;
use crate::style::units::RelativeScale;
use crate::style::{GraphicStyleRef, ParagraphStyleRef};
use crate::text::{TextP, TextTag};
use crate::xlink::{XLinkActuate, XLinkShow, XLinkType};
use crate::{CellRef, Length, OdsError};
use base64::Engine;
use chrono::NaiveDateTime;
use get_size2::GetSize;
#[derive(Debug, Clone)]
pub struct Annotation {
name: String,
display: bool,
creator: Option<String>,
date: Option<NaiveDateTime>,
text: Vec<TextTag>,
attr: AttrMap2,
}
impl GetSize for Annotation {
fn get_heap_size(&self) -> usize {
self.name.get_heap_size()
+ self.creator.get_heap_size()
+ self.text.get_heap_size()
+ self.attr.get_heap_size()
}
}
impl Annotation {
pub fn new_empty() -> Self {
Self {
name: Default::default(),
display: false,
creator: None,
date: None,
text: Default::default(),
attr: Default::default(),
}
}
pub fn new<S: Into<String>>(annotation: S) -> Self {
let mut r = Self {
name: Default::default(),
display: true,
creator: None,
date: None,
text: Default::default(),
attr: Default::default(),
};
r.push_text(TextP::new().text(annotation).into_xmltag());
r
}
pub fn attrmap(&self) -> &AttrMap2 {
&self.attr
}
pub fn attrmap_mut(&mut self) -> &mut AttrMap2 {
&mut self.attr
}
pub fn name(&self) -> &str {
&self.name
}
pub fn set_name<S: Into<String>>(&mut self, name: S) {
self.name = name.into();
}
pub fn display(&self) -> bool {
self.display
}
pub fn set_display(&mut self, display: bool) {
self.display = display;
}
pub fn creator(&self) -> Option<&String> {
self.creator.as_ref()
}
pub fn set_creator<S: Into<String>>(&mut self, creator: Option<S>) {
self.creator = creator.map(|v| v.into())
}
pub fn date(&self) -> Option<&NaiveDateTime> {
self.date.as_ref()
}
pub fn set_date(&mut self, date: Option<NaiveDateTime>) {
self.date = date;
}
pub fn text(&self) -> &Vec<TextTag> {
&self.text
}
pub fn push_text(&mut self, text: TextTag) {
self.text.push(text);
}
pub fn push_text_str<S: Into<String>>(&mut self, text: S) {
self.text.push(TextP::new().text(text).into_xmltag());
}
pub fn set_text(&mut self, text: Vec<TextTag>) {
self.text = text;
}
draw_caption_point_x!(attr);
draw_caption_point_y!(attr);
draw_class_names!(attr);
draw_corner_radius!(attr);
draw_id!(attr);
draw_layer!(attr);
draw_style_name!(attr);
draw_text_style_name!(attr);
draw_transform!(attr);
draw_z_index!(attr);
svg_height!(attr);
svg_width!(attr);
svg_x!(attr);
svg_y!(attr);
table_end_cell_address!(attr);
table_end_x!(attr);
table_end_y!(attr);
table_table_background!(attr);
xml_id!(attr);
}
#[derive(Debug, Clone, Default, GetSize)]
pub struct DrawFrame {
title: Option<String>,
desc: Option<String>,
attr: AttrMap2,
content: Vec<DrawFrameContent>,
}
#[derive(Debug, Clone, GetSize)]
pub enum DrawFrameContent {
Image(DrawImage),
}
impl DrawFrame {
pub fn new() -> Self {
Default::default()
}
pub fn attrmap(&self) -> &AttrMap2 {
&self.attr
}
pub fn attrmap_mut(&mut self) -> &mut AttrMap2 {
&mut self.attr
}
pub fn desc(&self) -> Option<&String> {
self.desc.as_ref()
}
pub fn set_desc<S: Into<String>>(&mut self, desc: S) {
self.desc = Some(desc.into())
}
pub fn clear_desc(&mut self) {
self.desc = None;
}
pub fn title(&self) -> Option<&String> {
self.title.as_ref()
}
pub fn set_title<S: Into<String>>(&mut self, title: S) {
self.title = Some(title.into());
}
pub fn clear_title(&mut self) {
self.title = None;
}
pub fn set_content(&mut self, content: Vec<DrawFrameContent>) {
self.content = content;
}
pub fn push_content(&mut self, content: DrawFrameContent) {
self.content.push(content);
}
pub fn clear_content(&mut self) {
self.content.clear();
}
pub fn content_ref(&self) -> &Vec<DrawFrameContent> {
&self.content
}
pub fn content_mut(&mut self) -> &mut Vec<DrawFrameContent> {
&mut self.content
}
draw_name!(attr);
draw_caption_id!(attr);
draw_class_names!(attr);
draw_corner_radius!(attr);
draw_copy_of!(attr);
draw_id!(attr);
draw_layer!(attr);
draw_style_name!(attr);
draw_text_style_name!(attr);
draw_transform!(attr);
draw_z_index!(attr);
style_rel_height!(attr);
style_rel_width!(attr);
svg_height!(attr);
svg_width!(attr);
svg_x!(attr);
svg_y!(attr);
table_end_cell_address!(attr);
table_end_x!(attr);
table_end_y!(attr);
table_table_background!(attr);
xml_id!(attr);
}
#[derive(Debug, Clone, Default, GetSize)]
pub struct DrawImage {
attr: AttrMap2,
binary_data: Option<String>,
text: Vec<TextTag>,
}
impl DrawImage {
pub fn new() -> Self {
Default::default()
}
pub fn attrmap(&self) -> &AttrMap2 {
&self.attr
}
pub fn attrmap_mut(&mut self) -> &mut AttrMap2 {
&mut self.attr
}
pub fn get_binary_base64(&self) -> Option<&String> {
self.binary_data.as_ref()
}
pub fn set_binary_base64(&mut self, binary: String) {
self.binary_data = Some(binary);
}
pub fn get_binary(&self) -> Result<Vec<u8>, OdsError> {
let ng = base64::engine::GeneralPurpose::new(
&base64::alphabet::STANDARD,
base64::engine::general_purpose::NO_PAD,
);
if let Some(binary_data) = &self.binary_data {
Ok(ng.decode(binary_data)?)
} else {
Ok(Default::default())
}
}
pub fn set_binary(&mut self, binary: &[u8]) {
let ng = base64::engine::GeneralPurpose::new(
&base64::alphabet::STANDARD,
base64::engine::general_purpose::NO_PAD,
);
self.binary_data = Some(ng.encode(binary));
}
pub fn clear_binary(&mut self) {
self.binary_data = None;
}
pub fn get_text(&self) -> &Vec<TextTag> {
&self.text
}
pub fn push_text(&mut self, text: TextTag) {
self.text.push(text);
}
pub fn push_text_str<S: Into<String>>(&mut self, text: S) {
self.text.push(TextP::new().text(text).into_xmltag());
}
pub fn set_text(&mut self, text: Vec<TextTag>) {
self.text = text;
}
draw_filter_name!(attr);
draw_mime_type!(attr);
xlink_actuate!(attr);
xlink_href!(attr);
xlink_show!(attr);
xlink_type!(attr);
xml_id!(attr);
}