From 6cf2d6882444d32740b9c1b6988847f531c1d3f6 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Sun, 19 Jul 2026 02:39:42 +0300 Subject: [PATCH] fix(mtext): a blank line takes the surrounding text height An empty `\P` paragraph carries no glyph to size it, so the per-line advance fell back to the full entity height. In a small-text block (a `\H0.2x` column) that blew a single blank line up to several times the height of the text around it, shoving everything below it far down the page. Size a glyph-less line by the last non-empty line's height instead. Co-Authored-By: Claude Opus 4.8 --- src/entities/text_support.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/entities/text_support.rs b/src/entities/text_support.rs index bdadd05b5..376eaa5b6 100644 --- a/src/entities/text_support.rs +++ b/src/entities/text_support.rs @@ -1266,6 +1266,11 @@ pub fn layout_mtext(opts: &MTextRenderOpts) -> MTextLayout { // otherwise a small line still leaves a full-height gap and the block // grows several times too tall. Accumulated per column (columns stack // independently). Uniform-height text reduces to the constant `line_h`. + // A blank line (an empty `\P` paragraph) carries no glyph to size it, so it + // takes the height of the text around it — the last non-empty line — not the + // full entity height, which would blow a small-text blank line up several + // times too tall and shove everything below it down the page. + let mut last_line_h = entity_h; let per_line_h: Vec = sub_lines .iter() .map(|s| { @@ -1277,7 +1282,12 @@ pub fn layout_mtext(opts: &MTextRenderOpts) -> MTextLayout { _ => None, }) .fold(0.0_f32, f32::max); - let mh = if mh > 0.0 { mh } else { entity_h }; + let mh = if mh > 0.0 { + last_line_h = mh; + mh + } else { + last_line_h + }; // A paragraph's own `\psm#`/`\pse#` overrides the entity factor for // its lines; `Exact` fixes the baseline gap outright. match s.line_spacing {