docx_rust/formatting/
fonts.rs

1use hard_xml::{XmlRead, XmlWrite};
2
3use crate::{__define_enum, __define_struct, __xml_test_suites};
4
5// __define_struct!{
6//     (Fontss, "w:rFonts", 'a) {
7//         hint, FontHint, "w:hint",
8//         ascii, Cow<'a, str>, "w:ascii",
9//         east_asia, Cow<'a, str>, "w:eastAsia",
10//     }
11// }
12
13__define_struct! {
14    ("w:rFonts", Fonts) {
15        "w:hint", hint, FontHint
16        "w:ascii", ascii, String
17        "w:eastAsia", east_asia, String
18        "w:hAnsi", h_ansi, String
19        "w:cs", custom, String
20        "w:asciiTheme", ascii_theme, ThemeFont
21        "w:eastAsiaTheme", east_asia_theme, ThemeFont
22        "w:hAnsiTheme", h_ansi_theme, ThemeFont
23        "w:cstheme", custom_theme, String
24    }
25}
26
27// #[derive(Debug, Clone)]
28// #[cfg_attr(test, derive(PartialEq))]
29// pub enum FontHint {
30//     Default,       //	High ANSI Font
31//     EastAsia,      //	East Asian Font
32//     ComplexScript, //	Complex Script Font
33// }
34
35__define_enum! {
36    FontHint {
37        Default= "default",  //	High ANSI Font
38        EastAsia = "eastAsia", //	East Asian Font
39        ComplexScript = "cs",//	Complex Script Font
40    }
41}
42
43__define_enum! {
44    ThemeFont {
45        MajorEastAsia = "majorEastAsia", // Major East Asian Theme Font
46        MajorBidi = "majorBidi", // Major Complex Script Theme Font
47        MajorAscii = "majorAscii", // Major ASCII Theme Font
48        MajorHansi = "majorHAnsi", // Major High ANSI Theme Font
49        MinorEastAsia = "minorEastAsia", // Minor East Asian Theme Font
50        MinorBidi = "minorBidi", // Minor Complex Script Theme Font
51        MinorAscii = "minorAscii", // Minor ASCII Theme Font
52        MinorHansi = "minorHAnsi", // Minor High ANSI Theme Font
53    }
54}
55
56__xml_test_suites!(
57    Fonts,
58    Fonts::default().east_asia("宋体"),
59    r#"<w:rFonts w:eastAsia="宋体"/>"#,
60    Fonts::default()
61        .east_asia("宋体")
62        .ascii("Batang")
63        .h_ansi("Batang"),
64    r#"<w:rFonts w:ascii="Batang" w:eastAsia="宋体" w:hAnsi="Batang"/>"#,
65);