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
use std::borrow::Cow;

use strong_xml::{XmlRead, XmlWrite};

use crate::{__setter, __string_enum, __xml_test_suites};

/// Size
///
/// ```rust
/// use docx_rust::formatting::*;
///
/// let sz = Size::from(42usize);
/// ```
#[derive(Debug, XmlRead, XmlWrite, Clone, Default)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:rFonts")]
pub struct Fonts<'a> {
    #[xml(attr = "w:hint")]
    pub hint: Option<FontHint>,
    #[xml(attr = "w:ascii")]
    pub ascii: Option<Cow<'a, str>>,
    #[xml(attr = "w:eastAsia")]
    pub east_asia: Option<Cow<'a, str>>,
    #[xml(attr = "w:hAnsi")]
    pub h_ansi: Option<Cow<'a, str>>,
    #[xml(attr = "w:cs")]
    pub custom: Option<Cow<'a, str>>,
    #[xml(attr = "w:asciiTheme")]
    pub ascii_theme: Option<Cow<'a, str>>,
    #[xml(attr = "w:eastAsiaTheme")]
    pub east_asia_theme: Option<Cow<'a, str>>,
    #[xml(attr = "w:hAnsiTheme")]
    pub h_ansi_theme: Option<Cow<'a, str>>,
    #[xml(attr = "w:cstheme")]
    pub cs_theme: Option<Cow<'a, str>>,
}

impl<'a> Fonts<'a> {
    __setter!(east_asia: Option<Cow<'a, str>>);
    __setter!(ascii: Option<Cow<'a, str>>);
    __setter!(h_ansi: Option<Cow<'a, str>>);
}

#[derive(Debug, Clone)]
#[cfg_attr(test, derive(PartialEq))]
pub enum FontHint {
    /// Text restarts on the next column.
    Ascii,
    /// Text restarts on the next page.
    EastAsia,
    /// Text restarts on the next line.
    HAnsi,
}

__string_enum! {
    FontHint {
        Ascii= "ascii",
        EastAsia = "eastAsia",
        HAnsi = "hAnsi",
    }
}

__xml_test_suites!(
    Fonts,
    Fonts::default().east_asia("宋体"),
    r#"<w:rFonts w:eastAsia="宋体"/>"#,
    Fonts::default()
        .east_asia("宋体")
        .ascii("Batang")
        .h_ansi("Batang"),
    r#"<w:rFonts w:ascii="Batang" w:eastAsia="宋体" w:hAnsi="Batang"/>"#,
);