Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override the minimum font size when rendering the text layer #18283

Merged

Conversation

nicolo-ribaudo
Copy link
Contributor

@nicolo-ribaudo nicolo-ribaudo commented Jun 18, 2024

Fixes #14426

Commit message:

Overrride the minimum font size when rendering the text layer

Browsers have an accessibility option that allows user to enforce a minimum font size for all text rendered in the page, regardless of what the font-size CSS property says. For example, it can be found in Firefox under font.minimum-size.x-western.

When rendering the s in the text layer, this causes the text layer to not be aligned anymore with the underlying canvas. While normally accessibility features should not be worked around, in this case it is not improving accessibility:

  • the text is transparent, so making it bigger doesn't make it more readable
  • the selection UX for users with that accessibility option enabled is worse than for other users (it's basically unusable).

While there is tecnically no way to ignore that minimum font size, this commit does it by multiplying all the font-sizes in the text layer by minFontSize, and then scaling all the <span>s down by 1/minFontSize.

This PR detects the min font size similarly to #14427, with a few changes:

  • the minimum font size is only computed once, rather than for every rendered element
  • I used getBoundingClientRect().height rather than getComputedStyle().fontSize, because getComputedStyle().fontSize returns the minimum font size in Chrome and Safari but not in Firefox (https://bugzilla.mozilla.org/show_bug.cgi?id=1903360)

Marking as draft because I still have to run all the tests locally, and add a new test.

@nicolo-ribaudo
Copy link
Contributor Author

This is ready for review. I couldn't run the full test suite locally because makeref gives me a bunch of failures and timeouts in Chrome, but everything passed in Firefox.

Also, I couldn't add a test for Chrome because it seems like it's impossible to set its "Settings > Appearance > Customise fonts > Minimum font size" option through puppeteer (the only way to change it programmatically is through the extensions API, but writing a Chrome extension for this test seems overkill)

@nicolo-ribaudo nicolo-ribaudo marked this pull request as ready for review June 19, 2024 13:19
@timvandermeij
Copy link
Contributor

Nit for the commit message: s/Overrride/Override.

Let's trigger a round of tests:

/botio test

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/674ae2965e56596/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/2c26c2e6f59439f/output.txt

@marco-c marco-c changed the title Overrride the minimum font size when rendering the text layer Override the minimum font size when rendering the text layer Jun 19, 2024
@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/674ae2965e56596/output.txt

Total script time: 28.92 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED
  different ref/snapshot: 16

Image differences available at: http://54.241.84.105:8877/674ae2965e56596/reftest-analyzer.html#web=eq.log

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/2c26c2e6f59439f/output.txt

Total script time: 44.77 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED
  different ref/snapshot: 2

Image differences available at: http://54.193.163.58:8877/2c26c2e6f59439f/reftest-analyzer.html#web=eq.log

@nicolo-ribaudo
Copy link
Contributor Author

nicolo-ribaudo commented Jun 19, 2024

Uhm, taking a look at the integration failures 🤔 It didn't fail locally for some reason

@timvandermeij
Copy link
Contributor

Note that most of them are known intermittents, see https://github.com/mozilla/pdf.js/issues?q=is%3Aopen+is%3Aissue+label%3Aintermittent for the associated issues, so I think only the Text layer when the browser enforces a minimum font size renders spans with the right size failure in the Windows logs is actually relevant for this PR.

@nicolo-ribaudo
Copy link
Contributor Author

There was some variability on the exact number of pixels across different platforms (and across different browsers on the same OS, even if the test only checks Firefox), so I relaxed the assertion to be "the with must be within 3% of 315px". Without the fix the width is more than 200% of the expected with, so a 3% tolerance is ok to verify that the fix is being applied.

I don't have access to a windows machine, could you re-run the bot?

@timvandermeij
Copy link
Contributor

/botio integrationtest

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/dbd55648b66ba65/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/7c447b81f825640/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/dbd55648b66ba65/output.txt

Total script time: 7.91 mins

  • Integration Tests: Passed

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/7c447b81f825640/output.txt

Total script time: 19.68 mins

  • Integration Tests: FAILED

@nicolo-ribaudo
Copy link
Contributor Author

One of the two remaining windows failures is a flaky tests (#17931), the other one is a timeout also related to pasting (Stamp Editor Copy and paste a stamp with an alt text must check that the pasted image has an alt text).

@timvandermeij
Copy link
Contributor

Yes, both are flaky tests and the failures are unrelated to this PR, so the tests here should now be OK.

Copy link
Contributor

@timvandermeij timvandermeij left a comment

Choose a reason for hiding this comment

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

The change looks good to me, but I'd also prefer a review from @Snuffleupagus to make sure that the comments/concerns from the original PR #14427 are fully resolved here. Thanks!

@Snuffleupagus
Copy link
Collaborator

Unfortunately it seems that the new integration test added in this PR has intermittent shutdown issues, based on the logs in http://54.241.84.105:8877/dbd55648b66ba65/output.txt:

�[32m.�[0mTEST-PASSED | renders spans with the right size
JavaScript warning: http://127.0.0.1:34837/build/generic/build/pdf.mjs, line 10681: Script terminated by timeout at:
#getMinFontSize@http://127.0.0.1:34837/build/generic/build/pdf.mjs:10681:25
#appendText@http://127.0.0.1:34837/build/generic/build/pdf.mjs:10573:71
#processItems@http://127.0.0.1:34837/build/generic/build/pdf.mjs:10534:23
render/pump/<@http://127.0.0.1:34837/build/generic/build/pdf.mjs:10453:27

@timvandermeij
Copy link
Contributor

timvandermeij commented Jun 22, 2024

I think the problem is that pretty much all integration tests call closePages in the afterAll handler, which ensures that proper cleanup is done using the testingClose method; see:

function closePages(pages) {
return Promise.all(
pages.map(async ([_, page]) => {
// Avoid to keep something from a previous test.
await page.evaluate(async () => {
await window.PDFViewerApplication.testingClose();
window.localStorage.clear();
});
await page.close({ runBeforeUnload: false });
})
);
}

However, in this new integration test, and also in other tests in this file, this pattern is not used and a separate browser is spawned instead. This is for good reason, but instead of only calling browser.close(), which doesn't do any cleanup of PDF.js, we should make sure the tests that spawn a new browser use the same cleanup mechanism.

We have a reference to the pages in the separate browser in these tests, so we should be able to close the page in a similar way to fix the issue.

@timvandermeij
Copy link
Contributor

I have fixed the issue for the existing test in f4053c2, which should make it a bit easier to mirror that approach for this test and that should solve the shutdown issue identified above.

@nicolo-ribaudo
Copy link
Contributor Author

Thank you! I'll rebase and fix it.

@timvandermeij
Copy link
Contributor

Could you rebase this patch once more onto the current master branch, now that all other test framework fixes have landed? I'll retrigger the tests here afterwards.

@nicolo-ribaudo
Copy link
Contributor Author

Done 👍

@timvandermeij
Copy link
Contributor

/botio integrationtest

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @timvandermeij received. Current queue size: 1

Live output at: http://54.241.84.105:8877/efb440126e25425/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @timvandermeij received. Current queue size: 1

Live output at: http://54.193.163.58:8877/d1053db49ae6092/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/efb440126e25425/output.txt

Total script time: 7.91 mins

  • Integration Tests: FAILED

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/d1053db49ae6092/output.txt

Total script time: 19.06 mins

  • Integration Tests: Passed

@nicolo-ribaudo
Copy link
Contributor Author

The remaining failure on Linux is #17931.

src/display/text_layer.js Outdated Show resolved Hide resolved
src/display/text_layer.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

r=me, with the final comments addressed and all tests passing; thank you!

src/display/text_layer.js Outdated Show resolved Hide resolved
src/display/text_layer.js Outdated Show resolved Hide resolved
Browsers have an accessibility option that allows user to enforce
a minimum font size for all text rendered in the page, regardless
of what the font-size CSS property says. For example, it can be
found in Firefox under `font.minimum-size.x-western`.

When rendering the <span>s in the text layer, this causes the
text layer to not be aligned anymore with the underlying canvas.
While normally accessibility features should not be worked around,
in this case it is *not* improving accessibility:
- the text is transparent, so making it bigger doesn't make it more
  readable
- the selection UX for users with that accessibility option enabled
  is worse than for other users (it's basically unusable).

While there is tecnically no way to ignore that minimum font size,
this commit does it by multiplying all the `font-size`s in the text
layer by minFontSize, and then scaling all the `<span>`s down by
1/minFontSize.
@Snuffleupagus
Copy link
Collaborator

/botio test

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.241.84.105:8877/de1f5d47520022a/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.193.163.58:8877/1cee9608bb46e28/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/de1f5d47520022a/output.txt

Total script time: 28.84 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED
  different ref/snapshot: 11
  different first/second rendering: 1

Image differences available at: http://54.241.84.105:8877/de1f5d47520022a/reftest-analyzer.html#web=eq.log

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/1cee9608bb46e28/output.txt

Total script time: 45.22 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED
  different ref/snapshot: 3

Image differences available at: http://54.193.163.58:8877/1cee9608bb46e28/reftest-analyzer.html#web=eq.log

@timvandermeij timvandermeij merged commit 11cb3a8 into mozilla:master Jun 25, 2024
9 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the ignore-browser-min-font-size branch June 25, 2024 13:57
@timvandermeij
Copy link
Contributor

Thank you for fixing this!

@nicolo-ribaudo
Copy link
Contributor Author

Thanks for the reviews!

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.

Highlight went wrong when the text font-size less than the minimum font-size of the browser
4 participants