onenote_parser/onenote/list.rs
1use crate::errors::{ErrorKind, Result};
2use crate::fsshttpb::data::exguid::ExGuid;
3use crate::one::property::color_ref::ColorRef;
4use crate::one::property_set::number_list_node;
5use crate::onestore::object_space::ObjectSpace;
6
7/// A list definition.
8///
9/// See [\[MS-ONE\] 2.2.25].
10///
11/// [\[MS-ONE\]] 2.2.25: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/1a141e7a-4455-4971-bf0b-1621e221984e
12#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
13pub struct List {
14 pub(crate) list_font: Option<String>,
15 pub(crate) list_restart: Option<i32>,
16 pub(crate) list_format: Vec<char>,
17 pub(crate) bold: bool,
18 pub(crate) italic: bool,
19 // pub(crate) language_code: Option<u32>,
20 pub(crate) font: Option<String>,
21 pub(crate) font_size: Option<u16>,
22 pub(crate) font_color: Option<ColorRef>,
23}
24
25impl List {
26 /// The font used for the symbol of the list bullet.
27 ///
28 /// See [\[MS-ONE\] 2.2.1].
29 ///
30 /// [\[MS-ONE\] 2.2.1]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/f4557c94-0081-4518-89f2-a3867714e5f3
31 pub fn list_font(&self) -> Option<&str> {
32 self.list_font.as_deref()
33 }
34
35 /// Restart the list numbering with this index.
36 ///
37 /// See [\[MS-ONE\] 2.3.43].
38 ///
39 /// [\[MS-ONE\] 2.3.43]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/b6971dae-d81a-4a7d-b640-661e9c0baa17
40 pub fn list_restart(&self) -> Option<i32> {
41 self.list_restart
42 }
43
44 /// The list format specifier.
45 ///
46 /// The value of the list format specifier is described in [\[MS-ONE\] 2.3.20].
47 ///
48 /// [\[MS-ONE\] 2.3.20]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/587f8d1c-e0c3-434f-8e02-c9b4e710c0b3
49 pub fn list_format(&self) -> &[char] {
50 &self.list_format
51 }
52
53 /// Whether to apply bold formatting to the list index number.
54 pub fn bold(&self) -> bool {
55 self.bold
56 }
57
58 /// Whether to apply italic formatting to the list index number.
59 pub fn italic(&self) -> bool {
60 self.italic
61 }
62
63 /// The font to use for the list index number.
64 pub fn font(&self) -> Option<&str> {
65 self.font.as_deref()
66 }
67
68 /// The font size in half-point increments used for the list index number or bullet.
69 ///
70 /// See [\[MS-ONE\] 2.3.16].
71 ///
72 /// [\[MS-ONE\] 2.3.16]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/f209fd9c-9042-4df2-b90c-1be20ac9c2d3
73 pub fn font_size(&self) -> Option<u16> {
74 self.font_size
75 }
76
77 /// The font color used for the list index number or bullet.
78 ///
79 /// See [\[MS-ONE\] 2.2.45].
80 ///
81 /// [\[MS-ONE\] 2.2.45]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/17a7e6a7-7fa9-456f-a3fe-b2d8fef31be3
82 pub fn font_color(&self) -> Option<ColorRef> {
83 self.font_color
84 }
85}
86
87pub(crate) fn parse_list(list_id: ExGuid, space: &ObjectSpace) -> Result<List> {
88 let object = space
89 .get_object(list_id)
90 .ok_or_else(|| ErrorKind::MalformedOneNoteData("rich text content is missing".into()))?;
91 let data = number_list_node::parse(object)?;
92
93 // TODO: Parse language code
94
95 let list = List {
96 list_font: data.list_font,
97 list_restart: data.list_restart,
98 list_format: data.list_format,
99 bold: data.bold,
100 italic: data.italic,
101 font: data.font,
102 font_size: data.font_size,
103 font_color: data.font_color,
104 };
105
106 Ok(list)
107}