[api-minor] Improve pdf reading in high contrast mode

- 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.
This commit is contained in:
Calixte Denizet 2022-05-04 15:37:13 +02:00
parent 8135d7ccf6
commit c8afd6ce8c
9 changed files with 159 additions and 13 deletions

View file

@ -1169,6 +1169,12 @@ class PDFDocumentProxy {
* <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)'.
*
* NOTE: This option may be partially, or completely, ignored when the
* `pageColors`-option is used.
* @property {Object} [pageColors] - Overwrites background and foreground colors
* with user defined ones in order to improve readability in high contrast
* mode.
* @property {Promise<OptionalContentConfig>} [optionalContentConfigPromise] -
* A promise that should resolve with an {@link OptionalContentConfig}
* created from `PDFDocumentProxy.getOptionalContentConfig`. If `null`,
@ -1393,6 +1399,7 @@ class PDFPageProxy {
background = null,
optionalContentConfigPromise = null,
annotationCanvasMap = null,
pageColors = null,
}) {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC")) {
if (arguments[0]?.renderInteractiveForms !== undefined) {
@ -1516,6 +1523,7 @@ class PDFPageProxy {
canvasFactory: canvasFactoryInstance,
useRequestAnimationFrame: !intentPrint,
pdfBug: this._pdfBug,
pageColors,
});
(intentState.renderTasks ||= new Set()).add(internalRenderTask);
@ -3219,6 +3227,7 @@ class InternalRenderTask {
canvasFactory,
useRequestAnimationFrame = false,
pdfBug = false,
pageColors = null,
}) {
this.callback = callback;
this.params = params;
@ -3230,6 +3239,7 @@ class InternalRenderTask {
this._pageIndex = pageIndex;
this.canvasFactory = canvasFactory;
this._pdfBug = pdfBug;
this.pageColors = pageColors;
this.running = false;
this.graphicsReadyCallback = null;
@ -3284,7 +3294,8 @@ class InternalRenderTask {
this.canvasFactory,
imageLayer,
optionalContentConfig,
this.annotationCanvasMap
this.annotationCanvasMap,
this.pageColors
);
this.gfx.beginDrawing({
transform,