| 1 |
use crate::errors::{ErrorKind, Result}; |
| 2 |
use crate::fsshttpb::data::exguid::ExGuid; |
| 3 |
use crate::one::property::author::Author; |
| 4 |
use crate::one::property::object_reference::ObjectReference; |
| 5 |
use crate::one::property::page_size::PageSize; |
| 6 |
use crate::one::property::time::Time; |
| 7 |
use crate::one::property::{simple, PropertyType}; |
| 8 |
use crate::one::property_set::PropertySetId; |
| 9 |
use crate::onestore::object::Object; |
| 10 |
|
| 11 |
/// A page. |
| 12 |
/// |
| 13 |
/// See [\[MS-ONE\] 2.2.19]. |
| 14 |
/// |
| 15 |
/// [\[MS-ONE\] 2.2.19]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/e381b7c7-b434-43a2-ba23-0d08bafd281a |
| 16 |
#[derive(Debug)] |
| 17 |
pub(crate) struct Data { |
| 18 |
pub(crate) last_modified: Option<Time>, |
| 19 |
pub(crate) cached_title: Option<String>, |
| 20 |
pub(crate) author: Option<Author>, // FIXME: Force this? |
| 21 |
pub(crate) content: Vec<ExGuid>, |
| 22 |
pub(crate) title: Option<ExGuid>, |
| 23 |
pub(crate) orientation_portrait: bool, |
| 24 |
pub(crate) page_width: Option<f32>, // FIXME: Force this? |
| 25 |
pub(crate) page_height: Option<f32>, // FIXME: Force this? |
| 26 |
pub(crate) page_margin_origin_x: Option<f32>, |
| 27 |
pub(crate) page_margin_origin_y: Option<f32>, |
| 28 |
pub(crate) page_margin_left: Option<f32>, // FIXME: Force this? |
| 29 |
pub(crate) page_margin_right: Option<f32>, // FIXME: Force this? |
| 30 |
pub(crate) page_margin_top: Option<f32>, // FIXME: Force this? |
| 31 |
pub(crate) page_margin_bottom: Option<f32>, // FIXME: Force this? |
| 32 |
pub(crate) page_size: PageSize, |
| 33 |
pub(crate) rtl: bool, |
| 34 |
} |
| 35 |
|
| 36 |
pub(crate) fn parse(object: &Object) -> Result<Data> { |
| 37 |
if object.id() != PropertySetId::PageNode.as_jcid() { |
| 38 |
return Err(ErrorKind::MalformedOneNoteFileData( |
| 39 |
format!("unexpected object type: 0x{:X}", object.id().0).into(), |
| 40 |
) |
| 41 |
.into()); |
| 42 |
} |
| 43 |
|
| 44 |
let last_modified = Time::parse(PropertyType::LastModifiedTime, object)?; |
| 45 |
let cached_title = simple::parse_string(PropertyType::CachedTitleStringFromPage, object)?; |
| 46 |
let author = Author::parse(object)?; |
| 47 |
let content = |
| 48 |
ObjectReference::parse_vec(PropertyType::ElementChildNodes, object)?.unwrap_or_default(); |
| 49 |
let title = ObjectReference::parse_vec(PropertyType::StructureElementChildNodes, object)? |
| 50 |
.unwrap_or_default() |
| 51 |
.first() |
| 52 |
.copied(); |
| 53 |
let orientation_portrait = |
| 54 |
simple::parse_bool(PropertyType::PortraitPage, object)?.unwrap_or_default(); |
| 55 |
let page_width = simple::parse_f32(PropertyType::PageWidth, object)?; |
| 56 |
let page_height = simple::parse_f32(PropertyType::PageHeight, object)?; |
| 57 |
let page_margin_origin_x = simple::parse_f32(PropertyType::PageMarginOriginX, object)?; |
| 58 |
let page_margin_origin_y = simple::parse_f32(PropertyType::PageMarginOriginY, object)?; |
| 59 |
let page_margin_left = simple::parse_f32(PropertyType::PageMarginLeft, object)?; |
| 60 |
let page_margin_right = simple::parse_f32(PropertyType::PageMarginRight, object)?; |
| 61 |
let page_margin_top = simple::parse_f32(PropertyType::PageMarginTop, object)?; |
| 62 |
let page_margin_bottom = simple::parse_f32(PropertyType::PageMarginBottom, object)?; |
| 63 |
let page_size = PageSize::parse(PropertyType::PageSize, object)?.unwrap_or_default(); |
| 64 |
let rtl = simple::parse_bool(PropertyType::EditRootRtl, object)?.unwrap_or_default(); |
| 65 |
|
| 66 |
let data = Data { |
| 67 |
last_modified, |
| 68 |
cached_title, |
| 69 |
author, |
| 70 |
content, |
| 71 |
title, |
| 72 |
orientation_portrait, |
| 73 |
page_width, |
| 74 |
page_height, |
| 75 |
page_margin_origin_x, |
| 76 |
page_margin_origin_y, |
| 77 |
page_margin_left, |
| 78 |
page_margin_right, |
| 79 |
page_margin_top, |
| 80 |
page_margin_bottom, |
| 81 |
page_size, |
| 82 |
rtl, |
| 83 |
}; |
| 84 |
|
| 85 |
Ok(data) |
| 86 |
} |