Skip to content

Measure a run's advance with its own font - #514

Merged
PrinsFrank merged 1 commit into
PrinsFrank:mainfrom
cosmocode:fix-advance-width-font
Aug 23, 2026
Merged

Measure a run's advance with its own font#514
PrinsFrank merged 1 commit into
PrinsFrank:mainfrom
cosmocode:fix-advance-width-font

Conversation

@splitbrain

Copy link
Copy Markdown
Contributor

The word break between two runs on a line is decided by the gap between them minus the advance width of the first run. That advance was measured with the font of the second run, so on a line that changes font mid-way the glyph widths of the wrong font were used and a space appeared or went missing. Each run's font is now carried to the next iteration and used to measure its own advance.

Six samples change, all on lines that switch font. Words that were run together or split apart are now separated correctly: "accusamusEt", "perspiciatisQuo" and "debitisQui" in gdocs-lorem-ipsum-with-titles-and-formatting, and the product name "VistalinkTM" in text-objects-across-multiple-streams, which was split into "Vista linkTM" twice.

The spacing around punctuation shifts either way: three spaces before a full stop disappear in word365-lorem-ipsum-with-titles-and-formatting, one appears in issue-457 and one in issue-235. In issue-457 the formula "x + y = 56" loses two spaces: the "+" and "=" are OpenSymbol glyphs whose advance includes wide side bearings, so the gap left over is smaller than the word break threshold once the advance is measured with the font that actually draws them.

The word break between two runs on a line is decided by the gap between them
minus the advance width of the first run. That advance was measured with the
font of the second run, so on a line that changes font mid-way the glyph widths
of the wrong font were used and a space appeared or went missing. Each run's
font is now carried to the next iteration and used to measure its own advance.

Six samples change, all on lines that switch font. Words that were run together
or split apart are now separated correctly: "accusamusEt", "perspiciatisQuo" and
"debitisQui" in gdocs-lorem-ipsum-with-titles-and-formatting, and the product
name "VistalinkTM" in text-objects-across-multiple-streams, which was split into
"Vista linkTM" twice.

The spacing around punctuation shifts either way: three spaces before a full stop
disappear in word365-lorem-ipsum-with-titles-and-formatting, one appears in
issue-457 and one in issue-235. In issue-457 the formula "x + y = 56" loses two
spaces: the "+" and "=" are OpenSymbol glyphs whose advance includes wide side
bearings, so the gap left over is smaller than the word break threshold once the
advance is measured with the font that actually draws them.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.90%. Comparing base (1dffdf9) to head (4f81779).

Files with missing lines Patch % Lines
src/Extraction/Markdown/MarkdownExtractor.php 0.00% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #514      +/-   ##
============================================
- Coverage     49.94%   49.90%   -0.05%     
- Complexity     1874     1875       +1     
============================================
  Files           108      108              
  Lines          3588     3591       +3     
============================================
  Hits           1792     1792              
- Misses         1796     1799       +3     

☔ View full report in Codecov by Harness.
📢 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.

@PrinsFrank PrinsFrank left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!

@PrinsFrank
PrinsFrank merged commit 6f93d2e into PrinsFrank:main Aug 23, 2026
22 checks passed
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.

3 participants