| 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 |
/// A table. |
| 12 |
/// |
| 13 |
/// See [\[MS-ONE\] 2.2.26]. |
| 14 |
/// |
| 15 |
/// [\[MS-ONE\] 2.2.26]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/9046980a-2410-4b2d-8a35-ec06e55648e0 |
| 16 |
#[derive(Debug)] |
| 17 |
pub(crate) struct Data { |
| 18 |
pub(crate) last_modified: Time, |
| 19 |
pub(crate) rows: Vec<ExGuid>, |
| 20 |
pub(crate) row_count: u32, |
| 21 |
pub(crate) col_count: u32, |
| 22 |
pub(crate) cols_locked: Vec<u8>, |
| 23 |
pub(crate) col_widths: Vec<f32>, |
| 24 |
pub(crate) borders_visible: bool, |
| 25 |
pub(crate) layout_alignment_in_parent: Option<LayoutAlignment>, |
| 26 |
pub(crate) layout_alignment_self: Option<LayoutAlignment>, |
| 27 |
pub(crate) note_tags: Vec<NoteTagData>, |
| 28 |
} |
| 29 |
|
| 30 |
pub(crate) fn parse(object: &Object) -> Result<Data> { |
| 31 |
if object.id() != PropertySetId::TableNode.as_jcid() { |
| 32 |
return Err(ErrorKind::MalformedOneNoteFileData( |
| 33 |
format!("unexpected object type: 0x{:X}", object.id().0).into(), |
| 34 |
) |
| 35 |
.into()); |
| 36 |
} |
| 37 |
|
| 38 |
let last_modified = Time::parse(PropertyType::LastModifiedTime, object)?.ok_or_else(|| { |
| 39 |
ErrorKind::MalformedOneNoteFileData("table has no last modified time".into()) |
| 40 |
})?; |
| 41 |
let rows = ObjectReference::parse_vec(PropertyType::ElementChildNodes, object)? |
| 42 |
.ok_or_else(|| ErrorKind::MalformedOneNoteFileData("table has no rows".into()))?; |
| 43 |
let row_count = simple::parse_u32(PropertyType::RowCount, object)? |
| 44 |
.ok_or_else(|| ErrorKind::MalformedOneNoteFileData("table has no row count".into()))?; |
| 45 |
let col_count = simple::parse_u32(PropertyType::ColumnCount, object)? |
| 46 |
.ok_or_else(|| ErrorKind::MalformedOneNoteFileData("table has no col count".into()))?; |
| 47 |
let cols_locked = simple::parse_vec(PropertyType::TableColumnsLocked, object)? |
| 48 |
.map(|value| value.into_iter().skip(1).collect()) |
| 49 |
.unwrap_or_default(); |
| 50 |
let col_widths = simple::parse_vec(PropertyType::TableColumnWidths, object)? |
| 51 |
.map(|value| { |
| 52 |
value |
| 53 |
.into_iter() |
| 54 |
.skip(1) |
| 55 |
.collect::<Vec<_>>() |
| 56 |
.chunks_exact(4) |
| 57 |
.map(|v| f32::from_le_bytes([v[0], v[1], v[2], v[3]])) |
| 58 |
.collect() |
| 59 |
}) |
| 60 |
.unwrap_or_default(); |
| 61 |
let borders_visible = |
| 62 |
simple::parse_bool(PropertyType::TableBordersVisible, object)?.unwrap_or(true); |
| 63 |
let layout_alignment_in_parent = |
| 64 |
LayoutAlignment::parse(PropertyType::LayoutAlignmentInParent, object)?; |
| 65 |
let layout_alignment_self = LayoutAlignment::parse(PropertyType::LayoutAlignmentSelf, object)?; |
| 66 |
|
| 67 |
let note_tags = NoteTagData::parse(object)?.unwrap_or_default(); |
| 68 |
|
| 69 |
let data = Data { |
| 70 |
last_modified, |
| 71 |
rows, |
| 72 |
row_count, |
| 73 |
col_count, |
| 74 |
cols_locked, |
| 75 |
col_widths, |
| 76 |
borders_visible, |
| 77 |
layout_alignment_in_parent, |
| 78 |
layout_alignment_self, |
| 79 |
note_tags, |
| 80 |
}; |
| 81 |
|
| 82 |
Ok(data) |
| 83 |
} |