Skip to content

Fix new TextMeasurer Bounds calculations so origin is absolute.#507

Merged
JimBobSquarePants merged 3 commits intomainfrom
js/textmeasurer-fixes
Mar 9, 2026
Merged

Fix new TextMeasurer Bounds calculations so origin is absolute.#507
JimBobSquarePants merged 3 commits 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 enhances the documentation and correctness of text measurement methods in TextMeasurer.cs, clarifying the distinction between logical advance and rendered glyph bounds, and ensuring absolute coordinates are used for layout calculations. It also updates the implementation to properly union the logical advance with the rendered bounds, and improves per-character measurement accuracy. The test utility is updated to reflect these changes.

Documentation improvements:

  • Added detailed remarks to all public measurement methods in TextMeasurer.cs, explaining the differences between logical advance, ink bounds, and renderable bounds, and referencing related methods for clarity. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

Measurement logic corrections:

  • Updated MeasureRenderableBounds(ReadOnlySpan<char>, TextOptions) to union the absolute advance rectangle (with origin) with the rendered bounds, ensuring the returned rectangle is in absolute coordinates and contains both logical and ink bounds.
  • Refined per-character renderable bounds calculation in TryGetCharacterRenderableBounds to use absolute advance rectangles and union them with glyph ink bounds, improving accuracy for layout and rendering.

Test utility update:

  • Modified TestLayout in TextLayoutTestUtilities.cs to calculate width and height using the new measurement logic, ensuring the test reflects the updated bounding box calculation.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 83%. Comparing base (3214ad7) to head (ddead05).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/SixLabors.Fonts/TextMeasurer.cs 40% 3 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #507   +/-   ##
=====================================
- Coverage     83%     83%   -1%     
=====================================
  Files        274     274           
  Lines      19167   19169    +2     
  Branches    2714    2714           
=====================================
+ Hits       16048   16049    +1     
- Misses      2441    2442    +1     
  Partials     678     678           
Flag Coverage Δ
unittests 83% <40%> (-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.

@JimBobSquarePants JimBobSquarePants merged commit 1ac46b2 into main Mar 9, 2026
9 of 10 checks passed
@JimBobSquarePants JimBobSquarePants deleted the js/textmeasurer-fixes branch March 9, 2026 06:41
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.

1 participant