Skip to content

More robust overhang - #8131

Merged
laurmaedje merged 16 commits into
typst:mainfrom
sicikh:more-robust-overhanging
Aug 4, 2026
Merged

laurmaedje merged 16 commits into
typst:mainfrom
sicikh:more-robust-overhanging

Conversation

@sicikh

@sicikh sicikh commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

Continues work of #7376.

Closes #7219, closes #8130. Also closes #6735 (see below).

For more info, see #7376 (comment).

  • Skip zero-advance glyphs when finding the first/last glyph for line overhang.
  • Restore overhang when a preceding word injects label-driven zero-width glyphs.
  • Keep existing behavior for lines that already start or end with regular glyphs.

New change, not included in the #7376 and what is resolving #6735:

When a glyph is shaped, its first character (glyph.c) may differ from the expected character (for example, sym.wj + sym.dash.em results in a glyph in which glyph.c is equal to \u{2060}). In this example, the old function-based implementation, which checks only the glyph.c, cannot verify that a particular character is a em-dash, and thus disables overhang for it. And vice versa, with font that substitutes multiple characters with different glyph, glyph.c can be misleading — two em-dashes in Noto Serif SC are substituted with U+2E3A, which should not be overhang, while glyph.c is the first em-dash, which causes the whole glyph to overhang (even with the wrong ratio!).

To solve this problem, each character in the overhang table is mapped to a glyph id in the glyph font, and only then are these ids compared to check if we should enable overhang.

@sicikh

sicikh commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor Author

And vice versa, with font that substitutes multiple characters with different glyph, glyph.c can be misleading — two em-dashes in Noto Serif SC are substituted with U+2E3A, which should not be overhang, while glyph.c is the first em-dash, which causes the whole glyph to overhang (even with the wrong ratio!).

This should be tested, but current test runner has specific version of Noto Serif SC without such substituion. Code for future test is under the spoiler below (adapted from original issue). See typst/typst-dev-assets#18.

Test case
#let ccwd = 12pt
#set page(height: auto, width: ccwd * 30 + 20pt, margin: 10pt)
#set text(
  lang: "zh",
  font: ("Noto Serif CJK SC"), // font converts 2 U+2014s to U+2E3A
  size: ccwd,
  cjk-latin-spacing: auto
)
#set par(justify: true, first-line-indent: (amount: 2em, all: true))
#place(
  top + left,
  dx: ccwd,
  box(width: ccwd * 30,
    repeat(
      rect(width: ccwd, height: 2.4em, stroke: none, fill: rgb("#7092be70")),
      gap: ccwd,
      justify: false
    )
  )
)

囗囗囗囗囗囗囗,囗囗囗囗囗囗囗囗。囗囗囗囗囗囗囗囗囗------囗囗囗囗

@laurmaedje laurmaedje added the waiting-on-review This PR is waiting to be reviewed. label Apr 21, 2026
@isuffix isuffix added layout Related to the layout category, which is about composing, positioning, etc. text Related to the text category, which is all about text handling, shaping, etc. labels May 17, 2026
Comment thread crates/typst-layout/src/inline/line.rs Resolved
@laurmaedje laurmaedje added waiting-on-author Pull request waits on author and removed waiting-on-review This PR is waiting to be reviewed. labels May 27, 2026
@laurmaedje

Copy link
Copy Markdown
Member

@sicikh Since there is still an unresolved review comment: Do you still plan to work on this?

@sicikh
sicikh requested a review from laurmaedje July 31, 2026 18:48
@sicikh

sicikh commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor Author

Sorry for the delay! I've answered to the review comment: #8131 (comment). In short, we really need to compute overhang table with data from the glyph's font, so obvious optimization is to memoize it, which is done in d39d1aa.

@laurmaedje laurmaedje added waiting-on-review This PR is waiting to be reviewed. and removed waiting-on-author Pull request waits on author labels Aug 3, 2026
@laurmaedje
laurmaedje force-pushed the more-robust-overhanging branch from ac2fe22 to eb4ff25 Compare August 3, 2026 14:55
Comment thread crates/typst-layout/src/inline/line.rs Resolved
@laurmaedje laurmaedje removed the waiting-on-review This PR is waiting to be reviewed. label Aug 3, 2026
@laurmaedje laurmaedje added the waiting-on-author Pull request waits on author label Aug 3, 2026
@sicikh
sicikh requested a review from laurmaedje August 3, 2026 15:27
There is not need to check the advance width since trimmed glyphs are excluded in `Deref for Glyphs`
@laurmaedje laurmaedje changed the title More robust overhanging (continuation of #7376) More robust overhang Aug 4, 2026
@laurmaedje laurmaedje removed the waiting-on-author Pull request waits on author label Aug 4, 2026
@laurmaedje
laurmaedje enabled auto-merge August 4, 2026 08:47
@laurmaedje

Copy link
Copy Markdown
Member

Thanks!

@laurmaedje
laurmaedje added this pull request to the merge queue Aug 4, 2026
Merged via the queue into typst:main with commit d1277b0 Aug 4, 2026
9 checks passed
@sicikh
sicikh deleted the more-robust-overhanging branch August 4, 2026 10:35
@YDX-2147483647

This comment was marked as resolved.

Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Aug 7, 2026
93 commits novos desde v0.15.1 (tag 9dfd3a0) até upstream/main (a51e028).
397 ficheiros alterados, 5782 inserções, 2831 remoções.

Destaques do upstream:
- Store required features in bindings (typst#8599)
- Support raw serialization format for typst eval (typst#8295)
- Add diagnostics-format environment variable (typst#8438)
- More robust overhang (typst#8131)
- Fix logical indices of hyphens with respect to surrounding tags (typst#8714)
- Bump krilla and hayro (typst#8716)
- Fix line breaking for hosts starting with a digit (typst#8039)
- Fix auto hanging-indent for heading numbering (typst#7247)

Build vanilla verificado: cargo build ok (3m02s).
Dikluwe added a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
93 commits novos desde v0.15.1 (tag 9dfd3a0) até upstream/main (a51e028).
397 ficheiros alterados, 5782 inserções, 2831 remoções.

Destaques do upstream:
- Store required features in bindings (typst#8599)
- Support raw serialization format for typst eval (typst#8295)
- Add diagnostics-format environment variable (typst#8438)
- More robust overhang (typst#8131)
- Fix logical indices of hyphens with respect to surrounding tags (typst#8714)
- Bump krilla and hayro (typst#8716)
- Fix line breaking for hosts starting with a digit (typst#8039)
- Fix auto hanging-indent for heading numbering (typst#7247)

Build vanilla verificado: cargo build ok (3m02s).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

layout Related to the layout category, which is about composing, positioning, etc. text Related to the text category, which is all about text handling, shaping, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show-rule disables overhanging punctuation Overhang disabled if word has label U+2E3A and two consecutive U+2014 should not be overhung

5 participants