-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathdefault_style.rs
More file actions
72 lines (64 loc) · 2.02 KB
/
Copy pathdefault_style.rs
File metadata and controls
72 lines (64 loc) · 2.02 KB
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
#![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::formatting::*;
/// use docx::styles::*;
///
/// let style = DefaultStyle::default()
/// .character(CharacterProperty::default())
/// .paragraph(ParagraphProperty::default());
/// ```
#[derive(Debug, Default, XmlRead, XmlWrite)]
#[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)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:rPrDefault")]
pub struct DefaultCharacterProperty<'a> {
/// character properties
#[xml(default, child = "w:rPr")]
pub inner: CharacterProperty<'a>,
}
impl<'a, T: Into<CharacterProperty<'a>>> From<T> for DefaultCharacterProperty<'a> {
fn from(val: T) -> Self {
DefaultCharacterProperty { inner: val.into() }
}
}
/// Default Paragraph Properties
#[derive(Default, Debug, XmlRead, XmlWrite)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:pPrDefault")]
pub struct DefaultParagraphProperty<'a> {
/// paragraph properties
#[xml(default, child = "w:pPr")]
pub inner: ParagraphProperty<'a>,
}
impl<'a, T: Into<ParagraphProperty<'a>>> From<T> for DefaultParagraphProperty<'a> {
fn from(val: T) -> Self {
DefaultParagraphProperty { inner: val.into() }
}
}
__xml_test_suites!(
DefaultStyle,
DefaultStyle::default(),
r#"<w:docDefaults><w:rPrDefault><w:rPr/></w:rPrDefault><w:pPrDefault><w:pPr/></w:pPrDefault></w:docDefaults>"#,
);