| 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::PropertySetId; |
| 8 |
use crate::onestore::object::Object; |
| 9 |
|
| 10 |
/// A page title. |
| 11 |
/// |
| 12 |
/// See [\[MS-ONE\] 2.2.29]. |
| 13 |
/// |
| 14 |
/// [\[MS-ONE\] 2.2.29]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/08bd4fd5-59fb-4568-9c82-d2d5280eced8 |
| 15 |
#[derive(Debug)] |
| 16 |
pub(crate) struct Data { |
| 17 |
pub(crate) last_modified_time: Time, |
| 18 |
pub(crate) children: Vec<ExGuid>, |
| 19 |
pub(crate) offset_horizontal: f32, |
| 20 |
pub(crate) offset_vertical: f32, |
| 21 |
pub(crate) layout_alignment_in_parent: Option<LayoutAlignment>, |
| 22 |
pub(crate) layout_alignment_self: Option<LayoutAlignment>, |
| 23 |
} |
| 24 |
|
| 25 |
pub(crate) fn parse(object: &Object) -> Result<Data> { |
| 26 |
if object.id() != PropertySetId::TitleNode.as_jcid() { |
| 27 |
return Err(ErrorKind::MalformedOneNoteFileData( |
| 28 |
format!("unexpected object type: 0x{:X}", object.id().0).into(), |
| 29 |
) |
| 30 |
.into()); |
| 31 |
} |
| 32 |
|
| 33 |
let last_modified_time = |
| 34 |
Time::parse(PropertyType::LastModifiedTime, object)?.ok_or_else(|| { |
| 35 |
ErrorKind::MalformedOneNoteFileData("title node has no last_modified time".into()) |
| 36 |
})?; |
| 37 |
|
| 38 |
let children = ObjectReference::parse_vec(PropertyType::ElementChildNodes, object)? |
| 39 |
.ok_or_else(|| { |
| 40 |
ErrorKind::MalformedOneNoteFileData("title node has no child nodes".into()) |
| 41 |
})?; |
| 42 |
let offset_horizontal = simple::parse_f32(PropertyType::OffsetFromParentHoriz, object)? |
| 43 |
.ok_or_else(|| { |
| 44 |
ErrorKind::MalformedOneNoteFileData("title has no horizontal offset".into()) |
| 45 |
})?; |
| 46 |
let offset_vertical = simple::parse_f32(PropertyType::OffsetFromParentVert, object)? |
| 47 |
.ok_or_else(|| { |
| 48 |
ErrorKind::MalformedOneNoteFileData("title has no vertical offset".into()) |
| 49 |
})?; |
| 50 |
|
| 51 |
let layout_alignment_in_parent = |
| 52 |
LayoutAlignment::parse(PropertyType::LayoutAlignmentInParent, object)?; |
| 53 |
let layout_alignment_self = LayoutAlignment::parse(PropertyType::LayoutAlignmentSelf, object)?; |
| 54 |
|
| 55 |
let data = Data { |
| 56 |
last_modified_time, |
| 57 |
children, |
| 58 |
offset_horizontal, |
| 59 |
offset_vertical, |
| 60 |
layout_alignment_in_parent, |
| 61 |
layout_alignment_self, |
| 62 |
}; |
| 63 |
|
| 64 |
Ok(data) |
| 65 |
} |