Debian Codegraph @

.cargo/vendor/onenote_parser/src/onenote/embedded_file.rs

raw
1 use crate::errors::{ErrorKind, Result};
2 use crate::fsshttpb::data::exguid::ExGuid;
3 use crate::one::property::file_type::FileType;
4 use crate::one::property_set::{embedded_file_container, embedded_file_node};
5 use crate::onenote::note_tag::{parse_note_tags, NoteTag};
6 use crate::onestore::object_space::ObjectSpace;
7
8 /// An embedded file.
9 ///
10 /// See [\[MS-ONE\] 2.2.32].
11 ///
12 /// [\[MS-ONE\] 2.2.32]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/a665b5ad-ff40-4c0c-9e42-4b707254dc3f
13 #[derive(Clone, PartialEq, PartialOrd, Debug)]
14 pub struct EmbeddedFile {
15 pub(crate) filename: String,
16 pub(crate) file_type: FileType,
17 pub(crate) data: Vec<u8>,
18
19 pub(crate) layout_max_width: Option<f32>,
20 pub(crate) layout_max_height: Option<f32>,
21
22 pub(crate) offset_horizontal: Option<f32>,
23 pub(crate) offset_vertical: Option<f32>,
24
25 pub(crate) note_tags: Vec<NoteTag>,
26 }
27
28 impl EmbeddedFile {
29 /// The embedded file's original file name.
30 ///
31 /// See [\[MS-ONE\] 2.2.71].
32 ///
33 /// [\[MS-ONE\] 2.2.71]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/9c3409c0-0d81-42a8-bd97-d02a5b130b7d
34 pub fn filename(&self) -> &str {
35 &self.filename
36 }
37
38 /// The file type.
39 ///
40 /// See [\[MS-ONE\] 2.3.62].
41 ///
42 /// [\[MS-ONE\] 2.3.62]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/112836a0-ed3b-4be1-bc4b-49f0f7b02295
43 pub fn file_type(&self) -> &FileType {
44 &self.file_type
45 }
46
47 /// The file's binary data.
48 pub fn data(&self) -> &[u8] {
49 &self.data
50 }
51
52 /// The max width of the embedded file's icon in half-inch increments.
53 ///
54 /// See [\[MS-ONE\] 2.3.21].
55 ///
56 /// [\[MS-ONE\] 2.3.21]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/2561c763-93b8-4b64-b6c7-1b86335d5b85
57 pub fn layout_max_width(&self) -> Option<f32> {
58 self.layout_max_width
59 }
60
61 /// The max height of the embedded file's icon in half-inch increments.
62 ///
63 /// See [\[MS-ONE\] 2.3.23].
64 ///
65 /// [\[MS-ONE\] 2.3.23]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/ce514d53-1229-4e77-9908-ef8de1761ceb
66 pub fn layout_max_height(&self) -> Option<f32> {
67 self.layout_max_height
68 }
69
70 /// The horizontal offset from the page origin in half-inch increments.
71 ///
72 /// See [\[MS-ONE\] 2.3.18].
73 ///
74 /// [\[MS-ONE\] 2.3.18]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/5fb9e84a-c9e9-4537-ab14-e5512f24669a
75 pub fn offset_horizontal(&self) -> Option<f32> {
76 self.offset_horizontal
77 }
78
79 /// The vertical offset from the page origin in half-inch increments.
80 ///
81 /// See [\[MS-ONE\] 2.3.19].
82 ///
83 /// [\[MS-ONE\] 2.3.19]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/5c4992ba-1db5-43e9-83dd-7299c562104d
84 pub fn offset_vertical(&self) -> Option<f32> {
85 self.offset_vertical
86 }
87
88 /// Note tags for the embedded file.
89 pub fn note_tags(&self) -> &[NoteTag] {
90 &self.note_tags
91 }
92 }
93
94 pub(crate) fn parse_embedded_file(file_id: ExGuid, space: &ObjectSpace) -> Result<EmbeddedFile> {
95 let node_object = space
96 .get_object(file_id)
97 .ok_or_else(|| ErrorKind::MalformedOneNoteData("embedded file is missing".into()))?;
98 let node = embedded_file_node::parse(node_object)?;
99
100 let container_object_id = node.embedded_file_container;
101 let container_object = space.get_object(container_object_id).ok_or_else(|| {
102 ErrorKind::MalformedOneNoteData("embedded file container is missing".into())
103 })?;
104 let container = embedded_file_container::parse(container_object)?;
105
106 // TODO: Resolve picture container
107
108 let file = EmbeddedFile {
109 filename: node.embedded_file_name,
110 file_type: node.file_type,
111 data: container.into_value(),
112 layout_max_width: node.layout_max_width,
113 layout_max_height: node.layout_max_height,
114 offset_horizontal: node.offset_from_parent_horiz,
115 offset_vertical: node.offset_from_parent_vert,
116 note_tags: parse_note_tags(node.note_tags, space)?,
117 };
118
119 Ok(file)
120 }