Skip to content

Refactor TextMeasurer advance/bounds measurement#506

Merged
JimBobSquarePants merged 1 commit intomainfrom
js/textmeasurer-fixes
Mar 8, 2026
Merged

Refactor TextMeasurer advance/bounds measurement#506
JimBobSquarePants merged 1 commit intomainfrom
js/textmeasurer-fixes

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 pull request introduces significant improvements to the text measurement API in TextMeasurer, clarifying the distinction between logical advance, rendered bounds, and their union, and adding new methods for more granular measurement. It also updates the implementation to use a more robust layout model and adds new per-character measurement capabilities. Several test image references have been updated to reflect these changes.

API and documentation improvements:

  • Clarified and expanded XML documentation for all measurement methods in TextMeasurer, distinguishing between logical advance, rendered glyph bounds, normalized size, and full renderable bounds. New remarks and references help users select the correct measurement method for their needs.
  • Added new methods: MeasureRenderableBounds and TryMeasureCharacterRenderableBounds, which return the union of logical advance and rendered glyph bounds, both for whole text and per-character entry.

Implementation changes:

  • Refactored the logical advance measurement to use the TextLayout.TextBox model, providing more accurate line and layout metrics, and simplified the logic for both horizontal and vertical layouts.
  • Added internal method TryGetCharacterRenderableBounds to compute per-character union bounds for advanced measurement scenarios.

Test updates:

  • Updated several test image references in tests/Images/ReferenceOutput to reflect the new measurement and rendering logic, resulting in changed output images and sizes. [1] [2] [3] [4] [5] [6] [7] [8]

@JimBobSquarePants JimBobSquarePants merged commit 3214ad7 into main Mar 8, 2026
17 checks passed
@JimBobSquarePants JimBobSquarePants deleted the js/textmeasurer-fixes branch March 8, 2026 12:59
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 8, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 83%. Comparing base (1ed876e) to head (36f9c52).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/SixLabors.Fonts/TextMeasurer.cs 50% 17 Missing and 3 partials ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #506   +/-   ##
=====================================
- Coverage     83%     83%   -1%     
=====================================
  Files        274     274           
  Lines      19171   19167    -4     
  Branches    2717    2714    -3     
=====================================
- Hits       16071   16048   -23     
- Misses      2424    2441   +17     
- Partials     676     678    +2     
Flag Coverage Δ
unittests 83% <50%> (-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