From d55f4e4059fda553f0da6b153b857c3c27d10fa7 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 01:44:18 +0800 Subject: [PATCH] Paint bitmap math accents before their base glyph --- src/rust_typeset/math_layout.rs | 14 ++++++++------ tests/typeset.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/rust_typeset/math_layout.rs b/src/rust_typeset/math_layout.rs index f09b0fd..0685bf0 100644 --- a/src/rust_typeset/math_layout.rs +++ b/src/rust_typeset/math_layout.rs @@ -4089,17 +4089,19 @@ fn layout_math_accent_paint( gap: f64::from(gap), extra_space: f64::from(extra_space), }); - let mut items = vec![MathItem::Child { + // Accent bitmaps have an opaque white background; draw the accent first + // so the nucleus paints over it instead of being clipped by it. + let mut items = vec![paint.item(MathPosition { + x: Mm::from(layout.accent_position.x), + y: Mm::from(layout.accent_position.y), + })]; + items.push(MathItem::Child { layout: Rc::new(body), position: MathPosition { x: Mm::from(layout.body_position.x), y: Mm::from(layout.body_position.y), }, - }]; - items.push(paint.item(MathPosition { - x: Mm::from(layout.accent_position.x), - y: Mm::from(layout.accent_position.y), - })); + }); MathBox { size: MathSize { width: Mm::from(layout.width), diff --git a/tests/typeset.rs b/tests/typeset.rs index e960056..a22492f 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -1838,6 +1838,33 @@ See \eqref{eq:x}. $\bar{x}+\vec{v}$. assert_eq!(value["status"], "ok"); } +#[test] +fn accent_images_paint_before_their_base_glyph() { + let source = "\\documentclass{article}\n\\begin{document}\n$\\widetilde{M}$\n\\end{document}\n"; + let value = fresh_preview(source, "accent-order.tex"); + assert_eq!(value["status"], "ok"); + let svg = page_svg(&value, 0); + let mut starts = svg.match_indices("").expect("image tag should close"); + &svg[start..start + end] + }; + let y_of = |tag: &str| { + let offset = tag.find(" y=\"").expect("image tag should have y") + 4; + let rest = &tag[offset..]; + let end = rest.find('"').expect("y attribute should close"); + rest[..end].parse::().expect("y should be numeric") + }; + let accent_y = y_of(tag(first)); + let base_y = y_of(tag(second)); + assert!( + accent_y < base_y, + "bitmap accents must be painted above the base glyph: accent={accent_y}, base={base_y}" + ); +} + #[test] fn geometry_text_sets_the_text_block() { let source = "\\documentclass{article}\n\\usepackage[text={100mm,150mm}]{geometry}\n\\begin{document}\nBody\n\\end{document}\n";