Skip to main content

umya_spreadsheet/structs/
font_size.rs

1// sz
2use std::io::Cursor;
3
4use quick_xml::{
5    Reader,
6    Writer,
7    events::BytesStart,
8};
9
10use super::DoubleValue;
11use crate::{
12    reader::driver::get_attribute,
13    writer::driver::write_start_tag,
14};
15
16#[derive(Clone, Default, Debug, PartialEq, PartialOrd)]
17pub struct FontSize {
18    pub(crate) val: DoubleValue,
19}
20
21impl FontSize {
22    #[inline]
23    #[must_use]
24    pub fn val(&self) -> f64 {
25        self.val.value()
26    }
27
28    #[inline]
29    #[must_use]
30    #[deprecated(since = "3.0.0", note = "Use val()")]
31    pub fn get_val(&self) -> f64 {
32        self.val()
33    }
34
35    #[inline]
36    pub fn set_val(&mut self, value: f64) -> &mut Self {
37        self.val.set_value(value);
38        self
39    }
40
41    #[inline]
42    pub(crate) fn set_attributes<R: std::io::BufRead>(
43        &mut self,
44        _reader: &mut Reader<R>,
45        e: &BytesStart,
46    ) {
47        self.val.set_value_string(get_attribute(e, b"val").unwrap());
48    }
49
50    #[inline]
51    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
52        // sz
53        if self.val.has_value() {
54            write_start_tag(
55                writer,
56                "sz",
57                vec![("val", &self.val.value_string()).into()],
58                true,
59            );
60        }
61    }
62}