Skip to content

Commit

Permalink
Merge pull request mozilla#14959 from Snuffleupagus/pageColors-thumbn…
Browse files Browse the repository at this point in the history
…ails

Support custom `pageColors` in the thumbnails (PR 14874)
  • Loading branch information
Snuffleupagus authored May 28, 2022
2 parents e6a0a95 + 9871761 commit d80035b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
15 changes: 9 additions & 6 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,13 @@ const PDFViewerApplication = {
});
this.pdfScriptingManager = pdfScriptingManager;

const container = appConfig.mainContainer;
const viewer = appConfig.viewerContainer;
const container = appConfig.mainContainer,
viewer = appConfig.viewerContainer;
const pageColors = {
background: AppOptions.get("pageColorsBackground"),
foreground: AppOptions.get("pageColorsForeground"),
};

this.pdfViewer = new PDFViewer({
container,
viewer,
Expand All @@ -525,10 +530,7 @@ const PDFViewerApplication = {
useOnlyCssZoom: AppOptions.get("useOnlyCssZoom"),
maxCanvasPixels: AppOptions.get("maxCanvasPixels"),
enablePermissions: AppOptions.get("enablePermissions"),
pageColors: {
background: AppOptions.get("pageColorsBackground"),
foreground: AppOptions.get("pageColorsForeground"),
},
pageColors,
});
pdfRenderingQueue.setViewer(this.pdfViewer);
pdfLinkService.setViewer(this.pdfViewer);
Expand All @@ -540,6 +542,7 @@ const PDFViewerApplication = {
renderingQueue: pdfRenderingQueue,
linkService: pdfLinkService,
l10n: this.l10n,
pageColors,
});
pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);

Expand Down
12 changes: 7 additions & 5 deletions web/base_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,15 @@ class BaseViewer {

if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
if (
options.pageColors &&
(!CSS.supports("color", options.pageColors.background) ||
!CSS.supports("color", options.pageColors.foreground))
this.pageColors &&
!(
CSS.supports("color", this.pageColors.background) &&
CSS.supports("color", this.pageColors.foreground)
)
) {
if (options.pageColors.background || options.pageColors.foreground) {
if (this.pageColors.background || this.pageColors.foreground) {
console.warn(
"Ignoring `pageColors`-option, since the browser doesn't support the values used."
"BaseViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used."
);
}
this.pageColors = null;
Expand Down
6 changes: 6 additions & 0 deletions web/pdf_thumbnail_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const THUMBNAIL_WIDTH = 98; // px
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
* @property {function} checkSetImageDisabled
* @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.
*/

class TempImageFactory {
Expand Down Expand Up @@ -87,6 +90,7 @@ class PDFThumbnailView {
renderingQueue,
checkSetImageDisabled,
l10n,
pageColors,
}) {
this.id = id;
this.renderingId = "thumbnail" + id;
Expand All @@ -97,6 +101,7 @@ class PDFThumbnailView {
this.viewport = defaultViewport;
this.pdfPageRotate = defaultViewport.rotation;
this._optionalContentConfigPromise = optionalContentConfigPromise || null;
this.pageColors = pageColors || null;

this.linkService = linkService;
this.renderingQueue = renderingQueue;
Expand Down Expand Up @@ -320,6 +325,7 @@ class PDFThumbnailView {
transform,
viewport: drawViewport,
optionalContentConfigPromise: this._optionalContentConfigPromise,
pageColors: this.pageColors,
};
const renderTask = (this.renderTask = pdfPage.render(renderContext));
renderTask.onContinue = renderContinueCallback;
Expand Down
31 changes: 30 additions & 1 deletion web/pdf_thumbnail_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

/**
Expand All @@ -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();
Expand Down Expand Up @@ -210,6 +238,7 @@ class PDFThumbnailViewer {
renderingQueue: this.renderingQueue,
checkSetImageDisabled,
l10n: this.l10n,
pageColors: this.pageColors,
});
this._thumbnails.push(thumbnail);
}
Expand Down

0 comments on commit d80035b

Please sign in to comment.