1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #14874 from calixteman/colors

[api-minor] Improve pdf reading in high contrast mode
This commit is contained in:
calixteman 2022-05-05 21:48:19 +02:00 committed by GitHub
commit cfac6fa511
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 159 additions and 13 deletions

View file

@ -525,6 +525,10 @@ const PDFViewerApplication = {
useOnlyCssZoom: AppOptions.get("useOnlyCssZoom"),
maxCanvasPixels: AppOptions.get("maxCanvasPixels"),
enablePermissions: AppOptions.get("enablePermissions"),
pageColors: {
background: AppOptions.get("pageBackgroundColor"),
foreground: AppOptions.get("pageForegroundColor"),
},
});
pdfRenderingQueue.setViewer(this.pdfViewer);
pdfLinkService.setViewer(this.pdfViewer);

View file

@ -129,6 +129,16 @@ const defaultOptions = {
compatibility: compatibilityParams.maxCanvasPixels,
kind: OptionKind.VIEWER,
},
pageBackgroundColor: {
/** @type {string} */
value: "Canvas",
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
pageForegroundColor: {
/** @type {string} */
value: "CanvasText",
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
pdfBugEnabled: {
/** @type {boolean} */
value: typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION"),

View file

@ -116,6 +116,9 @@ const PagesCountLimit = {
* @property {IL10n} l10n - Localization service.
* @property {boolean} [enablePermissions] - Enables PDF document permissions,
* when they exist. The default value is `false`.
* @property {Object} [pageColors] - Overwrites background and foreground colors
* with user defined ones in order to improve readability in high contrast
* mode.
*/
class PDFPageViewBuffer {
@ -262,6 +265,22 @@ class BaseViewer {
this.maxCanvasPixels = options.maxCanvasPixels;
this.l10n = options.l10n || NullL10n;
this.#enablePermissions = options.enablePermissions || false;
this.pageColors = options.pageColors || null;
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
if (
options.pageColors &&
(!CSS.supports("color", options.pageColors.background) ||
!CSS.supports("color", options.pageColors.foreground))
) {
if (options.pageColors.background || options.pageColors.foreground) {
console.warn(
"Ignoring `pageColors`-option, since the browser doesn't support the values used."
);
}
this.pageColors = null;
}
}
this.defaultRenderingQueue = !options.renderingQueue;
if (this.defaultRenderingQueue) {
@ -698,6 +717,7 @@ class BaseViewer {
renderer: this.renderer,
useOnlyCssZoom: this.useOnlyCssZoom,
maxCanvasPixels: this.maxCanvasPixels,
pageColors: this.pageColors,
l10n: this.l10n,
});
this._pages.push(pageView);

View file

@ -82,6 +82,9 @@ import { NullL10n } from "./l10n_utils.js";
* @property {number} [maxCanvasPixels] - The maximum supported canvas size in
* total pixels, i.e. width * height. Use -1 for no limit. The default value
* is 4096 * 4096 (16 mega-pixels).
* @property {Object} [pageColors] - Overwrites background and foreground colors
* with user defined ones in order to improve readability in high contrast
* mode.
* @property {IL10n} l10n - Localization service.
*/
@ -118,6 +121,7 @@ class PDFPageView {
this.imageResourcesPath = options.imageResourcesPath || "";
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
this.pageColors = options.pageColors || null;
this.eventBus = options.eventBus;
this.renderingQueue = options.renderingQueue;
@ -832,6 +836,7 @@ class PDFPageView {
annotationMode: this.#annotationMode,
optionalContentConfigPromise: this._optionalContentConfigPromise,
annotationCanvasMap: this._annotationCanvasMap,
pageColors: this.pageColors,
};
const renderTask = this.pdfPage.render(renderContext);
renderTask.onContinue = function (cont) {