umya_spreadsheet/structs/drawing/
font_scheme.rs1use std::io::Cursor;
3
4use quick_xml::{
5 Reader,
6 Writer,
7 events::{
8 BytesStart,
9 Event,
10 },
11};
12
13use super::{
14 super::StringValue,
15 FontCollectionType,
16};
17use crate::{
18 reader::driver::{
19 get_attribute,
20 xml_read_loop,
21 },
22 writer::driver::{
23 write_end_tag,
24 write_start_tag,
25 },
26};
27
28#[derive(Clone, Default, Debug)]
29pub struct FontScheme {
30 name: StringValue,
31 major_font: FontCollectionType,
32 minor_font: FontCollectionType,
33}
34
35impl FontScheme {
36 #[inline]
37 #[must_use]
38 pub fn name(&self) -> &str {
39 self.name.value_str()
40 }
41
42 #[inline]
43 #[must_use]
44 #[deprecated(since = "3.0.0", note = "Use name()")]
45 pub fn get_name(&self) -> &str {
46 self.name()
47 }
48
49 #[inline]
50 pub fn set_name<S: Into<String>>(&mut self, value: S) -> &mut Self {
51 self.name.set_value(value);
52 self
53 }
54
55 #[inline]
56 #[must_use]
57 pub fn major_font(&self) -> &FontCollectionType {
58 &self.major_font
59 }
60
61 #[inline]
62 #[must_use]
63 #[deprecated(since = "3.0.0", note = "Use major_font()")]
64 pub fn get_major_font(&self) -> &FontCollectionType {
65 self.major_font()
66 }
67
68 #[inline]
69 pub fn major_font_mut(&mut self) -> &mut FontCollectionType {
70 &mut self.major_font
71 }
72
73 #[inline]
74 #[deprecated(since = "3.0.0", note = "Use major_font_mut()")]
75 pub fn get_major_font_mut(&mut self) -> &mut FontCollectionType {
76 self.major_font_mut()
77 }
78
79 #[inline]
80 pub fn set_major_font(&mut self, value: FontCollectionType) -> &mut Self {
81 self.major_font = value;
82 self
83 }
84
85 #[inline]
86 #[must_use]
87 pub fn minor_font(&self) -> &FontCollectionType {
88 &self.minor_font
89 }
90
91 #[inline]
92 #[must_use]
93 #[deprecated(since = "3.0.0", note = "Use minor_font()")]
94 pub fn get_minor_font(&self) -> &FontCollectionType {
95 self.minor_font()
96 }
97
98 #[inline]
99 pub fn minor_font_mut(&mut self) -> &mut FontCollectionType {
100 &mut self.minor_font
101 }
102
103 #[inline]
104 #[deprecated(since = "3.0.0", note = "Use minor_font_mut()")]
105 pub fn get_minor_font_mut(&mut self) -> &mut FontCollectionType {
106 self.minor_font_mut()
107 }
108
109 #[inline]
110 pub fn set_minor_font(&mut self, value: FontCollectionType) -> &mut Self {
111 self.minor_font = value;
112 self
113 }
114
115 pub(crate) fn set_attributes<R: std::io::BufRead>(
116 &mut self,
117 reader: &mut Reader<R>,
118 e: &BytesStart,
119 ) {
120 if let Some(v) = get_attribute(e, b"name") {
121 self.name.set_value(v);
122 }
123
124 xml_read_loop!(
125 reader,
126 Event::Start(ref e) => {
127 match e.name().into_inner() {
128 b"a:majorFont" => {
129 self.major_font.set_attributes(reader, e);
130 }
131 b"a:minorFont" => {
132 self.minor_font.set_attributes(reader, e);
133 }
134 _ => (),
135 }
136 },
137 Event::End(ref e) => {
138 if e.name().into_inner() == b"a:fontScheme" {
139 return
140 }
141 },
142 Event::Eof => panic!("Error: Could not find {} end element", "a:fontScheme")
143 );
144 }
145
146 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
147 let mut attributes: crate::structs::AttrCollection = Vec::new();
149 if self.name.has_value() {
150 attributes.push(("name", self.name.value_str()).into());
151 }
152 write_start_tag(writer, "a:fontScheme", attributes, false);
153
154 self.major_font.write_to_major_font(writer);
156
157 self.minor_font.write_to_minor_font(writer);
159
160 write_end_tag(writer, "a:fontScheme");
161 }
162}