| 1 |
use crate::errors::{ErrorKind, Result}; |
| 2 |
use crate::one::property::charset::Charset; |
| 3 |
use crate::one::property::color_ref::ColorRef; |
| 4 |
use crate::one::property::paragraph_alignment::ParagraphAlignment; |
| 5 |
use crate::one::property::{simple, PropertyType}; |
| 6 |
use crate::one::property_set::PropertySetId; |
| 7 |
use crate::onestore::object::Object; |
| 8 |
|
| 9 |
/// A paragraph style. |
| 10 |
/// |
| 11 |
/// See [\[MS-ONE\] 2.2.43] and [\[MS-ONE\] 2.2.44] |
| 12 |
/// |
| 13 |
/// [\[MS-ONE\] 2.2.43]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/38eb9b74-cfaf-4df7-b061-a83968c7ff5b |
| 14 |
/// [\[MS-ONE\] 2.2.44]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/f0baabae-f42a-42e0-8cb2-869d420e865f |
| 15 |
#[derive(Debug)] |
| 16 |
pub(crate) struct Data { |
| 17 |
pub(crate) charset: Option<Charset>, |
| 18 |
pub(crate) bold: bool, |
| 19 |
pub(crate) italic: bool, |
| 20 |
pub(crate) underline: bool, |
| 21 |
pub(crate) strikethrough: bool, |
| 22 |
pub(crate) superscript: bool, |
| 23 |
pub(crate) subscript: bool, |
| 24 |
pub(crate) font: Option<String>, |
| 25 |
pub(crate) font_size: Option<u16>, |
| 26 |
pub(crate) font_color: Option<ColorRef>, |
| 27 |
pub(crate) highlight: Option<ColorRef>, |
| 28 |
pub(crate) next_style: Option<String>, |
| 29 |
pub(crate) style_id: Option<String>, |
| 30 |
pub(crate) paragraph_alignment: Option<ParagraphAlignment>, |
| 31 |
pub(crate) paragraph_space_before: Option<f32>, |
| 32 |
pub(crate) paragraph_space_after: Option<f32>, |
| 33 |
pub(crate) paragraph_line_spacing_exact: Option<f32>, |
| 34 |
pub(crate) language_code: Option<u32>, |
| 35 |
pub(crate) math_formatting: bool, |
| 36 |
pub(crate) hyperlink: bool, |
| 37 |
pub(crate) hyperlink_protected: bool, |
| 38 |
pub(crate) hidden: bool, |
| 39 |
pub(crate) text_run_is_embedded_object: bool, |
| 40 |
pub(crate) text_run_object_type: Option<u32>, |
| 41 |
} |
| 42 |
|
| 43 |
pub(crate) fn parse(object: &Object) -> Result<Data> { |
| 44 |
if object.id() != PropertySetId::ParagraphStyleObject.as_jcid() { |
| 45 |
return Err(ErrorKind::MalformedOneNoteFileData( |
| 46 |
format!("unexpected object type: 0x{:X}", object.id().0).into(), |
| 47 |
) |
| 48 |
.into()); |
| 49 |
} |
| 50 |
|
| 51 |
let charset = Charset::parse(PropertyType::Charset, object)?; |
| 52 |
let bold = simple::parse_bool(PropertyType::Bold, object)?.unwrap_or_default(); |
| 53 |
let italic = simple::parse_bool(PropertyType::Italic, object)?.unwrap_or_default(); |
| 54 |
let underline = simple::parse_bool(PropertyType::Underline, object)?.unwrap_or_default(); |
| 55 |
let strikethrough = |
| 56 |
simple::parse_bool(PropertyType::Strikethrough, object)?.unwrap_or_default(); |
| 57 |
let superscript = simple::parse_bool(PropertyType::Superscript, object)?.unwrap_or_default(); |
| 58 |
let subscript = simple::parse_bool(PropertyType::Subscript, object)?.unwrap_or_default(); |
| 59 |
let font = simple::parse_string(PropertyType::Font, object)?; |
| 60 |
let font_size = simple::parse_u16(PropertyType::FontSize, object)?; |
| 61 |
let font_color = ColorRef::parse(PropertyType::FontColor, object)?; |
| 62 |
let highlight = ColorRef::parse(PropertyType::Highlight, object)?; |
| 63 |
let next_style = simple::parse_string(PropertyType::NextStyle, object)?; |
| 64 |
let style_id = simple::parse_string(PropertyType::ParagraphStyleId, object)?; |
| 65 |
let paragraph_alignment = ParagraphAlignment::parse(object)?; |
| 66 |
let paragraph_space_before = simple::parse_f32(PropertyType::ParagraphSpaceBefore, object)?; |
| 67 |
let paragraph_space_after = simple::parse_f32(PropertyType::ParagraphSpaceAfter, object)?; |
| 68 |
let paragraph_line_spacing_exact = |
| 69 |
simple::parse_f32(PropertyType::ParagraphLineSpacingExact, object)?; |
| 70 |
let language_code = simple::parse_u32(PropertyType::LanguageId, object)?; |
| 71 |
let math_formatting = |
| 72 |
simple::parse_bool(PropertyType::MathFormatting, object)?.unwrap_or_default(); |
| 73 |
let hyperlink = simple::parse_bool(PropertyType::Hyperlink, object)?.unwrap_or_default(); |
| 74 |
let hyperlink_protected = |
| 75 |
simple::parse_bool(PropertyType::HyperlinkProtected, object)?.unwrap_or_default(); |
| 76 |
let hidden = simple::parse_bool(PropertyType::Hidden, object)?.unwrap_or_default(); |
| 77 |
let text_run_is_embedded_object = |
| 78 |
simple::parse_bool(PropertyType::TextRunIsEmbeddedObject, object)?.unwrap_or_default(); |
| 79 |
let text_run_object_type = simple::parse_u32(PropertyType::EmbeddedObjectType, object)?; |
| 80 |
|
| 81 |
let data = Data { |
| 82 |
charset, |
| 83 |
bold, |
| 84 |
italic, |
| 85 |
underline, |
| 86 |
strikethrough, |
| 87 |
superscript, |
| 88 |
subscript, |
| 89 |
font, |
| 90 |
font_size, |
| 91 |
font_color, |
| 92 |
highlight, |
| 93 |
next_style, |
| 94 |
style_id, |
| 95 |
paragraph_alignment, |
| 96 |
paragraph_space_before, |
| 97 |
paragraph_space_after, |
| 98 |
paragraph_line_spacing_exact, |
| 99 |
language_code, |
| 100 |
math_formatting, |
| 101 |
hyperlink, |
| 102 |
hyperlink_protected, |
| 103 |
hidden, |
| 104 |
text_run_is_embedded_object, |
| 105 |
text_run_object_type, |
| 106 |
}; |
| 107 |
|
| 108 |
Ok(data) |
| 109 |
} |