Skip to content

Feature: implement the truncating line break modes in the typesetter - #829

Open
DTW-Thalion wants to merge 2 commits into
gnustep:masterfrom
DTW-Thalion:feature/typesetter-truncation
Open

Feature: implement the truncating line break modes in the typesetter#829
DTW-Thalion wants to merge 2 commits into
gnustep:masterfrom
DTW-Thalion:feature/typesetter-truncation

Conversation

@DTW-Thalion

Copy link
Copy Markdown
Contributor

NSLineBreakByTruncatingTail, ...Head and ...Middle all fell through to clipping: the glyphs that did not fit were hidden and no ellipsis was drawn, and head and middle kept the wrong glyphs.

This adds a real truncation indicator. A line fragment can now carry a truncation glyph (an ellipsis) with a position and font:

  • GSLayoutManager stores it as transient layout information on the line fragment (in linefrag_t), set by the typesetter through -setTruncationGlyph:atPoint:font:forGlyphRange: and read back with -truncationGlyphForGlyphAtIndex:. Because it is layout information and not written into the glyph store, a re-layout regenerates it correctly and the glyph/character mapping is untouched.
  • NSLayoutManager draws the truncation glyph after the fragment's glyphs.
  • GSHorizontalTypesetter handles the three modes: tail drops the trailing glyphs and places the ellipsis at the end; head shows a trailing suffix after a leading ellipsis; middle keeps a leading prefix and a trailing suffix with the ellipsis between them. Dropped glyphs are marked not-shown and the shown suffix is repositioned.

The ellipsis glyph comes from the font, and if the font has none the line is clipped as before.

Tests: Tests/gui/GSHorizontalTypesetter/truncation.m checks, for each mode, which glyphs are shown or hidden and that the ellipsis is set. Layout was verified against the full text-layout suites with no regressions, and drawing of all three modes was checked against the X11 backend under Xvfb.

Closes #414

NSLineBreakByTruncatingTail, ...Head and ...Middle all fell through to
clipping: the glyphs that did not fit were hidden and no ellipsis was
drawn, and head and middle kept the wrong glyphs.

Add a truncation indicator to the layout. A line fragment can now carry a
truncation glyph (an ellipsis) with a position and font, set by the
typesetter through -setTruncationGlyph:atPoint:font:forGlyphRange: and
read back with -truncationGlyphForGlyphAtIndex:. The glyph is transient
layout information on the line fragment, so it is not written into the
glyph store and a re-layout regenerates it correctly. NSLayoutManager
draws it after the fragment's glyphs.

GSHorizontalTypesetter now handles the three modes: tail drops trailing
glyphs and places the ellipsis at the end, head shows a trailing suffix
after a leading ellipsis, and middle keeps a leading prefix and a
trailing suffix with the ellipsis between them. The hidden glyphs are
marked not-shown and the shown suffix is repositioned.

Tests/gui/GSHorizontalTypesetter/truncation.m covers the glyph visibility
and the ellipsis for each mode.

Closes gnustep#414
@DTW-Thalion
DTW-Thalion requested a review from fredkiefer as a code owner July 27, 2026 16:18
START_SET creates an autorelease pool and END_SET releases it, so the pool
these tests create around the set is redundant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

GSHorizontalTypesetter improvements: Implement Truncation Modes Properly

1 participant