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 <noreply@anthropic.com>
This commit is contained in:
parent
b2720987a7
commit
6cf2d68824
1 changed files with 11 additions and 1 deletions
|
|
@ -1266,6 +1266,11 @@ pub fn layout_mtext(opts: &MTextRenderOpts) -> MTextLayout {
|
||||||
// otherwise a small line still leaves a full-height gap and the block
|
// otherwise a small line still leaves a full-height gap and the block
|
||||||
// grows several times too tall. Accumulated per column (columns stack
|
// grows several times too tall. Accumulated per column (columns stack
|
||||||
// independently). Uniform-height text reduces to the constant `line_h`.
|
// 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<f32> = sub_lines
|
let per_line_h: Vec<f32> = sub_lines
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
|
|
@ -1277,7 +1282,12 @@ pub fn layout_mtext(opts: &MTextRenderOpts) -> MTextLayout {
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.fold(0.0_f32, f32::max);
|
.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
|
// A paragraph's own `\psm#`/`\pse#` overrides the entity factor for
|
||||||
// its lines; `Exact` fixes the baseline gap outright.
|
// its lines; `Exact` fixes the baseline gap outright.
|
||||||
match s.line_spacing {
|
match s.line_spacing {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue