use crate::errors::ErrorKind;
use crate::one::property_set::math_inline_object::Data;
use enum_primitive_derive::Primitive;
use num_traits::FromPrimitive;
#[derive(Copy, Clone, Debug, PartialEq, Primitive)]
#[repr(u32)]
#[derive(Default)]
pub enum MathObjectType {
#[default]
SimpleText = 0,
Accent = 10,
Box = 11,
BoxedFormula = 12,
Brackets = 13,
BracketsWithSeps = 14,
EquationArray = 15,
Fraction = 16,
FunctionApply = 17,
LeftSubSup = 18,
LowerLimit = 19,
Matrix = 20,
Nary = 21,
OpChar = 22,
Overbar = 23,
Phantom = 24,
Radical = 25,
SlashedFraction = 26,
Stack = 27,
StretchStack = 28,
Subscript = 29,
SubSup = 30,
Superscript = 31,
Underbar = 32,
UpperLimit = 33,
PlainText = 0x90000000u32,
}
#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct MathInlineObject {
pub(crate) object_type: MathObjectType,
pub(crate) arg_count: u32,
pub(crate) column: Option<u8>,
pub(crate) align: Option<u8>,
pub(crate) char: Option<char>,
pub(crate) char1: Option<char>,
pub(crate) char2: Option<char>,
}
impl MathInlineObject {
pub fn object_type(&self) -> MathObjectType {
self.object_type
}
pub fn arg_count(&self) -> u32 {
self.arg_count
}
pub fn column(&self) -> Option<u8> {
self.column
}
pub fn align(&self) -> Option<u8> {
self.align
}
pub fn char(&self) -> Option<char> {
self.char
}
pub fn char1(&self) -> Option<char> {
self.char1
}
pub fn char2(&self) -> Option<char> {
self.char2
}
}
pub(crate) fn parse_math_inline_object(data: Data) -> crate::errors::Result<MathInlineObject> {
let object_type = MathObjectType::from_u32(data.object_type.unwrap_or(0)).ok_or_else(|| {
ErrorKind::MalformedOneNoteFileData(
format!("MathInlineObject has invalid type: {:?}", data.object_type).into(),
)
})?;
Ok(MathInlineObject {
object_type,
arg_count: data.arg_count.unwrap_or(0),
column: data.column,
align: data.align,
char: data.char,
char1: data.char1,
char2: data.char2,
})
}