Add the mathstrut item

This commit is contained in:
gloamxun committed 2026-10-20 13:36:37 +08:00
1 parent 69e80f6060
commit bdf3279aed
2 files changed
+19

No files matched your search

+17
View File
@@ -46,6 +46,7 @@ pub enum MathAtom {
horizontal: bool,
vertical: bool,
},
Strut,
Limits {
base: Box<MathAtom>,
sub: Option<Box<MathAtom>>,
@@ -263,6 +264,11 @@ pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox {
depth: if *bottom { 0 } else { body.depth },
}
}
MathAtom::Strut => MathBox {
width: 0,
height: 7 * 65_536,
depth: 2 * 65_536,
},
MathAtom::Phantom {
body,
horizontal,
@@ -630,6 +636,7 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
after,
)
}
"mathstrut" => (MathAtom::Strut, next),
"phantom" | "hphantom" | "vphantom" => {
let (body, after) = parse_atom(chars, next);
(
@@ -1002,6 +1009,16 @@ mod tests {
assert_eq!(smashed.height, 0);
assert_eq!(smashed.depth, 0);
}
#[test]
fn mathstrut_has_zero_width_and_math_height() {
let font = Cmr10Metrics::default();
let box_ = layout_math(&parse_math(r"\mathstrut"), &font);
assert_eq!(box_.width, 0);
assert_eq!(box_.height, 7 * 65_536);
assert_eq!(box_.depth, 2 * 65_536);
}
#[test]
fn phantoms_keep_only_selected_dimensions() {
let font = Cmr10Metrics::default();
+2
View File
@@ -243,3 +243,5 @@ v1 remains the production renderer; the route-D core is additive and tested inde
`Unit::mark(id, class, text)` and `Unit::float(id, placement, width, height)` are convenience constructors for M2 page items.
`\mathop` uses the Op spacing class (3mu against ordinary atoms).
`\mathstrut` is a zero-width strut with 7pt height and 2pt depth.