-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Add language attribute to canvas #17770
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but this change isn't correct.
First of all the textLayer can be used outside of the viewer, a use-case that this patch completely breaks. Secondly you're not really "allowed" to do inline DOM lookups like this, hence a different solution would be required.
I'd say that the right thing to do is to attach the canvas at the right place here: |
Makes sense, um, I believe to fix this, getCtx() could be changed to set the lang attribute of the canvas to be the same as that of the viewer? |
a305589
to
af3b660
Compare
@calixteman @Snuffleupagus Hey, I updated the pull request, so we assign the same language as the viewer to the canvas, this fixes the text layer issue and also the problems that @calixteman mentioned above. |
23303ee
to
f2fbf37
Compare
I'm not even sure if this is the "correct" solution, given e.g. #17770 (comment) above? /cc @calixteman (Assuming this is a good solution, the actual implementation needs a little bit of work to improve things.) |
I wonder what "the right place" would be. Currently the language is set per-page, while there is only one canvas injected in the document. Are all pages of a PDF guaranteed to have the same language? If so we could inject the canvas in the first page's text layer, and re-use it for all the pages. If not, the alternative is to inject the canvas in every page. |
I suppose we could pass the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this is not a good solution in its current form, since viewer initialization and first rendering is now blocked on Metadata fetching and parsing despite that being unrelated to actual rendering.
This will thus affect general viewer loading performance for all PDF documents, given that /Info-dictionaries and /Metadata-streams are often placed at the end of the file. Especially for e.g. linearized PDFs this could thus have a noticeable impact.
Hence my first idea, to work-around these problems, could be to also include the /Lang-data in the textContent
such that it becomes directly available in the src/display/text_layer.js
file. (I can try outlining a patch for this part during the weekend).
That's a fair point.
Passing the |
I did do some experimentation to make the text layer font the same as the document font, but I didn't go ahead with that since the font details are cleaned up after a few seconds here unless |
The cache thing isn't really a problem here: we could just disable it, the main problem is that we've to deal with a lot of fonts which aren't always in a good state to be used as is in the text layer. |
My idea would only require invoking Lines 117 to 124 in e78ce74
textContent .
|
Can't we just get a promise with the lang and pass it when building the text layer and get its value only when the first chunk is rendered, something like that ? |
Now that #17941 is in place, this patch can be updated to make use of the new |
f2fbf37
to
0603d1a
Compare
Updated the pull request using the new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add a text
reference test, using the first page of the affected PDF document.
And please improve the commit message to explain what's being changed and why, i.e. you'll want more than a single line, since it's currently difficult to understand what the patch does without looking at the code.
4e53e30
to
ac8a22f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this will now require another rebase, sorry about that!
a56a26a
to
b17cce5
Compare
On it! |
b17cce5
to
86f22d0
Compare
86f22d0
to
bcfe427
Compare
Fixes issue mozilla#16843. In certain cases, the text layer was misaligned due to a difference between the `lang` attribute of the viewer and the canvas. This commit addresses the problem by adding the `lang` attribute to the canvas. The issue was caused because PDF.js uses serif/sans-serif fonts to generate the text layer and relies on system fonts. The difference in the `lang` attribute led to different fonts being picked, causing the misalignment.
bcfe427
to
9edca0a
Compare
/botio test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.193.163.58:8877/030f1b06ca59e29/output.txt |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.241.84.105:8877/f990e5b7a010e09/output.txt |
From: Bot.io (Windows)FailedFull output at http://54.193.163.58:8877/030f1b06ca59e29/output.txt Total script time: 6.64 mins
Image differences available at: http://54.193.163.58:8877/030f1b06ca59e29/reftest-analyzer.html#web=eq.log |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/f990e5b7a010e09/output.txt Total script time: 27.76 mins
Image differences available at: http://54.241.84.105:8877/f990e5b7a010e09/reftest-analyzer.html#web=eq.log |
/botio-windows test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 1 Live output at: http://54.193.163.58:8877/dd43222cb7c27d0/output.txt |
From: Bot.io (Windows)FailedFull output at http://54.193.163.58:8877/dd43222cb7c27d0/output.txt Total script time: 40.77 mins
Image differences available at: http://54.193.163.58:8877/dd43222cb7c27d0/reftest-analyzer.html#web=eq.log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me, thank you!
/botio makeref |
From: Bot.io (Linux m4)ReceivedCommand cmd_makeref from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.241.84.105:8877/30f062f551ad04a/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_makeref from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.193.163.58:8877/13b047407e28182/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.241.84.105:8877/30f062f551ad04a/output.txt Total script time: 20.10 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.193.163.58:8877/13b047407e28182/output.txt Total script time: 25.14 mins
|
Fixes issue #16843.
In certain cases, the text layer was misaligned due to a difference
between the
lang
attribute of the viewer and the canvas. This commit addresses the problem by adding thelang
attribute to the canvas. The issue was caused because PDF.js uses serif/sans-serif fonts to generate the text layer and relies on system fonts. The difference in thelang
attribute led to different fonts being picked, causing the misalignment.Before the change:
After the change:
Thanks, @nicolo-ribaudo for helping with this.