use crate::formula::omml::elements::ElementProperties;
use crate::formula::omml::attributes::*;
#[allow(dead_code)] pub fn parse_run_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"scr" | "m:scr" => {
properties.math_variant = Some(value.to_string());
properties.style = Some(value.to_string());
}
"sty" | "m:sty" => {
properties.display_style = Some(matches!(value, "d" | "display" | "1" | "true"));
properties.run_math_style = Some(value.to_string());
}
"nor" | "m:nor" => {
properties.font = Some(value.to_string());
properties.run_normal_text = Some(value.to_string());
}
"lit" | "m:lit" => {
properties.run_literal = Some(matches!(value, "1" | "true"));
}
_ => {}
}
}
}
properties
}
pub fn parse_fraction_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"type" | "m:type" => {
properties.fraction_type = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
pub fn parse_delimiter_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"begChr" | "m:begChr" => {
properties.delimiter_open_char = Some(value.to_string());
}
"endChr" | "m:endChr" => {
properties.delimiter_close_char = Some(value.to_string());
}
"sepChr" | "m:sepChr" => {
properties.delimiter_separator_char = Some(value.to_string());
}
"grow" | "m:grow" => {
properties.delimiter_grow = Some(matches!(value, "1" | "true"));
}
"shp" | "m:shp" => {
properties.delimiter_shape = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
pub fn parse_nary_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"chr" | "m:chr" => {
properties.chr = Some(value.to_string());
}
"grow" | "m:grow" => {
properties.nary_operator_grow = Some(matches!(value, "1" | "true"));
}
"subHide" | "m:subHide" => {
properties.nary_hide_sub = Some(matches!(value, "1" | "true"));
}
"supHide" | "m:supHide" => {
properties.nary_hide_sup = Some(matches!(value, "1" | "true"));
}
"limLoc" | "m:limLoc" => {
properties.style = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
pub fn parse_accent_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"chr" | "m:chr" => {
properties.chr = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
pub fn parse_matrix_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"baseJc" | "m:baseJc" => {
properties.matrix_alignment = Some(value.to_string());
}
"plcHide" | "m:plcHide" => {
properties.hide = Some(matches!(value, "1" | "true"));
}
"rSp" | "m:rSp" => {
properties.matrix_row_spacing = Some(value.to_string());
}
"cSp" | "m:cSp" => {
properties.matrix_column_spacing = Some(value.to_string());
}
"cGp" | "m:cGp" => {
properties.spacing = Some(value.to_string());
}
"mcs" | "m:mcs" => {
properties.spacing = Some(value.to_string());
}
"mcsJc" | "m:mcsJc" => {
properties.alignment = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
pub fn parse_group_char_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"chr" | "m:chr" => {
properties.chr = Some(value.to_string());
}
"pos" | "m:pos" => {
properties.accent_position = Some(value.to_string());
}
"vertJc" | "m:vertJc" => {
properties.vertical_alignment = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
pub fn parse_eq_arr_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"baseJc" | "m:baseJc" => {
properties.eq_arr_base_alignment = Some(value.to_string());
}
"maxDist" | "m:maxDist" => {
properties.eq_arr_max_distance = Some(value.to_string());
}
"objDist" | "m:objDist" => {
properties.eq_arr_object_distance = Some(value.to_string());
}
"rSp" | "m:rSp" => {
properties.eq_arr_row_spacing = Some(value.to_string());
}
"rSpRule" | "m:rSpRule" => {
properties.eq_arr_row_spacing_rule = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
pub fn parse_limit_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"type" | "m:type" => {
properties.style = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
pub fn parse_bar_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"pos" | "m:pos" => {
properties.accent_position = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
pub fn parse_box_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"opEmu" | "m:opEmu" => {
properties.box_operator_emulation = Some(matches!(value, "1" | "true"));
}
"noBreak" | "m:noBreak" => {
properties.box_no_break = Some(matches!(value, "1" | "true"));
}
"diff" | "m:diff" => {
properties.box_differential = Some(matches!(value, "1" | "true"));
}
"brk" | "m:brk" => {
properties.box_break = Some(matches!(value, "1" | "true"));
}
"aln" | "m:aln" => {
properties.box_alignment = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
pub fn parse_border_box_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"hideTop" | "m:hideTop" => {
properties.border_hide_top = Some(matches!(value, "1" | "true"));
}
"hideBot" | "m:hideBot" => {
properties.border_hide_bottom = Some(matches!(value, "1" | "true"));
}
"hideLeft" | "m:hideLeft" => {
properties.border_hide_left = Some(matches!(value, "1" | "true"));
}
"hideRight" | "m:hideRight" => {
properties.border_hide_right = Some(matches!(value, "1" | "true"));
}
"strikeH" | "m:strikeH" => {
properties.border_strike_horizontal = Some(matches!(value, "1" | "true"));
}
"strikeV" | "m:strikeV" => {
properties.border_strike_vertical = Some(matches!(value, "1" | "true"));
}
"strikeBLTR" | "m:strikeBLTR" => {
properties.border_strike_bltr = Some(matches!(value, "1" | "true"));
}
"strikeTLBR" | "m:strikeTLBR" => {
properties.border_strike_tlbr = Some(matches!(value, "1" | "true"));
}
_ => {}
}
}
}
properties
}
pub fn parse_phantom_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"show" | "m:show" => {
properties.phantom_show = Some(matches!(value, "1" | "true"));
}
"zeroWid" | "m:zeroWid" => {
properties.phantom_zero_width = Some(matches!(value, "1" | "true"));
}
"zeroAsc" | "m:zeroAsc" => {
properties.phantom_zero_ascent = Some(matches!(value, "1" | "true"));
}
"zeroDesc" | "m:zeroDesc" => {
properties.phantom_zero_descent = Some(matches!(value, "1" | "true"));
}
"transp" | "m:transp" => {
properties.phantom_transparent = Some(matches!(value, "1" | "true"));
}
_ => {}
}
}
}
properties
}
pub fn parse_radical_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"degHide" | "m:degHide" => {
properties.radical_hide_degree = Some(matches!(value, "1" | "true"));
}
_ => {}
}
}
}
properties
}
pub fn parse_spacing_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"val" | "m:val" => {
properties.spacing = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
#[allow(dead_code)] pub fn parse_subscript_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"degHide" | "m:degHide" => {
properties.hide = Some(matches!(value, "1" | "true"));
}
_ => {}
}
}
}
properties
}
#[allow(dead_code)] pub fn parse_superscript_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"degHide" | "m:degHide" => {
properties.hide = Some(matches!(value, "1" | "true"));
}
_ => {}
}
}
}
properties
}
#[allow(dead_code)] pub fn parse_subsup_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"subHide" | "m:subHide" => {
properties.nary_hide_sub = Some(matches!(value, "1" | "true"));
}
"supHide" | "m:supHide" => {
properties.nary_hide_sup = Some(matches!(value, "1" | "true"));
}
"aln" | "m:aln" => {
properties.alignment = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
#[allow(dead_code)] pub fn parse_prescript_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"subHide" | "m:subHide" => {
properties.nary_hide_sub = Some(matches!(value, "1" | "true"));
}
"supHide" | "m:supHide" => {
properties.nary_hide_sup = Some(matches!(value, "1" | "true"));
}
_ => {}
}
}
}
properties
}
#[allow(dead_code)] pub fn parse_function_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"type" | "m:type" => {
properties.style = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
#[allow(dead_code)] pub fn parse_upper_limit_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"limLoc" | "m:limLoc" => {
properties.style = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
#[allow(dead_code)] pub fn parse_lower_limit_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"limLoc" | "m:limLoc" => {
properties.style = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
#[allow(dead_code)] pub fn parse_control_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"ascii" | "m:ascii" => {
properties.font = Some(value.to_string());
}
"hAnsi" | "m:hAnsi" => {
properties.font = Some(value.to_string());
}
"cs" | "m:cs" => {
properties.font = Some(value.to_string());
}
"eastAsia" | "m:eastAsia" => {
properties.font = Some(value.to_string());
}
_ => {}
}
}
}
properties
}
pub fn parse_general_properties(attrs: &[quick_xml::events::attributes::Attribute]) -> ElementProperties {
let mut properties = ElementProperties::default();
for attr in attrs {
if let Ok(key) = std::str::from_utf8(attr.key.as_ref())
&& let Ok(value) = std::str::from_utf8(&attr.value) {
match key {
"scr" | "m:scr" => properties.math_variant = Some(value.to_string()),
"sty" | "m:sty" => properties.display_style = Some(matches!(value, "d" | "display" | "1" | "true")),
"sz" | "m:sz" => properties.size = Some(value.to_string()),
"minSz" | "m:minSz" => properties.min_size = Some(value.to_string()),
"maxSz" | "m:maxSz" => properties.max_size = Some(value.to_string()),
"scrLvl" | "m:scrLvl" => {
if let Some(lvl) = parse_int_simd(value) {
properties.script_level = Some(lvl);
}
}
"color" | "m:color" => properties.color = Some(value.to_string()),
"font" | "m:font" => properties.font = Some(value.to_string()),
"nor" | "m:nor" => properties.font = Some(value.to_string()),
"aln" | "m:aln" => properties.alignment = Some(value.to_string()),
"alnScr" | "m:alnScr" => properties.alignment = Some(value.to_string()),
"vertJc" | "m:vertJc" => properties.vertical_alignment = Some(value.to_string()),
"baseJc" | "m:baseJc" => properties.alignment = Some(value.to_string()),
"chr" | "m:chr" => properties.chr = Some(value.to_string()),
"val" | "m:val" => properties.spacing = Some(value.to_string()),
"type" | "m:type" => properties.fraction_type = Some(value.to_string()),
"lnThick" | "m:lnThick" => properties.fraction_line_thickness = Some(value.to_string()),
"rSp" | "m:rSp" => properties.matrix_row_spacing = Some(value.to_string()),
"cSp" | "m:cSp" => properties.matrix_column_spacing = Some(value.to_string()),
"pos" | "m:pos" => properties.accent_position = Some(value.to_string()),
"diff" | "m:diff" => properties.box_differential = Some(matches!(value, "1" | "true")),
"opEmu" | "m:opEmu" => properties.box_operator_emulation = Some(matches!(value, "1" | "true")),
"brk" | "m:brk" => properties.box_break = Some(matches!(value, "1" | "true")),
"noBreak" | "m:noBreak" => properties.box_no_break = Some(matches!(value, "1" | "true")),
"show" | "m:show" => properties.phantom_show = Some(matches!(value, "1" | "true")),
"zeroWid" | "m:zeroWid" => properties.phantom_zero_width = Some(matches!(value, "1" | "true")),
"zeroAsc" | "m:zeroAsc" => properties.phantom_zero_ascent = Some(matches!(value, "1" | "true")),
"zeroDesc" | "m:zeroDesc" => properties.phantom_zero_descent = Some(matches!(value, "1" | "true")),
"transp" | "m:transp" => properties.phantom_transparent = Some(matches!(value, "1" | "true")),
"hideTop" | "m:hideTop" => properties.border_hide_top = Some(matches!(value, "1" | "true")),
"hideBot" | "m:hideBot" => properties.border_hide_bottom = Some(matches!(value, "1" | "true")),
"hideLeft" | "m:hideLeft" => properties.border_hide_left = Some(matches!(value, "1" | "true")),
"hideRight" | "m:hideRight" => properties.border_hide_right = Some(matches!(value, "1" | "true")),
"strikeH" | "m:strikeH" => properties.border_strike_horizontal = Some(matches!(value, "1" | "true")),
"strikeV" | "m:strikeV" => properties.border_strike_vertical = Some(matches!(value, "1" | "true")),
"strikeBLTR" | "m:strikeBLTR" => properties.border_strike_bltr = Some(matches!(value, "1" | "true")),
"strikeTLBR" | "m:strikeTLBR" => properties.border_strike_tlbr = Some(matches!(value, "1" | "true")),
"maxDist" | "m:maxDist" => properties.eq_arr_max_distance = Some(value.to_string()),
"objDist" | "m:objDist" => properties.eq_arr_object_distance = Some(value.to_string()),
"rSpRule" | "m:rSpRule" => properties.eq_arr_row_spacing_rule = Some(value.to_string()),
"subHide" | "m:subHide" => properties.nary_hide_sub = Some(matches!(value, "1" | "true")),
"supHide" | "m:supHide" => properties.nary_hide_sup = Some(matches!(value, "1" | "true")),
"grow" | "m:grow" => properties.nary_operator_grow = Some(matches!(value, "1" | "true")),
"sepChr" | "m:sepChr" => properties.delimiter_separator_char = Some(value.to_string()),
"begChr" | "m:begChr" => properties.delimiter_open_char = Some(value.to_string()),
"endChr" | "m:endChr" => properties.delimiter_close_char = Some(value.to_string()),
"shp" | "m:shp" => properties.delimiter_shape = Some(value.to_string()),
"degHide" | "m:degHide" => properties.radical_hide_degree = Some(matches!(value, "1" | "true")),
"lit" | "m:lit" => properties.run_literal = Some(matches!(value, "1" | "true")),
"hide" | "m:hide" => properties.hide = Some(matches!(value, "1" | "true")),
"strike" | "m:strike" => properties.strike_through = Some(matches!(value, "1" | "true")),
"dstrike" | "m:dstrike" => properties.double_strike_through = Some(matches!(value, "1" | "true")),
"u" | "m:u" => properties.underline = Some(value.to_string()),
"o" | "m:o" => properties.overline = Some(value.to_string()),
"den" | "m:den" => properties.alignment = Some("denominator".to_string()),
"num" | "m:num" => properties.alignment = Some("numerator".to_string()),
_ => {} }
}
}
properties
}