1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#![allow(unused_must_use)]
use strong_xml::{XmlRead, XmlWrite};

use crate::{
    __setter, __xml_test_suites,
    formatting::{CharacterProperty, ParagraphProperty},
};

/// Default Style
///
/// This style is inherited by every paragraph and run.
///
/// ```rust
/// use docx_rust::formatting::*;
/// use docx_rust::styles::*;
///
/// let style = DefaultStyle::default()
///     .character(CharacterProperty::default())
///     .paragraph(ParagraphProperty::default());
/// ```
#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:docDefaults")]
pub struct DefaultStyle<'a> {
    #[xml(default, child = "w:rPrDefault")]
    pub character: DefaultCharacterProperty<'a>,
    #[xml(default, child = "w:pPrDefault")]
    pub paragraph: DefaultParagraphProperty<'a>,
}

impl<'a> DefaultStyle<'a> {
    __setter!(character: DefaultCharacterProperty<'a>);
    __setter!(paragraph: DefaultParagraphProperty<'a>);
}

/// Default Character Properties
#[derive(Default, Debug, XmlRead, XmlWrite, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:rPrDefault")]
pub struct DefaultCharacterProperty<'a> {
    /// character properties
    #[xml(default, child = "w:rPr")]
    pub inner: Option<CharacterProperty<'a>>,
}

impl<'a, T: Into<CharacterProperty<'a>>> From<T> for DefaultCharacterProperty<'a> {
    fn from(val: T) -> Self {
        DefaultCharacterProperty {
            inner: Some(val.into()),
        }
    }
}

/// Default Paragraph Properties
#[derive(Default, Debug, XmlRead, XmlWrite, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:pPrDefault")]
pub struct DefaultParagraphProperty<'a> {
    /// paragraph properties
    #[xml(default, child = "w:pPr")]
    pub inner: Option<ParagraphProperty<'a>>,
}

impl<'a, T: Into<ParagraphProperty<'a>>> From<T> for DefaultParagraphProperty<'a> {
    fn from(val: T) -> Self {
        DefaultParagraphProperty {
            inner: Some(val.into()),
        }
    }
}

__xml_test_suites!(
    DefaultStyle,
    DefaultStyle::default(),
    r#"<w:docDefaults><w:rPrDefault/><w:pPrDefault/></w:docDefaults>"#,
);