use crate::renderer::equation::layout::{LayoutBox, LayoutKind};
use crate::renderer::equation::GlyphOutlineCommand;
fn delimiter(
layout: &LayoutBox,
text: &str,
width: f64,
x: f64,
outline: &Option<Vec<GlyphOutlineCommand>>,
right_side: bool,
) -> LayoutBox {
let kind = if let Some(outline) = outline {
LayoutKind::FontGlyph {
text: text.to_owned(),
font_family: "Latin Modern Math, STIX Two Math, serif",
outline: Some(outline.clone()),
paint: None,
}
} else {
let LayoutKind::Paren {
delimiter_height,
glyph_delimiters,
..
} = &layout.kind
else {
unreachable!()
};
LayoutKind::Paren {
left: if right_side {
String::new()
} else {
text.to_owned()
},
right: if right_side {
text.to_owned()
} else {
String::new()
},
left_width: if right_side { 0.0 } else { width },
right_width: if right_side { width } else { 0.0 },
delimiter_height: *delimiter_height,
glyph_delimiters: *glyph_delimiters,
left_outline: None,
right_outline: None,
body: Box::new(LayoutBox {
x: 0.0,
y: 0.0,
width: 0.0,
height: 0.0,
baseline: 0.0,
font_size: layout.font_size,
kind: LayoutKind::Empty,
}),
}
};
LayoutBox {
x,
y: 0.0,
width,
height: layout.height,
baseline: layout.baseline,
font_size: layout.font_size,
kind,
}
}
pub(super) fn write_kind(buf: &mut String, layout: &LayoutBox) -> bool {
let LayoutKind::Paren {
left,
right,
left_width,
right_width,
left_outline,
right_outline,
body,
..
} = &layout.kind
else {
return false;
};
if left_outline.is_none() && right_outline.is_none() {
return false;
}
buf.push_str("{\"type\":\"row\",\"children\":[");
if !left.is_empty() {
super::write_equation_layout_box(
buf,
&delimiter(layout, left, *left_width, 0.0, left_outline, false),
);
buf.push(',');
}
super::write_equation_layout_box(buf, body);
if !right.is_empty() {
buf.push(',');
super::write_equation_layout_box(
buf,
&delimiter(
layout,
right,
*right_width,
layout.width - right_width,
right_outline,
true,
),
);
}
buf.push_str("]}");
true
}