-
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
[api-minor] Improve pdf reading in high contrast mode #14874
Conversation
With tracemonkey.pdf there no noticeable difference in term of performance when rendering the 14 pages at zoom level set to 1%. |
What does the browser support situation look like for those values, since the only information I could find is https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#system_colors and that page doesn't (as far as I can tell) say anything about the compatibility situation? |
Good question. About Chrome I found this bug: About Safari: |
For the What happens in a browser without System Colors support, does it fallback gracefully or does rendering just break? |
That document is probably simple enough to not really stress those canvas-methods all that much. What about a larger and more complex one, e.g. this map https://github.com/mozilla/pdf.js/files/1522715/wuppertal_2012.pdf? |
In using perf tool in devtools in Firefox beta, there are nothing noticeable with this pdf without the patch, with the patch but the default black and white, with the patch with overwritten colors.
To avoid any bad things with these values (i.e. Canvas & CanvasText) we could add a check in using |
Thanks for checking! Also, just a FYI: Note that you can use the PDF.js debugging tools for basic performance measurements. Set
Sure, that could work. In that case it's probably best to add that code in the if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
...
} |
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @calixteman received. Current queue size: 0 Live output at: http://54.241.84.105:8877/ba10c92bfd94806/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @calixteman received. Current queue size: 0 Live output at: http://54.193.163.58:8877/c847e936a225940/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/ba10c92bfd94806/output.txt Total script time: 26.66 mins
Image differences available at: http://54.241.84.105:8877/ba10c92bfd94806/reftest-analyzer.html#web=eq.log |
From: Bot.io (Windows)FailedFull output at http://54.193.163.58:8877/c847e936a225940/output.txt Total script time: 30.80 mins
Image differences available at: http://54.193.163.58:8877/c847e936a225940/reftest-analyzer.html#web=eq.log |
/botio-windows browsertest |
From: Bot.io (Windows)ReceivedCommand cmd_browsertest from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.193.163.58:8877/47a826a7d55a7c2/output.txt |
From: Bot.io (Windows)SuccessFull output at http://54.193.163.58:8877/47a826a7d55a7c2/output.txt Total script time: 24.24 mins
|
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, with the final comments addressed; thank you!
src/display/canvas.js
Outdated
|
||
if (this.foregroundColor && this.backgroundColor) { | ||
// Get the #RRGGBB value of the color. If it's a name (e.g. CanvasText) | ||
// then it'll be converted to it's rgb value. |
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.
Grammar-nit: it's
-> its
.
"foreground": "#00FF00" | ||
}, | ||
"type": "eq" | ||
}, |
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.
Can you please add one more test here, using the same color values as in the viewer, such that we actually test that configuration as well?
E.g. something like:
{ "id": "tracemonkey-viewer-colors-eq",
"file": "pdfs/tracemonkey.pdf",
"md5": "9a192d8b1a7dc652a19835f6f08098bd",
"rounds": 1,
"pageColors": {
"background": "Canvas",
"foreground": "CanvasText"
},
"type": "eq",
"about": "Uses the same pageColors as the viewer."
},
src/display/canvas.js
Outdated
// Then for every color in the pdf, if its rounded luminance is the | ||
// same as the background one then it's replaced by the new | ||
// background color else by the foreground one. | ||
const cB = parseInt(this.defaultBackgroundColor.slice(1), 16); |
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.
Wait, does this actually work correctly in general given what sort of values are listed as supported for the background
-parameter?
Please refer to
Lines 1160 to 1164 in 7d6d6f9
* @property {Object | string} [background] - Background to use for the canvas. | |
* Any valid `canvas.fillStyle` can be used: a `DOMString` parsed as CSS | |
* <color> value, a `CanvasGradient` object (a linear or radial gradient) or | |
* a `CanvasPattern` object (a repetitive image). The default value is | |
* 'rgb(255,255,255)'. |
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.
I might be overlooking something here, but should we maybe even consider deprecating the old background
-parameter in favour of the new pageColors
one?
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.
If I'm correct, for Firefox, the background
parameter is always null so finally the default bg is always white.
Consequently, we can add a check on the the default bg color using a if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL"))
.
About this parameter in general, it has been added here:
#8413
and in considering the use case shown in the 1st comment, I guess having the parameter is still relevant but in this case it's impossible to detect what is the real background color so the stuff I added is useless.
I'm wondering if I should rename the options I added here because it's really a patch about forced colors... something like pageForcedColors
, wdyt ?
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.
Right, we probably need to keep the background
-parameter.
I'm not sure that we actually need to rename the new parameter, though.
However, we may want to explicitly skip the background
-parameter (in the canvas
-code) if pageColors
have been set and also document that in the API?
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.
It isn't always skipped it depends.
For example if someone set it to a light gray then it'll be really a light gray for some people but for ones who enabled high contrast mode they will get the new colors.
And my patch is using the default bg luminance to "guess" when use forced bg or fg so the parameter never ignored (except when it isn't a #RRGGBB).
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.
OK, then how about simply adding a note like this
*
* NOTE: This option may be partially, or completely, ignored when
* the `pageColors`-option is used.
to the existing documentation at
Lines 1160 to 1164 in 7d6d6f9
* @property {Object | string} [background] - Background to use for the canvas. | |
* Any valid `canvas.fillStyle` can be used: a `DOMString` parsed as CSS | |
* <color> value, a `CanvasGradient` object (a linear or radial gradient) or | |
* a `CanvasPattern` object (a repetitive image). The default value is | |
* 'rgb(255,255,255)'. |
and calling that good enough?
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, with all tests passing; thanks again!
- Use Canvas & CanvasText color when they don't have their default value as background and foreground colors. - The colors used to draw (stroke/fill) in a pdf are replaced by the bg/fg ones according to their luminance.
/botio test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @calixteman received. Current queue size: 0 Live output at: http://54.193.163.58:8877/e255e303c35aa70/output.txt |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @calixteman received. Current queue size: 0 Live output at: http://54.241.84.105:8877/b13109f453b2ce2/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/b13109f453b2ce2/output.txt Total script time: 26.32 mins
Image differences available at: http://54.241.84.105:8877/b13109f453b2ce2/reftest-analyzer.html#web=eq.log |
From: Bot.io (Windows)FailedFull output at http://54.193.163.58:8877/e255e303c35aa70/output.txt Total script time: 31.48 mins
|
Failures are unrelated to this change. |
/botio makeref |
From: Bot.io (Linux m4)ReceivedCommand cmd_makeref from @calixteman received. Current queue size: 0 Live output at: http://54.241.84.105:8877/cab6ed20d8acc44/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_makeref from @calixteman received. Current queue size: 0 Live output at: http://54.193.163.58:8877/8a8f493d80a2ca3/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.241.84.105:8877/cab6ed20d8acc44/output.txt Total script time: 23.05 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.193.163.58:8877/8a8f493d80a2ca3/output.txt Total script time: 25.26 mins
|
/botio makeref |
From: Bot.io (Linux m4)ReceivedCommand cmd_makeref from @calixteman received. Current queue size: 0 Live output at: http://54.241.84.105:8877/cf1b2109ca3f1fa/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_makeref from @calixteman received. Current queue size: 1 Live output at: http://54.193.163.58:8877/5aad85bab447421/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.241.84.105:8877/cf1b2109ca3f1fa/output.txt Total script time: 23.04 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.193.163.58:8877/5aad85bab447421/output.txt Total script time: 24.80 mins
|
as background and foreground colors.
ones according to their luminance.