Skip to content

Type: Top-to-Top Leading — leading measured from em box top to em box top - #385

Merged
bflatastic merged 2 commits into
storytold:mainfrom
imachus:pr/ja-leading
Oct 7, 2026
Merged

bflatastic merged 2 commits into
storytold:mainfrom
imachus:pr/ja-leading

Conversation

@imachus

@imachus imachus commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

What and why

Japanese layout measures leading from the top of one line's ideographic
em box to the next (the right side, in vertical type), not from baseline
to baseline. The Paragraph panel menu now offers both:

  • ParaStyle.leading_model: RomanBaseline (as before, the default) or
    EmBoxTop. With EmBoxTop a line's leading is the space below it — the
    next line's em box top is this line's plus its leading, and the next
    baseline hangs from there by that line's tallest em box — and area
    type's first line touches the top of the frame (its em box top on the
    frame's top, at least Area Type Options' minimum). With baseline
    leading a line's leading stays the space above it.
  • Lines of one size are exactly as far apart either way; the models
    differ for mixed sizes and for the first line of area type (fonts
    whose ascent isn't the em box top: Hiragino's nearly is).
  • The em box top comes from the font's vertical metrics (Type: vertical type takes upright glyphs' cells from the font's vertical metrics #343), else
    0.88 em. Written only when EmBoxTop.
  • text.setFormat {leadingModel: "romanBaseline"|"emBoxTop"}; menu items
    Top-to-Top Leading / Bottom-to-Bottom Leading (checked as set); catalog
    rows in ja and zh-hant.

The default stays baseline to baseline, so no existing or new document changes unless the paragraph is set to Top-to-Top. Japanese layout apps usually default to Top-to-Top for Japanese type; whether VectorCraft's new type should too (it would move area type's first line for every font whose ascent isn't its em box top) is left for a separate decision.

How it was tested

  • Full workspace cargo test passes (3,573), with new tests: area type's first line flush with the frame top; lines of one size equally spaced in both models; 40 pt over 20 pt spaced by the big line's leading (Top-to-Top) vs the small line's (baseline); text.setFormat, its error, undo, and saved only when Top-to-Top.
  • Rendered horizontal and vertical area type in Hiragino Mincho both ways.
  • cargo fmt --check, cargo clippy --workspace --all-targets -D warnings, cargo xtask brands, layers, assets pass; the web build compiles.

Checklist

  • cargo xtask ci passes (fmt, clippy, tests, assets, brands, layers, wasm).
  • No panics in shipped code.
  • Clean-room: behaviour from public docs and JLREQ; feature names only.
  • No new assets.

🤖 Generated with Claude Code

imachus and others added 2 commits October 8, 2026 06:24
… top

Japanese layout measures leading from the top of one line's ideographic
em box to the next (the right side, in vertical type), not from baseline
to baseline. The Paragraph panel menu now offers both:

- `ParaStyle.leading_model`: RomanBaseline (as before, the default) or
  EmBoxTop. With EmBoxTop a line's leading is the space below it — the
  next line's em box top is this line's plus its leading, and the next
  baseline hangs from there by that line's tallest em box — and area
  type's first line touches the top of the frame (its em box top on the
  frame's top, at least Area Type Options' minimum). With baseline
  leading a line's leading stays the space above it.
- Lines of one size are exactly as far apart either way; the models
  differ for mixed sizes and for the first line of area type (fonts
  whose ascent isn't the em box top: Hiragino's nearly is).
- The em box top comes from the font's vertical metrics (storytold#343), else
  0.88 em. Written only when EmBoxTop.
- `text.setFormat {leadingModel: "romanBaseline"|"emBoxTop"}`; menu items
  Top-to-Top Leading / Bottom-to-Bottom Leading (checked as set); catalog
  rows in ja and zh-hant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The em box top that Top-to-Top Leading asks of every glyph's line metrics parsed the font's
  cmap and vertical metrics per glyph on every layout: each face now reads it once.
- The Paragraph panel menu shows Top-to-Top / Bottom-to-Bottom Leading with the East Asian
  options (Preferences › Type), as the Mojikumi Set does, and Reset Panel goes back to
  Bottom-to-Bottom Leading, the default.
- Saved as `leading_model`, like the other paragraph attributes in files.
- Simplified Chinese (landed since) translates the two menu items.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bflatastic
bflatastic merged commit d8a2d4c into storytold:main Oct 7, 2026
@bflatastic

Copy link
Copy Markdown
Member

Thank you @imachus, merged! Top-to-Top Leading is clean, and the file format stays readable by older builds. I rebased it on main, fitting the field into the new ParaStyleFile (the Justify Auto back-compat wrapper), and added one commit on top:

  • Speed: each font face now reads its ideographic em box once instead of once per glyph on every layout. It was on the hot path even with the default model.
  • Menu: the two leading items show in the Paragraph panel menu only with Show East Asian Options, as in Illustrator, and Reset Panel goes back to Bottom-to-Bottom.
  • Saved key: the attribute is saved as leading_model like the other paragraph fields. The command param stays leadingModel.
  • Translations: Simplified Chinese and Spanish rows, since those catalogs landed in the meantime.

Checked live: Top-to-Top moves area type's first line so its em box touches the frame top, at the same line pitch. Over MCP, text.setFormat {leadingModel: "emBoxTop"} works with undo/redo, and bad values return clean errors.

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.

2 participants