docx_rust/styles/
default_style.rs

1#![allow(unused_must_use)]
2use hard_xml::{XmlRead, XmlWrite};
3
4use crate::{
5    __setter, __xml_test_suites,
6    formatting::{CharacterProperty, ParagraphProperty},
7};
8
9/// Default Style
10///
11/// This style is inherited by every paragraph and run.
12///
13/// ```rust
14/// use docx_rust::formatting::*;
15/// use docx_rust::styles::*;
16///
17/// let style = DefaultStyle::default()
18///     .character(CharacterProperty::default())
19///     .paragraph(ParagraphProperty::default());
20/// ```
21#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
22#[cfg_attr(test, derive(PartialEq))]
23#[xml(tag = "w:docDefaults")]
24pub struct DefaultStyle<'a> {
25    #[xml(default, child = "w:rPrDefault")]
26    pub character: DefaultCharacterProperty<'a>,
27    #[xml(default, child = "w:pPrDefault")]
28    pub paragraph: DefaultParagraphProperty<'a>,
29}
30
31impl<'a> DefaultStyle<'a> {
32    __setter!(character: DefaultCharacterProperty<'a>);
33    __setter!(paragraph: DefaultParagraphProperty<'a>);
34}
35
36/// Default Character Properties
37#[derive(Default, Debug, XmlRead, XmlWrite, Clone)]
38#[cfg_attr(test, derive(PartialEq))]
39#[xml(tag = "w:rPrDefault")]
40pub struct DefaultCharacterProperty<'a> {
41    /// character properties
42    #[xml(default, child = "w:rPr")]
43    pub inner: Option<CharacterProperty<'a>>,
44}
45
46impl<'a, T: Into<CharacterProperty<'a>>> From<T> for DefaultCharacterProperty<'a> {
47    fn from(val: T) -> Self {
48        DefaultCharacterProperty {
49            inner: Some(val.into()),
50        }
51    }
52}
53
54/// Default Paragraph Properties
55#[derive(Default, Debug, XmlRead, XmlWrite, Clone)]
56#[cfg_attr(test, derive(PartialEq))]
57#[xml(tag = "w:pPrDefault")]
58pub struct DefaultParagraphProperty<'a> {
59    /// paragraph properties
60    #[xml(default, child = "w:pPr")]
61    pub inner: Option<ParagraphProperty<'a>>,
62}
63
64impl<'a, T: Into<ParagraphProperty<'a>>> From<T> for DefaultParagraphProperty<'a> {
65    fn from(val: T) -> Self {
66        DefaultParagraphProperty {
67            inner: Some(val.into()),
68        }
69    }
70}
71
72__xml_test_suites!(
73    DefaultStyle,
74    DefaultStyle::default(),
75    r#"<w:docDefaults><w:rPrDefault/><w:pPrDefault/></w:docDefaults>"#,
76);