| 1 |
use crate::errors::{ErrorKind, Result}; |
| 2 |
use crate::one::property::ink_dimensions::InkDimension; |
| 3 |
use crate::one::property::{simple, PropertyType}; |
| 4 |
use crate::one::property_set::PropertySetId; |
| 5 |
use crate::onestore::object::Object; |
| 6 |
|
| 7 |
/// An ink stroke's properties. |
| 8 |
#[allow(dead_code)] |
| 9 |
pub(crate) struct Data { |
| 10 |
pub(crate) aliased: bool, |
| 11 |
pub(crate) fit_to_curve: bool, |
| 12 |
pub(crate) ignore_pressure: bool, |
| 13 |
pub(crate) pen_tip: Option<u8>, |
| 14 |
pub(crate) raster_operation: Option<u8>, |
| 15 |
pub(crate) transparency: Option<u8>, |
| 16 |
pub(crate) ink_height: f32, |
| 17 |
pub(crate) ink_width: f32, |
| 18 |
pub(crate) color: Option<u32>, |
| 19 |
pub(crate) dimensions: Vec<InkDimension>, |
| 20 |
} |
| 21 |
|
| 22 |
pub(crate) fn parse(object: &Object) -> Result<Data> { |
| 23 |
if object.id() != PropertySetId::StrokePropertiesNode.as_jcid() { |
| 24 |
return Err(ErrorKind::MalformedOneNoteFileData( |
| 25 |
format!("unexpected object type: 0x{:X}", object.id().0).into(), |
| 26 |
) |
| 27 |
.into()); |
| 28 |
} |
| 29 |
|
| 30 |
let aliased = simple::parse_bool(PropertyType::InkAntialised, object)?.unwrap_or_default(); |
| 31 |
let fit_to_curve = simple::parse_bool(PropertyType::InkFitToCurve, object)?.unwrap_or_default(); |
| 32 |
let ignore_pressure = |
| 33 |
simple::parse_bool(PropertyType::InkIgnorePressure, object)?.unwrap_or_default(); |
| 34 |
let pen_tip = simple::parse_u8(PropertyType::InkPenTip, object)?; |
| 35 |
let raster_operation = simple::parse_u8(PropertyType::InkRasterOperation, object)?; |
| 36 |
let transparency = simple::parse_u8(PropertyType::InkTransparency, object)?; |
| 37 |
let ink_width = simple::parse_f32(PropertyType::InkHeight, object)?.ok_or_else(|| { |
| 38 |
ErrorKind::MalformedOneNoteFileData("ink stroke properties has no height".into()) |
| 39 |
})?; |
| 40 |
let ink_height = simple::parse_f32(PropertyType::InkWidth, object)?.ok_or_else(|| { |
| 41 |
ErrorKind::MalformedOneNoteFileData("ink stroke properties has no width".into()) |
| 42 |
})?; |
| 43 |
let color = simple::parse_u32(PropertyType::InkColor, object)?; |
| 44 |
let dimensions = InkDimension::parse(PropertyType::InkDimensions, object)?; |
| 45 |
|
| 46 |
Ok(Data { |
| 47 |
aliased, |
| 48 |
fit_to_curve, |
| 49 |
ignore_pressure, |
| 50 |
pen_tip, |
| 51 |
raster_operation, |
| 52 |
transparency, |
| 53 |
ink_height, |
| 54 |
ink_width, |
| 55 |
color, |
| 56 |
dimensions, |
| 57 |
}) |
| 58 |
} |