Skip to content

Add new TexBlock and Hit testing APIs#530

Merged
JimBobSquarePants merged 17 commits into
mainfrom
js/textblock
May 8, 2026
Merged

Add new TexBlock and Hit testing APIs#530
JimBobSquarePants merged 17 commits into
mainfrom
js/textblock

Conversation

@JimBobSquarePants
Copy link
Copy Markdown
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

This PR expands the text layout stack into a richer prepared-layout and interaction API surface.

Highlights:

  • Adds prepared TextBlock layout APIs for repeated measuring, rendering, per-line inspection, and manual flow.
  • Adds LineLayout and LineLayoutEnumerator so callers can inspect, render, and position individual laid-out lines.
  • Adds text interaction APIs for hit testing, caret positioning, caret movement, word selection, and selection bounds.
  • Adds bidi-aware caret/selection behavior, including split visual selection rectangles for mixed-direction text.
  • Adds TextBidiMode to support normal bidi resolution and explicit direction override behavior.
  • Adds paragraph/editor interaction modes so paragraph layout trims trailing whitespace while editor layout preserves typed trailing spaces and terminal hard breaks.
  • Adds soft-hyphen rendering support with TextHyphenation and custom hyphen markers.
  • Adds max-line ellipsis support with TextEllipsis and custom ellipsis markers.
  • Adds inline placeholder support using object replacement semantics, placeholder metrics, alignment, and line-height participation.
  • Consolidates glyph detail APIs into GetGlyphMetrics, exposing advance, bounds, renderable bounds, code point, and source mapping from one glyph metrics entry.
  • Updates the design documentation for the new measurement, layout, and interaction APIs.

Breaking API Changes

  • Replaces the old separate glyph measurement APIs with a single GetGlyphMetrics API.
  • Renames the font-table glyph metrics type to FontGlyphMetrics.
  • Uses GlyphMetrics for laid-out glyph entries exposed by text measurement APIs.

Testing

This includes unit and visual coverage for:

  • Soft hyphen behavior, including none/custom modes, fallback runs, bidi text, and visual output.
  • Ellipsis behavior, including standard/custom markers, max-line truncation, and visual output.
  • Bidi mode behavior, including normal vs override ordering.
  • Caret placement and movement, including bidi cases, start/end placement, line movement, and preserved line navigation position.
  • Selection geometry, including bidi-discontinuous selection ranges.
  • Paragraph vs editor whitespace handling.
  • Placeholder layout, alignment, line-height effects, source mapping, and visual output.
  • Per-line layout enumeration and manual flow rendering.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

❌ Patch coverage is 89.10035% with 315 lines in your changes missing coverage. Please review.
✅ Project coverage is 84%. Comparing base (bf9f4aa) to head (98c6466).

Files with missing lines Patch % Lines
src/SixLabors.Fonts/TextInteraction.cs 74% 68 Missing and 50 partials ⚠️
src/SixLabors.Fonts/FontGlyphMetrics.cs 75% 39 Missing and 10 partials ⚠️
src/SixLabors.Fonts/TextLayout.LineBreaking.cs 89% 19 Missing and 11 partials ⚠️
src/SixLabors.Fonts/TextLine.cs 93% 15 Missing and 13 partials ⚠️
src/SixLabors.Fonts/LineLayout.cs 76% 20 Missing ⚠️
src/SixLabors.Fonts/TextBlock.Visitors.cs 95% 7 Missing and 5 partials ⚠️
src/SixLabors.Fonts/TextLayout.cs 95% 3 Missing and 5 partials ⚠️
...es/AdvancedTypographic/GPos/LookupType3SubTable.cs 12% 7 Missing ⚠️
src/SixLabors.Fonts/TextMeasurer.cs 75% 6 Missing and 1 partial ⚠️
src/SixLabors.Fonts/PlaceholderGlyphMetrics.cs 90% 6 Missing ⚠️
... and 16 more
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #530     +/-   ##
=======================================
  Coverage     83%     84%             
=======================================
  Files        312     332     +20     
  Lines      22737   24634   +1897     
  Branches    3349    3609    +260     
=======================================
+ Hits       19018   20737   +1719     
- Misses      2905    3010    +105     
- Partials     814     887     +73     
Flag Coverage Δ
unittests 84% <89%> (+<1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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