Skip to content

fix(theme): keep hard-broken lines at the body line height - #256

Merged
Bill Traynor (wmat) merged 2 commits into
mainfrom
fix/hard-break-line-spacing
Aug 28, 2026
Merged

Bill Traynor (wmat) merged 2 commits into
mainfrom
fix/hard-break-line-spacing

Conversation

@wmat

Copy link
Copy Markdown
Collaborator

Fixes riscv/docs-spec-template#118

Problem

Hard line breaks render with uneven vertical spacing: every line in a broken block
except the last one appears to sit slightly lower than it should. This affects +
hard breaks, [%hardbreaks], and hard breaks inside list items (where the bullet
appears raised relative to its text).

Measured baseline advances with the current theme at the default 11pt body size:

baseline advance
normal wrapped lines 13.979 pt
lines ending in a hard break 16.531 pt
last line of a broken block 13.979 pt

Root cause

Asciidoctor converts a hard break into a U+000A character in the text fragment.
Petrona has no glyph for U+000A, so Asciidoctor PDF walks font.fallbacks to find
a font that does, and Prawn then sizes the entire line by the tallest fragment on it.

The copy of M+ 1p in fonts/ does not map U+000A, so it is skipped despite
being first in the chain, and the lookup falls through to Noto Sans. At 11pt:

  • Petrona-Light line height: 12.408
  • Noto Sans line height: 14.960

14.960 − 12.408 = 2.552 pt, exactly the excess observed on hard-broken lines.

This is not a Petrona bug — Petrona is simply shorter than the font that ends up
supplying the break glyph. Swapping the body font for a taller one (e.g. Gentium
Plus) masks the symptom without addressing the cause.

Fix

Point the M+ 1p Fallback catalog entry at the copy bundled with Asciidoctor PDF
(GEM_FONTS_DIR/mplus1p-regular-fallback.ttf). That copy does map U+000A and is
shorter than the body font (11.990), so it is selected first and the line height is
unchanged. The catalog already uses GEM_FONTS_DIR for the sans-serif family, so
this also removes an inconsistency between the two entries.

Verification

Rebuilt a document exercising + breaks, [%hardbreaks], breaks inside list items,
and broad glyph coverage:

block baseline advances
+ hard breaks 13.979, 13.980, 13.979
[%hardbreaks] 13.980, 13.979
hard breaks in a list item 13.979, 13.980
wrapped paragraph (control) 13.979

Uniform, and matching wrapped text. Fallback coverage is intact — Greek, Cyrillic,
Vietnamese, Japanese, the -> <- => <= arrow replacements, math symbols and
smart punctuation all still resolve, with no missing-glyph warnings.

🤖 Generated with Claude Code

Hard line breaks (`+`, `[%hardbreaks]`, and breaks inside list items)
rendered ~2.55pt taller than surrounding lines, so every line but the
last in a broken block appeared to sit lower.

Asciidoctor converts a hard break into U+000A in the text fragment.
Petrona has no glyph for it, so Asciidoctor PDF walks font.fallbacks to
find one that does, and Prawn then sizes the whole line by the tallest
fragment on it. The copy of M+ 1p in fonts/ does not map U+000A, so the
chain fell through to Noto Sans, whose line height at 11pt (14.960)
exceeds Petrona-Light's (12.408) by exactly the 2.552pt observed.

Point M+ 1p Fallback at the copy bundled with Asciidoctor PDF, which
does map U+000A and is shorter than the body font (11.990), so it is
selected first and the line height is unchanged. The catalog already
uses GEM_FONTS_DIR for the sans-serif family, so this also removes an
inconsistency between the two.

Verified: hard-broken lines now advance a uniform 13.979pt, matching
wrapped lines, and Greek, Cyrillic, Vietnamese, Japanese, arrow
replacements, math symbols and smart punctuation still resolve through
the fallback chain with no missing-glyph warnings.

Fixes riscv/docs-spec-template#118

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Bill Traynor <wmat@riscv.org>
Signed-off-by: Bill Traynor <wmat@riscv.org>
@wmat
Bill Traynor (wmat) merged commit d93e7bf into main Aug 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vertical spacing wrong with hard line breaks with the default Petrona font

1 participant