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

Ignore pageColors when the background/foreground is identical (PR 14874 follow-up) #14887

Merged
merged 2 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extensions/chromium/preferences_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@
],
"default": -1
},
"pageBackgroundColor": {
"pageColorsBackground": {
"description": "The color is a string as defined in CSS. Its goal is to help improve readability in high contrast mode",
"type": "string",
"default": "Canvas"
},
"pageForegroundColor": {
"pageColorsForeground": {
"description": "The color is a string as defined in CSS. Its goal is to help improve readability in high contrast mode",
"type": "string",
"default": "CanvasText"
Expand Down
14 changes: 13 additions & 1 deletion src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,19 @@ class CanvasGraphics {
typeof defaultBg === "string" && /^#[0-9A-Fa-f]{6}$/.test(defaultBg);
}

if ((fg === "#000000" && bg === "#ffffff") || !isValidDefaultBg) {
if (
(fg === "#000000" && bg === "#ffffff") ||
fg === bg ||
!isValidDefaultBg
) {
// Ignore the `pageColors`-option when:
// - The computed background/foreground colors have their default
// values, i.e. white/black.
// - The computed background/foreground colors are identical,
// since that'd render the `canvas` mostly blank.
// - The `background`-option has a value that's incompatible with
// the `pageColors`-values.
//
this.foregroundColor = this.backgroundColor = null;
} else {
// https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_Colors_and_Luminance
Expand Down
4 changes: 2 additions & 2 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,8 @@ const PDFViewerApplication = {
maxCanvasPixels: AppOptions.get("maxCanvasPixels"),
enablePermissions: AppOptions.get("enablePermissions"),
pageColors: {
background: AppOptions.get("pageBackgroundColor"),
foreground: AppOptions.get("pageForegroundColor"),
background: AppOptions.get("pageColorsBackground"),
foreground: AppOptions.get("pageColorsForeground"),
},
});
pdfRenderingQueue.setViewer(this.pdfViewer);
Expand Down
4 changes: 2 additions & 2 deletions web/app_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ const defaultOptions = {
compatibility: compatibilityParams.maxCanvasPixels,
kind: OptionKind.VIEWER,
},
pageBackgroundColor: {
pageColorsBackground: {
/** @type {string} */
value: "Canvas",
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
pageForegroundColor: {
pageColorsForeground: {
/** @type {string} */
value: "CanvasText",
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
Expand Down