| 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::paragraph_alignment::ParagraphAlignment; |
| 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 |
/// A rich text paragraph. |
| 13 |
/// |
| 14 |
/// See [\[MS-ONE\] 2.2.23]. |
| 15 |
/// |
| 16 |
/// [\[MS-ONE\] 2.2.23]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/980fae36-b5dd-4581-bf1e-5ab54177153d |
| 17 |
#[derive(Debug)] |
| 18 |
pub(crate) struct Data { |
| 19 |
pub(crate) last_modified_time: Time, |
| 20 |
pub(crate) tight_layout: bool, |
| 21 |
pub(crate) text_run_formatting: Vec<ExGuid>, |
| 22 |
pub(crate) text_run_indices: Vec<u32>, |
| 23 |
pub(crate) text_run_data_object: Vec<ExGuid>, |
| 24 |
pub(crate) paragraph_style: ExGuid, |
| 25 |
pub(crate) paragraph_space_before: f32, |
| 26 |
pub(crate) paragraph_space_after: f32, |
| 27 |
pub(crate) paragraph_line_spacing_exact: Option<f32>, |
| 28 |
pub(crate) paragraph_alignment: ParagraphAlignment, |
| 29 |
pub(crate) text: Option<String>, |
| 30 |
pub(crate) is_title_time: bool, |
| 31 |
pub(crate) is_boiler_text: bool, |
| 32 |
pub(crate) is_title_date: bool, |
| 33 |
pub(crate) is_title_text: bool, |
| 34 |
pub(crate) layout_alignment_in_parent: Option<LayoutAlignment>, |
| 35 |
pub(crate) layout_alignment_self: Option<LayoutAlignment>, |
| 36 |
pub(crate) language_code: Option<u32>, |
| 37 |
pub(crate) rtl: bool, |
| 38 |
pub(crate) note_tags: Vec<NoteTagData>, |
| 39 |
} |
| 40 |
|
| 41 |
pub(crate) fn parse(object: &Object) -> Result<Data> { |
| 42 |
if object.id() != PropertySetId::RichTextNode.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 = |
| 50 |
Time::parse(PropertyType::LastModifiedTime, object)?.ok_or_else(|| { |
| 51 |
ErrorKind::MalformedOneNoteFileData("rich text node has no last_modified time".into()) |
| 52 |
})?; |
| 53 |
let tight_layout = |
| 54 |
simple::parse_bool(PropertyType::LayoutTightLayout, object)?.unwrap_or_default(); |
| 55 |
let text_run_formatting = |
| 56 |
ObjectReference::parse_vec(PropertyType::TextRunFormatting, object)?.unwrap_or_default(); |
| 57 |
let text_run_indices = |
| 58 |
simple::parse_vec_u32(PropertyType::TextRunIndex, object)?.unwrap_or_default(); |
| 59 |
let text_run_data_object = |
| 60 |
ObjectReference::parse_vec(PropertyType::TextRunDataObject, object)?.unwrap_or_default(); |
| 61 |
let paragraph_style = ObjectReference::parse(PropertyType::ParagraphStyle, object)? |
| 62 |
.ok_or_else(|| { |
| 63 |
ErrorKind::MalformedOneNoteFileData("rich text has no paragraph style".into()) |
| 64 |
})?; |
| 65 |
let paragraph_space_before = |
| 66 |
simple::parse_f32(PropertyType::ParagraphSpaceBefore, object)?.unwrap_or_default(); |
| 67 |
let paragraph_space_after = |
| 68 |
simple::parse_f32(PropertyType::ParagraphSpaceAfter, object)?.unwrap_or_default(); |
| 69 |
let paragraph_line_spacing_exact = |
| 70 |
simple::parse_f32(PropertyType::ParagraphLineSpacingExact, object)?; |
| 71 |
let paragraph_alignment = ParagraphAlignment::parse(object)?.unwrap_or_default(); |
| 72 |
|
| 73 |
let text = match simple::parse_string(PropertyType::RichEditTextUnicode, object)? { |
| 74 |
None => simple::parse_ascii(PropertyType::TextExtendedAscii, object)?, |
| 75 |
text => text, |
| 76 |
}; |
| 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_title_time = simple::parse_bool(PropertyType::IsTitleTime, object)?.unwrap_or_default(); |
| 83 |
let is_boiler_text = |
| 84 |
simple::parse_bool(PropertyType::IsBoilerText, object)?.unwrap_or_default(); |
| 85 |
let is_title_date = simple::parse_bool(PropertyType::IsTitleDate, object)?.unwrap_or_default(); |
| 86 |
let is_title_text = simple::parse_bool(PropertyType::IsTitleText, object)?.unwrap_or_default(); |
| 87 |
let language_code = |
| 88 |
simple::parse_u16(PropertyType::RichEditTextLangId, object)?.map(|value| value as u32); |
| 89 |
let rtl = simple::parse_bool(PropertyType::ReadingOrderRtl, object)?.unwrap_or_default(); |
| 90 |
|
| 91 |
let note_tags = NoteTagData::parse(object)?.unwrap_or_default(); |
| 92 |
|
| 93 |
let data = Data { |
| 94 |
last_modified_time, |
| 95 |
tight_layout, |
| 96 |
text_run_formatting, |
| 97 |
text_run_indices, |
| 98 |
text_run_data_object, |
| 99 |
paragraph_style, |
| 100 |
paragraph_space_before, |
| 101 |
paragraph_space_after, |
| 102 |
paragraph_line_spacing_exact, |
| 103 |
paragraph_alignment, |
| 104 |
text, |
| 105 |
is_title_time, |
| 106 |
is_boiler_text, |
| 107 |
is_title_date, |
| 108 |
is_title_text, |
| 109 |
layout_alignment_in_parent, |
| 110 |
layout_alignment_self, |
| 111 |
language_code, |
| 112 |
rtl, |
| 113 |
note_tags, |
| 114 |
}; |
| 115 |
|
| 116 |
Ok(data) |
| 117 |
} |