From fe93742c8f912dc97f51531ca37e9250ad612f60 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Wed, 6 Jul 2022 13:50:45 +0200 Subject: [PATCH] Use default colors only in forced-colors mode (bug 1778068) --- extensions/chromium/preferences_schema.json | 5 +++++ web/app.js | 12 ++++++++---- web/app_options.js | 5 +++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/extensions/chromium/preferences_schema.json b/extensions/chromium/preferences_schema.json index 4b8d686233526..799b0eaedae47 100644 --- a/extensions/chromium/preferences_schema.json +++ b/extensions/chromium/preferences_schema.json @@ -213,6 +213,11 @@ ], "default": -1 }, + "forcePageColors": { + "description": "When enabled, the pdf rendering will use the high contrast mode colors", + "type": "boolean", + "default": false + }, "pageColorsBackground": { "description": "The color is a string as defined in CSS. Its goal is to help improve readability in high contrast mode", "type": "string", diff --git a/web/app.js b/web/app.js index b4b95ca0b6d2e..5ebe755550fb2 100644 --- a/web/app.js +++ b/web/app.js @@ -516,10 +516,14 @@ const PDFViewerApplication = { const container = appConfig.mainContainer, viewer = appConfig.viewerContainer; const annotationEditorMode = AppOptions.get("annotationEditorMode"); - const pageColors = { - background: AppOptions.get("pageColorsBackground"), - foreground: AppOptions.get("pageColorsForeground"), - }; + const pageColors = + AppOptions.get("forcePageColors") || + window.matchMedia("(forced-colors: active)").matches + ? { + background: AppOptions.get("pageColorsBackground"), + foreground: AppOptions.get("pageColorsForeground"), + } + : null; this.pdfViewer = new PDFViewer({ container, diff --git a/web/app_options.js b/web/app_options.js index f0408b725e3a9..79c75b5e01db2 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -138,6 +138,11 @@ const defaultOptions = { value: 16777216, kind: OptionKind.VIEWER, }, + forcePageColors: { + /** @type {boolean} */ + value: false, + kind: OptionKind.VIEWER + OptionKind.PREFERENCE, + }, pageColorsBackground: { /** @type {string} */ value: "Canvas",