docx_rs/documents/
font_table.rs1use super::Font;
2use crate::documents::BuildXML;
3use crate::types::FontPitchType;
4use crate::xml_builder::*;
5use std::io::Write;
6
7use serde::Serialize;
8
9#[derive(Debug, Clone, PartialEq, Serialize, Default)]
10#[serde(rename_all = "camelCase")]
11pub struct FontTable {}
12
13impl FontTable {
14 pub fn new() -> FontTable {
15 Default::default()
16 }
17}
18
19impl BuildXML for FontTable {
20 fn build_to<W: Write>(
21 &self,
22 stream: xml::writer::EventWriter<W>,
23 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
24 let b = XMLBuilder::from(stream);
25 let times = Font::new("Times New Roman", "00", "roman", FontPitchType::Variable);
26 let symbol = Font::new("Symbol", "02", "roman", FontPitchType::Variable);
27 let arial = Font::new("Arial", "00", "swiss", FontPitchType::Variable);
28 b.declaration(Some(true))?
29 .open_fonts()?
30 .add_child(×)?
31 .add_child(&symbol)?
32 .add_child(&arial)?
33 .close()?
34 .into_inner()
35 }
36}
37
38#[cfg(test)]
39mod tests {
40
41 use super::*;
42 use pretty_assertions::assert_str_eq;
43 use std::str;
44
45 #[test]
46 fn test_settings() {
47 let c = FontTable::new();
48 let b = c.build();
49 assert_str_eq!(
50 str::from_utf8(&b).unwrap(),
51 r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:fonts xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><w:font w:name="Times New Roman"><w:charset w:val="00" /><w:family w:val="roman" /><w:pitch w:val="variable" /></w:font><w:font w:name="Symbol"><w:charset w:val="02" /><w:family w:val="roman" /><w:pitch w:val="variable" /></w:font><w:font w:name="Arial"><w:charset w:val="00" /><w:family w:val="swiss" /><w:pitch w:val="variable" /></w:font></w:fonts>"#
52 );
53 }
54}