Skip to content

Align text on a common baseline and keep the line strut - #272

Merged
eXpl0it3r merged 1 commit into
masterfrom
fix/line-baseline-strut
Nov 9, 2026
Merged

eXpl0it3r merged 1 commit into
masterfrom
fix/line-baseline-strut

Conversation

@eXpl0it3r

@eXpl0it3r eXpl0it3r commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

While going through the updated "Line break" baseline from #270, the two "Release" lines in the heading looked off. Compared against Edge, the spacing itself is right, every line in the <h1> is as tall as the heading's font, but two things weren't:

  • Smaller text hung from the top of the line instead of sitting on the baseline. ApplyVerticalAlignment called the highest top of the line the "baseline", so mixed font sizes were effectively top aligned.
  • A line with only smaller text was just as tall as that text, the block's own font (the strut, CSS 2.1 10.8.1) was never taken into account. As such the last "Release" line was too short.

Text words of a line now share one baseline, taken from the largest ascent of the words and the block's own font, and a line with text is at least as tall as the block's font. The line box keeps the strut, so it also survives the pagination pass and OffsetTop. Words inside sub/super keep their existing handling, and images and image-only lines aren't touched for now, to keep the change contained.

With the same heading, Edge renders four lines of 43px with the "Release" lines at 66-81 and 150-167, HTML Renderer now renders four lines of 40px with them at 62-73 and 140-154.

Five baselines changed, all of them lines with mixed font sizes:

  • Line break: the heading gets its four full-height lines
  • Text: the text after the big "Warning:" sits on its baseline
  • Fonts decorations: the | separators line up with the @font-face text
  • MaxWidth and Media queries and color scheme: the inline monospace code moves down by 1-2px onto the baseline

How to test this PR?

CI should succeed. LineBaselineIntegrationTests covers the baseline and the strut, and fails on master.

- Put text of different sizes in a line on one baseline instead of aligning it to the top
- Make a line with text at least as tall as the block's own font, also through pagination
- Update the five baselines with mixed font sizes in a line
@eXpl0it3r
eXpl0it3r merged commit 9aa6735 into master Nov 9, 2026
18 checks passed
@eXpl0it3r
eXpl0it3r deleted the fix/line-baseline-strut branch November 9, 2026 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant