Skip to main content

umya_spreadsheet/structs/drawing/
supplemental_font.rs

1// a:font
2use std::io::Cursor;
3
4use quick_xml::{
5    Reader,
6    Writer,
7    events::{
8        BytesStart,
9        Event,
10    },
11};
12
13use crate::{
14    reader::driver::{
15        get_attribute,
16        set_string_from_xml,
17        xml_read_loop,
18    },
19    structs::StringValue,
20    writer::driver::write_start_tag,
21};
22
23#[derive(Clone, Default, Debug)]
24pub struct SupplementalFont {
25    script:   StringValue,
26    typeface: StringValue,
27}
28
29impl SupplementalFont {
30    #[inline]
31    #[must_use]
32    pub fn script(&self) -> &str {
33        self.script.value_str()
34    }
35
36    #[inline]
37    #[must_use]
38    #[deprecated(since = "3.0.0", note = "Use script()")]
39    pub fn get_script(&self) -> &str {
40        self.script()
41    }
42
43    #[inline]
44    pub fn set_script<S: Into<String>>(&mut self, value: S) -> &mut Self {
45        self.script.set_value(value);
46        self
47    }
48
49    #[inline]
50    #[must_use]
51    pub fn typeface(&self) -> &str {
52        self.typeface.value_str()
53    }
54
55    #[inline]
56    #[must_use]
57    #[deprecated(since = "3.0.0", note = "Use typeface()")]
58    pub fn get_typeface(&self) -> &str {
59        self.typeface()
60    }
61
62    #[inline]
63    pub fn set_typeface<S: Into<String>>(&mut self, value: S) -> &mut Self {
64        self.typeface.set_value(value);
65        self
66    }
67
68    #[inline]
69    pub(crate) fn set_attributes<R: std::io::BufRead>(
70        &mut self,
71        reader: &mut Reader<R>,
72        e: &BytesStart,
73        empty_flag: bool,
74    ) {
75        set_string_from_xml!(self, e, script, "script");
76        set_string_from_xml!(self, e, typeface, "typeface");
77
78        if empty_flag {
79            return;
80        }
81
82        xml_read_loop!(
83            reader,
84            Event::End(ref e) => {
85                if e.name().into_inner() == b"a:font" {
86                    return;
87                }
88            },
89            Event::Eof => panic!("Error: Could not find {} end element", "a:font")
90        );
91    }
92
93    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
94        // a:font
95        write_start_tag(
96            writer,
97            "a:font",
98            vec![
99                ("script", self.script.value_str()).into(),
100                ("typeface", self.typeface.value_str()).into(),
101            ],
102            true,
103        );
104    }
105}