| 1 |
use crate::errors::{ErrorKind, Result}; |
| 2 |
use crate::fsshttpb::data::exguid::ExGuid; |
| 3 |
use crate::one::property::layout_alignment::LayoutAlignment; |
| 4 |
use crate::one::property::object_reference::ObjectReference; |
| 5 |
use crate::one::property::time::Time; |
| 6 |
use crate::one::property::{simple, PropertyType}; |
| 7 |
use crate::one::property_set::note_tag_container::Data as NoteTagData; |
| 8 |
use crate::one::property_set::PropertySetId; |
| 9 |
use crate::onestore::object::Object; |
| 10 |
|
| 11 |
/// An embedded image. |
| 12 |
/// |
| 13 |
/// See [\[MS-ONE\] 2.2.24]. |
| 14 |
/// |
| 15 |
/// [\[MS-ONE\] 2.2.24]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/b7bb4d1a-2a57-4819-9eb4-5a2ce8cf210f |
| 16 |
#[derive(Debug)] |
| 17 |
pub(crate) struct Data { |
| 18 |
pub(crate) last_modified: Time, |
| 19 |
pub(crate) picture_container: Option<ExGuid>, |
| 20 |
pub(crate) layout_max_width: Option<f32>, |
| 21 |
pub(crate) layout_max_height: Option<f32>, |
| 22 |
pub(crate) is_layout_size_set_by_user: bool, |
| 23 |
pub(crate) language_code: Option<u32>, |
| 24 |
pub(crate) alt_text: Option<String>, |
| 25 |
pub(crate) layout_alignment_in_parent: Option<LayoutAlignment>, |
| 26 |
pub(crate) layout_alignment_self: Option<LayoutAlignment>, |
| 27 |
pub(crate) image_filename: Option<String>, |
| 28 |
pub(crate) displayed_page_number: Option<u32>, |
| 29 |
pub(crate) text: Option<String>, |
| 30 |
pub(crate) text_language_code: Option<u32>, |
| 31 |
pub(crate) picture_width: Option<f32>, |
| 32 |
pub(crate) picture_height: Option<f32>, |
| 33 |
pub(crate) hyperlink_url: Option<String>, |
| 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) is_background: bool, |
| 38 |
pub(crate) iframe: Vec<ExGuid>, |
| 39 |
} |
| 40 |
|
| 41 |
pub(crate) fn parse(object: &Object) -> Result<Data> { |
| 42 |
if object.id() != PropertySetId::ImageNode.as_jcid() { |
| 43 |
return Err(ErrorKind::MalformedOneNoteFileData( |
| 44 |
format!("unexpected object type: 0x{:X}", object.id().0).into(), |
| 45 |
) |
| 46 |
.into()); |
| 47 |
} |
| 48 |
|
| 49 |
let last_modified = Time::parse(PropertyType::LastModifiedTime, object)?.ok_or_else(|| { |
| 50 |
ErrorKind::MalformedOneNoteFileData("image has no last modified time".into()) |
| 51 |
})?; |
| 52 |
let picture_container = ObjectReference::parse(PropertyType::PictureContainer, object)?; |
| 53 |
let layout_max_width = simple::parse_f32(PropertyType::LayoutMaxWidth, object)?; |
| 54 |
let layout_max_height = simple::parse_f32(PropertyType::LayoutMaxHeight, object)?; |
| 55 |
let is_layout_size_set_by_user = |
| 56 |
simple::parse_bool(PropertyType::IsLayoutSizeSetByUser, object)?.unwrap_or_default(); |
| 57 |
let language_code = simple::parse_u32(PropertyType::LanguageId, object)?; |
| 58 |
let alt_text = simple::parse_string(PropertyType::ImageAltText, object)?; |
| 59 |
let layout_alignment_in_parent = |
| 60 |
LayoutAlignment::parse(PropertyType::LayoutAlignmentInParent, object)?; |
| 61 |
let layout_alignment_self = LayoutAlignment::parse(PropertyType::LayoutAlignmentSelf, object)?; |
| 62 |
let image_filename = simple::parse_string(PropertyType::ImageFilename, object)?; |
| 63 |
let displayed_page_number = simple::parse_u32(PropertyType::DisplayedPageNumber, object)?; |
| 64 |
let text = simple::parse_string(PropertyType::RichEditTextUnicode, object)?; |
| 65 |
let text_language_code = |
| 66 |
simple::parse_u16(PropertyType::RichEditTextLangId, object)?.map(|value| value as u32); |
| 67 |
let picture_width = simple::parse_f32(PropertyType::PictureWidth, object)?; |
| 68 |
let picture_height = simple::parse_f32(PropertyType::PictureHeight, object)?; |
| 69 |
let hyperlink_url = simple::parse_string(PropertyType::WzHyperlinkUrl, object)?; |
| 70 |
let offset_from_parent_horiz = simple::parse_f32(PropertyType::OffsetFromParentHoriz, object)?; |
| 71 |
let offset_from_parent_vert = simple::parse_f32(PropertyType::OffsetFromParentVert, object)?; |
| 72 |
let is_background = simple::parse_bool(PropertyType::IsBackground, object)?.unwrap_or_default(); |
| 73 |
|
| 74 |
let note_tags = NoteTagData::parse(object)?.unwrap_or_default(); |
| 75 |
|
| 76 |
let iframe = |
| 77 |
ObjectReference::parse_vec(PropertyType::ContentChildNodes, object)?.unwrap_or_default(); |
| 78 |
|
| 79 |
let data = Data { |
| 80 |
last_modified, |
| 81 |
picture_container, |
| 82 |
layout_max_width, |
| 83 |
layout_max_height, |
| 84 |
is_layout_size_set_by_user, |
| 85 |
language_code, |
| 86 |
alt_text, |
| 87 |
layout_alignment_in_parent, |
| 88 |
layout_alignment_self, |
| 89 |
image_filename, |
| 90 |
displayed_page_number, |
| 91 |
text, |
| 92 |
text_language_code, |
| 93 |
picture_width, |
| 94 |
picture_height, |
| 95 |
hyperlink_url, |
| 96 |
note_tags, |
| 97 |
offset_from_parent_horiz, |
| 98 |
offset_from_parent_vert, |
| 99 |
is_background, |
| 100 |
iframe, |
| 101 |
}; |
| 102 |
|
| 103 |
Ok(data) |
| 104 |
} |