docx_reader/documents/elements/
drawing.rs1use super::*;
2use serde::{ser::*, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Default, Serialize)]
5pub struct Drawing {
6 #[serde(flatten)]
7 pub data: Option<DrawingData>,
8}
9
10#[derive(Debug, Clone, PartialEq)]
11pub enum DrawingData {
12 Pic(Pic),
13 TextBox(TextBox),
14}
15
16impl Serialize for DrawingData {
17 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
18 where
19 S: Serializer,
20 {
21 match *self {
22 DrawingData::Pic(ref pic) => {
23 let mut t = serializer.serialize_struct("Pic", 2)?;
24 t.serialize_field("type", "pic")?;
25 t.serialize_field("data", pic)?;
26 t.end()
27 }
28 DrawingData::TextBox(ref text_box) => {
29 let mut t = serializer.serialize_struct("TextBox", 2)?;
30 t.serialize_field("type", "textBox")?;
31 t.serialize_field("data", text_box)?;
32 t.end()
33 }
34 }
35 }
36}
37
38impl Drawing {
39 pub fn new() -> Drawing {
40 Default::default()
41 }
42
43 pub fn pic(mut self, pic: Pic) -> Drawing {
44 self.data = Some(DrawingData::Pic(pic));
45 self
46 }
47
48 pub fn text_box(mut self, t: TextBox) -> Drawing {
49 self.data = Some(DrawingData::TextBox(t));
50 self
51 }
52}