| 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::outline_indent_distance::OutlineIndentDistance; |
| 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 |
/// An outline group. |
| 12 |
/// |
| 13 |
/// See [\[MS-ONE\] 2.2.20]. |
| 14 |
/// |
| 15 |
/// [\[MS-ONE\] 2.2.20]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/b25fa331-e07e-474e-99c9-b3603b7bf937 |
| 16 |
#[derive(Debug)] |
| 17 |
pub(crate) struct Data { |
| 18 |
pub(crate) last_modified: Time, |
| 19 |
pub(crate) children: Vec<ExGuid>, |
| 20 |
pub(crate) child_level: u8, |
| 21 |
pub(crate) layout_max_height: Option<f32>, |
| 22 |
pub(crate) layout_max_width: Option<f32>, |
| 23 |
pub(crate) layout_reserved_width: Option<f32>, |
| 24 |
pub(crate) layout_minimum_outline_width: Option<f32>, |
| 25 |
pub(crate) layout_tight_alignment: bool, |
| 26 |
pub(crate) is_layout_size_set_by_user: bool, |
| 27 |
pub(crate) offset_from_parent_horiz: Option<f32>, |
| 28 |
pub(crate) offset_from_parent_vert: Option<f32>, |
| 29 |
pub(crate) list_spacing: Option<f32>, |
| 30 |
pub(crate) outline_indent_distance: OutlineIndentDistance, |
| 31 |
pub(crate) layout_alignment_in_parent: Option<LayoutAlignment>, |
| 32 |
pub(crate) layout_alignment_self: Option<LayoutAlignment>, |
| 33 |
pub(crate) is_deletable: bool, |
| 34 |
pub(crate) is_title_date: bool, |
| 35 |
pub(crate) is_selectable: bool, |
| 36 |
pub(crate) is_title_text: bool, |
| 37 |
pub(crate) is_read_only: bool, |
| 38 |
pub(crate) descendants_cannot_be_moved: bool, |
| 39 |
pub(crate) tight_layout: bool, |
| 40 |
} |
| 41 |
|
| 42 |
pub(crate) fn parse(object: &Object) -> Result<Data> { |
| 43 |
if object.id() != PropertySetId::OutlineNode.as_jcid() { |
| 44 |
return Err(ErrorKind::MalformedOneNoteFileData( |
| 45 |
format!("unexpected object type: 0x{:X}", object.id().0).into(), |
| 46 |
) |
| 47 |
.into()); |
| 48 |
} |
| 49 |
|
| 50 |
let last_modified = Time::parse(PropertyType::LastModifiedTime, object)?.ok_or_else(|| { |
| 51 |
ErrorKind::MalformedOneNoteFileData("outline has no last modified time".into()) |
| 52 |
})?; |
| 53 |
let children = |
| 54 |
ObjectReference::parse_vec(PropertyType::ElementChildNodes, object)?.unwrap_or_default(); |
| 55 |
let child_level = simple::parse_u8(PropertyType::OutlineElementChildLevel, object)? |
| 56 |
.ok_or_else(|| { |
| 57 |
ErrorKind::MalformedOneNoteFileData("outline node has no child level".into()) |
| 58 |
})?; |
| 59 |
|
| 60 |
let layout_max_height = simple::parse_f32(PropertyType::LayoutMaxHeight, object)?; |
| 61 |
let layout_reserved_width = |
| 62 |
simple::parse_f32(PropertyType::LayoutOutlineReservedWidth, object)?; |
| 63 |
let layout_minimum_outline_width = |
| 64 |
simple::parse_f32(PropertyType::LayoutMinimumOutlineWidth, object)?; |
| 65 |
let layout_max_width = simple::parse_f32(PropertyType::LayoutMaxWidth, object)?; |
| 66 |
let layout_tight_alignment = |
| 67 |
simple::parse_bool(PropertyType::LayoutTightAlignment, object)?.unwrap_or_default(); |
| 68 |
|
| 69 |
let is_layout_size_set_by_user = |
| 70 |
simple::parse_bool(PropertyType::IsLayoutSizeSetByUser, object)?.unwrap_or_default(); |
| 71 |
let list_spacing = simple::parse_f32(PropertyType::ListSpacingMu, object)?; |
| 72 |
let outline_indent_distance = OutlineIndentDistance::parse(object)?.ok_or_else(|| { |
| 73 |
ErrorKind::MalformedOneNoteFileData("outline node has no outline indent distance".into()) |
| 74 |
})?; |
| 75 |
let offset_from_parent_horiz = simple::parse_f32(PropertyType::OffsetFromParentHoriz, object)?; |
| 76 |
let offset_from_parent_vert = simple::parse_f32(PropertyType::OffsetFromParentVert, object)?; |
| 77 |
|
| 78 |
let layout_alignment_in_parent = |
| 79 |
LayoutAlignment::parse(PropertyType::LayoutAlignmentInParent, object)?; |
| 80 |
let layout_alignment_self = LayoutAlignment::parse(PropertyType::LayoutAlignmentSelf, object)?; |
| 81 |
|
| 82 |
let is_deletable = simple::parse_bool(PropertyType::Deletable, object)?.unwrap_or_default(); |
| 83 |
let is_title_date = simple::parse_bool(PropertyType::IsTitleDate, object)?.unwrap_or_default(); |
| 84 |
let is_selectable = simple::parse_bool(PropertyType::CannotBeSelected, object)? |
| 85 |
.map(|value| !value) |
| 86 |
.unwrap_or(true); |
| 87 |
let is_title_text = simple::parse_bool(PropertyType::IsTitleText, object)?.unwrap_or_default(); |
| 88 |
let is_read_only = simple::parse_bool(PropertyType::IsReadOnly, object)?.unwrap_or_default(); |
| 89 |
let descendants_cannot_be_moved = |
| 90 |
simple::parse_bool(PropertyType::DescendantsCannotBeMoved, object)?.unwrap_or_default(); |
| 91 |
let tight_layout = |
| 92 |
simple::parse_bool(PropertyType::LayoutTightLayout, object)?.unwrap_or_default(); |
| 93 |
|
| 94 |
let data = Data { |
| 95 |
last_modified, |
| 96 |
children, |
| 97 |
child_level, |
| 98 |
layout_max_height, |
| 99 |
layout_reserved_width, |
| 100 |
layout_minimum_outline_width, |
| 101 |
layout_max_width, |
| 102 |
layout_tight_alignment, |
| 103 |
is_layout_size_set_by_user, |
| 104 |
offset_from_parent_horiz, |
| 105 |
offset_from_parent_vert, |
| 106 |
list_spacing, |
| 107 |
outline_indent_distance, |
| 108 |
layout_alignment_in_parent, |
| 109 |
layout_alignment_self, |
| 110 |
is_deletable, |
| 111 |
is_title_date, |
| 112 |
is_selectable, |
| 113 |
is_title_text, |
| 114 |
is_read_only, |
| 115 |
descendants_cannot_be_moved, |
| 116 |
tight_layout, |
| 117 |
}; |
| 118 |
|
| 119 |
Ok(data) |
| 120 |
} |