Skip to content

Prevent inherited spacing from affecting text layer#21321

Merged
calixteman merged 1 commit into
mozilla:masterfrom
danyalahmed1995:fix/issue-21259-text-layer-spacing
May 25, 2026
Merged

Prevent inherited spacing from affecting text layer#21321
calixteman merged 1 commit into
mozilla:masterfrom
danyalahmed1995:fix/issue-21259-text-layer-spacing

Conversation

@danyalahmed1995

Copy link
Copy Markdown
Contributor

Summary

Fixes #21259.

This prevents inherited letter-spacing and word-spacing from affecting the text layer. External page styles can otherwise change the rendered width/positioning of text-layer spans while the PDF canvas remains unchanged, causing text selection/highlight alignment issues.

The fix resets spacing on:

  • .textLayer
  • the hidden measurement canvas used by the text layer

A regression test was added to cover inherited spacing from the viewer container.

Testing

  • npx eslint src/display/text_layer.js test/integration/text_layer_spec.mjs
  • npx stylelint web/text_layer_builder.css
  • npx gulp generic
  • Manual verification in the local viewer:
    • applied letter-spacing: 5px and word-spacing: 5px to body / #mainContainer
    • confirmed body had inherited spacing
    • confirmed .textLayer and text-layer spans stayed at neutral computed spacing
    • confirmed text selection remained aligned

Note: I also tried npx gulp integrationtest --headless --noFirefox -t text_layer, but it did not stay limited to the text-layer test and started running unrelated integration tests, so I stopped it locally.

@timvandermeij timvandermeij left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me, with the comment addressed and passing tests. Thank you for your contribution!

Comment thread test/integration/text_layer_spec.mjs Outdated
@timvandermeij

Copy link
Copy Markdown
Contributor

Could you squash the commits into one, see https://github.com/mozilla/pdf.js/wiki/Squashing-Commits, and include (a summary of) the context from the PR description in the actual commit message so that it's also clear from e.g. git log what the patch is about? After that I'll trigger the tests here.

@danyalahmed1995

Copy link
Copy Markdown
Contributor Author

Sure , give me a moment

@danyalahmed1995 danyalahmed1995 force-pushed the fix/issue-21259-text-layer-spacing branch from d6c4c48 to fbe9a52 Compare May 24, 2026 13:36
@danyalahmed1995

Copy link
Copy Markdown
Contributor Author

@timvandermeij Squashed into one commit with the PR context included in the commit message.

@codecov-commenter

codecov-commenter commented May 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.41%. Comparing base (ea18e73) to head (4ee9c39).
⚠️ Report is 22 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21321      +/-   ##
==========================================
+ Coverage   81.39%   81.41%   +0.01%     
==========================================
  Files         256      257       +1     
  Lines       65337    65339       +2     
==========================================
+ Hits        53183    53196      +13     
+ Misses      12154    12143      -11     
Flag Coverage Δ
fonttest 9.11% <ø> (-0.01%) ⬇️
integrationtest 66.99% <ø> (+0.01%) ⬆️
unittest 56.85% <ø> (+<0.01%) ⬆️
unittestcli 56.06% <ø> (+<0.01%) ⬆️

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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/display/text_layer.js
@timvandermeij

Copy link
Copy Markdown
Contributor

/botio-linux preview

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.241.84.105:8877/0e9ab44fdd528b3/output.txt

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/0e9ab44fdd528b3/output.txt

Total script time: 1.20 mins

Published

Comment thread test/integration/text_layer_spec.mjs Outdated
Fixes mozilla#21259.

Reset letter-spacing and word-spacing on the text layer and hidden measurement canvas so inherited page styles do not affect text layer alignment. Add an integration regression test for inherited spacing.
@danyalahmed1995 danyalahmed1995 force-pushed the fix/issue-21259-text-layer-spacing branch from fbe9a52 to 4ee9c39 Compare May 24, 2026 18:56
@timvandermeij

Copy link
Copy Markdown
Contributor

/botio browsertest

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_browsertest from @timvandermeij received. Current queue size: 0

Live output at: http://54.241.84.105:8877/0089e6b5470a51d/output.txt

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Received

Command cmd_browsertest from @timvandermeij received. Current queue size: 0

Live output at: http://54.193.163.58:8877/5a0bdd56e8589f3/output.txt

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/0089e6b5470a51d/output.txt

Total script time: 18.28 mins

  • Regression tests: Passed

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/5a0bdd56e8589f3/output.txt

Total script time: 25.32 mins

  • Regression tests: Passed

@calixteman calixteman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Thank you.

@calixteman calixteman merged commit 164ffb9 into mozilla:master May 25, 2026
22 checks passed
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.

[Bug]: letter-spacing and word-spacing can mess up the scaling of the text layer's elements

6 participants