| 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::layout_alignment::LayoutAlignment; |
| 5 |
use crate::one::property::object_reference::ObjectReference; |
| 6 |
use crate::one::property::time::Time; |
| 7 |
use crate::one::property::{simple, PropertyType}; |
| 8 |
use crate::one::property_set::note_tag_container::Data as NoteTagData; |
| 9 |
use crate::one::property_set::PropertySetId; |
| 10 |
use crate::onestore::object::Object; |
| 11 |
|
| 12 |
/// An embedded file. |
| 13 |
/// |
| 14 |
/// See [\[MS-ONE\] 2.2.32]. |
| 15 |
/// |
| 16 |
/// [\[MS-ONE\] 2.2.32]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/a665b5ad-ff40-4c0c-9e42-4b707254dc3f |
| 17 |
#[derive(Debug)] |
| 18 |
pub(crate) struct Data { |
| 19 |
pub(crate) last_modified: Time, |
| 20 |
pub(crate) picture_container: Option<ExGuid>, |
| 21 |
pub(crate) layout_max_width: Option<f32>, |
| 22 |
pub(crate) layout_max_height: Option<f32>, |
| 23 |
pub(crate) is_layout_size_set_by_user: bool, |
| 24 |
pub(crate) text: Option<String>, |
| 25 |
pub(crate) text_language_code: Option<u32>, |
| 26 |
pub(crate) layout_alignment_in_parent: Option<LayoutAlignment>, |
| 27 |
pub(crate) layout_alignment_self: Option<LayoutAlignment>, |
| 28 |
pub(crate) embedded_file_container: ExGuid, |
| 29 |
pub(crate) embedded_file_name: String, |
| 30 |
pub(crate) source_path: Option<String>, |
| 31 |
pub(crate) file_type: FileType, |
| 32 |
pub(crate) picture_width: Option<f32>, |
| 33 |
pub(crate) picture_height: Option<f32>, |
| 34 |
pub(crate) note_tags: Vec<NoteTagData>, |
| 35 |
pub(crate) offset_from_parent_horiz: Option<f32>, |
| 36 |
pub(crate) offset_from_parent_vert: Option<f32>, |
| 37 |
pub(crate) recording_duration: Option<u32>, |
| 38 |
} |
| 39 |
|
| 40 |
pub(crate) fn parse(object: &Object) -> Result<Data> { |
| 41 |
if object.id() != PropertySetId::EmbeddedFileNode.as_jcid() { |
| 42 |
return Err(ErrorKind::MalformedOneNoteFileData( |
| 43 |
format!("unexpected object type: 0x{:X}", object.id().0).into(), |
| 44 |
) |
| 45 |
.into()); |
| 46 |
} |
| 47 |
|
| 48 |
let last_modified = Time::parse(PropertyType::LastModifiedTime, object)?.ok_or_else(|| { |
| 49 |
ErrorKind::MalformedOneNoteFileData("embedded file has no last modified time".into()) |
| 50 |
})?; |
| 51 |
let picture_container = ObjectReference::parse(PropertyType::PictureContainer, object)?; |
| 52 |
let layout_max_width = simple::parse_f32(PropertyType::LayoutMaxWidth, object)?; |
| 53 |
let layout_max_height = simple::parse_f32(PropertyType::LayoutMaxHeight, object)?; |
| 54 |
let is_layout_size_set_by_user = |
| 55 |
simple::parse_bool(PropertyType::IsLayoutSizeSetByUser, object)?.unwrap_or_default(); |
| 56 |
let text = simple::parse_string(PropertyType::RichEditTextUnicode, object)?; |
| 57 |
let text_language_code = |
| 58 |
simple::parse_u16(PropertyType::RichEditTextLangId, object)?.map(|value| value as u32); |
| 59 |
let layout_alignment_in_parent = |
| 60 |
LayoutAlignment::parse(PropertyType::LayoutAlignmentInParent, object)?; |
| 61 |
let layout_alignment_self = LayoutAlignment::parse(PropertyType::LayoutAlignmentSelf, object)?; |
| 62 |
let embedded_file_container = |
| 63 |
ObjectReference::parse(PropertyType::EmbeddedFileContainer, object)?.ok_or_else(|| { |
| 64 |
ErrorKind::MalformedOneNoteFileData("embedded file has no file container".into()) |
| 65 |
})?; |
| 66 |
let embedded_file_name = simple::parse_string(PropertyType::EmbeddedFileName, object)? |
| 67 |
.ok_or_else(|| { |
| 68 |
ErrorKind::MalformedOneNoteFileData("embedded file has no file name".into()) |
| 69 |
})?; |
| 70 |
let source_path = simple::parse_string(PropertyType::SourceFilepath, object)?; |
| 71 |
let file_type = FileType::parse(object)?; |
| 72 |
let picture_width = simple::parse_f32(PropertyType::PictureWidth, object)?; |
| 73 |
let picture_height = simple::parse_f32(PropertyType::PictureHeight, object)?; |
| 74 |
let offset_from_parent_horiz = simple::parse_f32(PropertyType::OffsetFromParentHoriz, object)?; |
| 75 |
let offset_from_parent_vert = simple::parse_f32(PropertyType::OffsetFromParentVert, object)?; |
| 76 |
// let recording_duration = simple::parse_u32(PropertyType::Duration) // FIXME: Record duration property id not known |
| 77 |
|
| 78 |
let note_tags = NoteTagData::parse(object)?.unwrap_or_default(); |
| 79 |
|
| 80 |
let data = Data { |
| 81 |
last_modified, |
| 82 |
picture_container, |
| 83 |
layout_max_width, |
| 84 |
layout_max_height, |
| 85 |
is_layout_size_set_by_user, |
| 86 |
text, |
| 87 |
text_language_code, |
| 88 |
layout_alignment_in_parent, |
| 89 |
layout_alignment_self, |
| 90 |
embedded_file_container, |
| 91 |
embedded_file_name, |
| 92 |
source_path, |
| 93 |
file_type, |
| 94 |
picture_width, |
| 95 |
picture_height, |
| 96 |
note_tags, |
| 97 |
offset_from_parent_horiz, |
| 98 |
offset_from_parent_vert, |
| 99 |
recording_duration: None, // FIXME: Parse this |
| 100 |
}; |
| 101 |
|
| 102 |
Ok(data) |
| 103 |
} |