1#[non_exhaustive]
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum ProgId {
7 ExcelWorksheet,
9 ExcelChart,
11 WordDocument,
13 PowerPointPresentation,
15 PowerPointSlide,
17 VisioDrawing,
19 AcrobatDocument,
21 Package,
23}
24
25impl ProgId {
26 #[must_use]
28 pub const fn to_prog_id_str(self) -> &'static str {
29 match self {
30 Self::ExcelWorksheet => "Excel.Sheet.12",
31 Self::ExcelChart => "Excel.Chart.8",
32 Self::WordDocument => "Word.Document.12",
33 Self::PowerPointPresentation => "PowerPoint.Show.12",
34 Self::PowerPointSlide => "PowerPoint.Slide.12",
35 Self::VisioDrawing => "Visio.Drawing.15",
36 Self::AcrobatDocument => "AcroExch.Document",
37 Self::Package => "Package",
38 }
39 }
40
41 #[must_use]
43 pub fn from_prog_id_str(s: &str) -> Option<Self> {
44 match s {
45 "Excel.Sheet.12" => Some(Self::ExcelWorksheet),
46 "Excel.Chart.8" => Some(Self::ExcelChart),
47 "Word.Document.12" => Some(Self::WordDocument),
48 "PowerPoint.Show.12" => Some(Self::PowerPointPresentation),
49 "PowerPoint.Slide.12" => Some(Self::PowerPointSlide),
50 "Visio.Drawing.15" => Some(Self::VisioDrawing),
51 "AcroExch.Document" => Some(Self::AcrobatDocument),
52 "Package" => Some(Self::Package),
53 _ => None,
54 }
55 }
56}
57
58#[non_exhaustive]
64#[derive(Debug, Clone, Copy, PartialEq, Eq)]
65pub enum PpMediaType {
66 Movie,
68 Sound,
70 Other,
72}
73
74impl PpMediaType {
75 #[must_use]
77 pub const fn to_xml_str(self) -> &'static str {
78 match self {
79 Self::Movie => "movie",
80 Self::Sound => "sound",
81 Self::Other => "other",
82 }
83 }
84
85 #[must_use]
87 pub fn from_xml_str(s: &str) -> Option<Self> {
88 match s {
89 "movie" => Some(Self::Movie),
90 "sound" => Some(Self::Sound),
91 "other" => Some(Self::Other),
92 _ => None,
93 }
94 }
95}
96
97pub struct ExcelNumFormat;
105
106impl ExcelNumFormat {
107 pub const GENERAL: &str = "General";
109 pub const NUMBER: &str = "0.00";
111 pub const NUMBER_NO_DECIMAL: &str = "0";
113 pub const CURRENCY: &str = "$#,##0.00";
115 pub const PERCENTAGE: &str = "0%";
117 pub const PERCENTAGE_DECIMAL: &str = "0.00%";
119 pub const DATE: &str = "m/d/yyyy";
121 pub const TIME: &str = "h:mm:ss";
123}
124
125#[non_exhaustive]
131#[derive(Debug, Clone, Copy, PartialEq, Eq)]
132pub enum PrintColorMode {
133 Color,
135 Grayscale,
137 PureBlackWhite,
139}
140
141impl PrintColorMode {
142 #[must_use]
144 pub const fn to_xml_str(self) -> &'static str {
145 match self {
146 Self::Color => "clr",
147 Self::Grayscale => "gray",
148 Self::PureBlackWhite => "pureBlkWht",
149 }
150 }
151
152 #[must_use]
154 pub fn from_xml_str(s: &str) -> Option<Self> {
155 match s {
156 "clr" => Some(Self::Color),
157 "gray" => Some(Self::Grayscale),
158 "pureBlkWht" => Some(Self::PureBlackWhite),
159 _ => None,
160 }
161 }
162}
163
164#[non_exhaustive]
170#[derive(Debug, Clone, Copy, PartialEq, Eq)]
171pub enum PrintWhat {
172 Slides,
174 Handouts,
176 Notes,
178 Outline,
180}
181
182impl PrintWhat {
183 #[must_use]
185 pub const fn to_xml_str(self) -> &'static str {
186 match self {
187 Self::Slides => "slides",
188 Self::Handouts => "handouts",
189 Self::Notes => "notes",
190 Self::Outline => "outline",
191 }
192 }
193
194 #[must_use]
196 pub fn from_xml_str(s: &str) -> Option<Self> {
197 match s {
198 "slides" => Some(Self::Slides),
199 "handouts" => Some(Self::Handouts),
200 "notes" => Some(Self::Notes),
201 "outline" => Some(Self::Outline),
202 _ => None,
203 }
204 }
205}
206
207#[non_exhaustive]
213#[derive(Debug, Clone, Copy, PartialEq, Eq)]
214pub enum HandoutLayout {
215 One,
217 Two,
219 Three,
221 Four,
223 Six,
225 Nine,
227}
228
229impl HandoutLayout {
230 #[must_use]
232 pub const fn to_xml_str(self) -> &'static str {
233 match self {
234 Self::One => "handouts1",
235 Self::Two => "handouts2",
236 Self::Three => "handouts3",
237 Self::Four => "handouts4",
238 Self::Six => "handouts6",
239 Self::Nine => "handouts9",
240 }
241 }
242
243 #[must_use]
245 pub fn from_xml_str(s: &str) -> Option<Self> {
246 match s {
247 "handouts1" => Some(Self::One),
248 "handouts2" => Some(Self::Two),
249 "handouts3" => Some(Self::Three),
250 "handouts4" => Some(Self::Four),
251 "handouts6" => Some(Self::Six),
252 "handouts9" => Some(Self::Nine),
253 _ => None,
254 }
255 }
256}
257
258#[non_exhaustive]
264#[derive(Debug, Clone, Copy, PartialEq, Eq)]
265pub enum PrintOrientation {
266 Portrait,
268 Landscape,
270}
271
272impl PrintOrientation {
273 #[must_use]
275 pub const fn to_xml_str(self) -> &'static str {
276 match self {
277 Self::Portrait => "portrait",
278 Self::Landscape => "landscape",
279 }
280 }
281
282 #[must_use]
284 pub fn from_xml_str(s: &str) -> Option<Self> {
285 match s {
286 "portrait" => Some(Self::Portrait),
287 "landscape" => Some(Self::Landscape),
288 _ => None,
289 }
290 }
291}
292
293#[cfg(test)]
294mod tests {
295 use super::*;
296
297 #[test]
298 fn test_prog_id_roundtrip() {
299 let ids = [
300 ProgId::ExcelWorksheet,
301 ProgId::ExcelChart,
302 ProgId::WordDocument,
303 ProgId::PowerPointPresentation,
304 ProgId::Package,
305 ];
306 for id in ids {
307 let s = id.to_prog_id_str();
308 assert_eq!(ProgId::from_prog_id_str(s), Some(id));
309 }
310 }
311
312 #[test]
313 fn test_unknown_prog_id() {
314 assert_eq!(ProgId::from_prog_id_str("Unknown.App"), None);
315 }
316
317 #[test]
318 fn test_pp_media_type_roundtrip() {
319 let types = [PpMediaType::Movie, PpMediaType::Sound, PpMediaType::Other];
320 for t in types {
321 let s = t.to_xml_str();
322 assert_eq!(PpMediaType::from_xml_str(s), Some(t));
323 }
324 }
325
326 #[test]
327 fn test_pp_media_type_unknown() {
328 assert_eq!(PpMediaType::from_xml_str("unknown"), None);
329 }
330
331 #[test]
332 fn test_pp_media_type_values() {
333 assert_eq!(PpMediaType::Movie.to_xml_str(), "movie");
334 assert_eq!(PpMediaType::Sound.to_xml_str(), "sound");
335 assert_eq!(PpMediaType::Other.to_xml_str(), "other");
336 }
337
338 #[test]
339 fn test_excel_num_format_constants() {
340 assert_eq!(ExcelNumFormat::GENERAL, "General");
341 assert_eq!(ExcelNumFormat::NUMBER, "0.00");
342 assert_eq!(ExcelNumFormat::NUMBER_NO_DECIMAL, "0");
343 assert_eq!(ExcelNumFormat::CURRENCY, "$#,##0.00");
344 assert_eq!(ExcelNumFormat::PERCENTAGE, "0%");
345 assert_eq!(ExcelNumFormat::PERCENTAGE_DECIMAL, "0.00%");
346 assert_eq!(ExcelNumFormat::DATE, "m/d/yyyy");
347 assert_eq!(ExcelNumFormat::TIME, "h:mm:ss");
348 }
349
350 #[test]
351 fn test_print_color_mode_roundtrip() {
352 let modes = [
353 PrintColorMode::Color,
354 PrintColorMode::Grayscale,
355 PrintColorMode::PureBlackWhite,
356 ];
357 for m in modes {
358 let s = m.to_xml_str();
359 assert_eq!(PrintColorMode::from_xml_str(s), Some(m));
360 }
361 }
362
363 #[test]
364 fn test_print_color_mode_unknown() {
365 assert_eq!(PrintColorMode::from_xml_str("unknown"), None);
366 }
367
368 #[test]
369 fn test_print_what_roundtrip() {
370 let targets = [
371 PrintWhat::Slides,
372 PrintWhat::Handouts,
373 PrintWhat::Notes,
374 PrintWhat::Outline,
375 ];
376 for t in targets {
377 let s = t.to_xml_str();
378 assert_eq!(PrintWhat::from_xml_str(s), Some(t));
379 }
380 }
381
382 #[test]
383 fn test_print_what_unknown() {
384 assert_eq!(PrintWhat::from_xml_str("unknown"), None);
385 }
386
387 #[test]
388 fn test_handout_layout_roundtrip() {
389 let layouts = [
390 HandoutLayout::One,
391 HandoutLayout::Two,
392 HandoutLayout::Three,
393 HandoutLayout::Four,
394 HandoutLayout::Six,
395 HandoutLayout::Nine,
396 ];
397 for l in layouts {
398 let s = l.to_xml_str();
399 assert_eq!(HandoutLayout::from_xml_str(s), Some(l));
400 }
401 }
402
403 #[test]
404 fn test_handout_layout_unknown() {
405 assert_eq!(HandoutLayout::from_xml_str("unknown"), None);
406 }
407
408 #[test]
409 fn test_print_orientation_roundtrip() {
410 let orientations = [PrintOrientation::Portrait, PrintOrientation::Landscape];
411 for o in orientations {
412 let s = o.to_xml_str();
413 assert_eq!(PrintOrientation::from_xml_str(s), Some(o));
414 }
415 }
416
417 #[test]
418 fn test_print_orientation_unknown() {
419 assert_eq!(PrintOrientation::from_xml_str("unknown"), None);
420 }
421}