Support custom pageColors in the thumbnails (PR 14874)

Currently, when non-standard `pageColors` are specified, the thumbnails will look inconsistent depending on how they're created.
The thumbnails that are created by downsizing the *page* canvases will obviously use the `pageColors` as intended, however the thumbnails which are rendered *directly* will always use the default colors.
This commit is contained in:
Jonas Jenwald 2022-05-26 09:45:05 +02:00
parent 5b02c685d6
commit 9871761949
4 changed files with 52 additions and 12 deletions

View file

@ -40,6 +40,9 @@ const THUMBNAIL_SELECTED_CLASS = "selected";
* @property {IPDFLinkService} linkService - The navigation/linking service.
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
* @property {IL10n} l10n - Localization service.
* @property {Object} [pageColors] - Overwrites background and foreground colors
* with user defined ones in order to improve readability in high contrast
* mode.
*/
/**
@ -49,11 +52,36 @@ class PDFThumbnailViewer {
/**
* @param {PDFThumbnailViewerOptions} options
*/
constructor({ container, eventBus, linkService, renderingQueue, l10n }) {
constructor({
container,
eventBus,
linkService,
renderingQueue,
l10n,
pageColors,
}) {
this.container = container;
this.linkService = linkService;
this.renderingQueue = renderingQueue;
this.l10n = l10n;
this.pageColors = pageColors || null;
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
if (
this.pageColors &&
!(
CSS.supports("color", this.pageColors.background) &&
CSS.supports("color", this.pageColors.foreground)
)
) {
if (this.pageColors.background || this.pageColors.foreground) {
console.warn(
"PDFThumbnailViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used."
);
}
this.pageColors = null;
}
}
this.scroll = watchScroll(this.container, this._scrollUpdated.bind(this));
this._resetView();
@ -210,6 +238,7 @@ class PDFThumbnailViewer {
renderingQueue: this.renderingQueue,
checkSetImageDisabled,
l10n: this.l10n,
pageColors: this.pageColors,
});
this._thumbnails.push(thumbnail);
}