Merge pull request #16608 from Snuffleupagus/PDFPageView-refactor-filterFactory

Re-factor how HCM highlight-filters are handled in the viewer components (PR 16593 follow-up)
This commit is contained in:
Jonas Jenwald 2023-06-27 15:13:00 +02:00 committed by GitHub
commit 50488d7a47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 24 deletions

View File

@ -1381,6 +1381,13 @@ class PDFPageProxy {
return this._transport.getPageJSActions(this._pageIndex); return this._transport.getPageJSActions(this._pageIndex);
} }
/**
* @type {Object} The filter factory instance.
*/
get filterFactory() {
return this._transport.filterFactory;
}
/** /**
* @type {boolean} True if only XFA form. * @type {boolean} True if only XFA form.
*/ */

View File

@ -13,8 +13,6 @@
* limitations under the License. * limitations under the License.
*/ */
// eslint-disable-next-line max-len
/** @typedef {import("../src/display/base_factory.js").BaseFilterFactory} BaseFilterFactory */
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ /** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
@ -86,8 +84,6 @@ import { XfaLayerBuilder } from "./xfa_layer_builder.js";
* @property {IL10n} [l10n] - Localization service. * @property {IL10n} [l10n] - Localization service.
* @property {function} [layerProperties] - The function that is used to lookup * @property {function} [layerProperties] - The function that is used to lookup
* the necessary layer-properties. * the necessary layer-properties.
* @property {BaseFilterFactory} [filterFactory] - Factory to create some SVG
* filters.
*/ */
const MAX_CANVAS_PIXELS = compatibilityParams.maxCanvasPixels || 16777216; const MAX_CANVAS_PIXELS = compatibilityParams.maxCanvasPixels || 16777216;
@ -174,6 +170,7 @@ class PDFPageView {
this.resume = null; this.resume = null;
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
this._isStandalone = !this.renderingQueue?.hasViewer(); this._isStandalone = !this.renderingQueue?.hasViewer();
this._container = container;
} }
this._annotationCanvasMap = null; this._annotationCanvasMap = null;
@ -207,21 +204,6 @@ class PDFPageView {
"--scale-factor", "--scale-factor",
this.scale * PixelsPerInch.PDF_TO_CSS_UNITS this.scale * PixelsPerInch.PDF_TO_CSS_UNITS
); );
if (
options.filterFactory &&
(this.pageColors?.foreground === "CanvasText" ||
this.pageColors?.background === "Canvas")
) {
container?.style.setProperty(
"--hcm-highligh-filter",
options.filterFactory.addHighlightHCMFilter(
"CanvasText",
"Canvas",
"HighlightText",
"Highlight"
)
);
}
const { optionalContentConfigPromise } = options; const { optionalContentConfigPromise } = options;
if (optionalContentConfigPromise) { if (optionalContentConfigPromise) {
@ -295,6 +277,22 @@ class PDFPageView {
} }
setPdfPage(pdfPage) { setPdfPage(pdfPage) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
this._isStandalone &&
(this.pageColors?.foreground === "CanvasText" ||
this.pageColors?.background === "Canvas")
) {
this._container?.style.setProperty(
"--hcm-highligh-filter",
pdfPage.filterFactory.addHighlightHCMFilter(
"CanvasText",
"Canvas",
"HighlightText",
"Highlight"
)
);
}
this.pdfPage = pdfPage; this.pdfPage = pdfPage;
this.pdfPageRotate = pdfPage.rotate; this.pdfPageRotate = pdfPage.rotate;
@ -585,10 +583,7 @@ class PDFPageView {
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
this._isStandalone this._isStandalone
) { ) {
this.div.parentNode?.style.setProperty( this._container?.style.setProperty("--scale-factor", this.viewport.scale);
"--scale-factor",
this.viewport.scale
);
} }
let isScalingRestricted = false; let isScalingRestricted = false;

View File

@ -916,7 +916,6 @@ class PDFViewer {
pageColors: this.pageColors, pageColors: this.pageColors,
l10n: this.l10n, l10n: this.l10n,
layerProperties, layerProperties,
filterFactory: pdfDocument.filterFactory,
}); });
this._pages.push(pageView); this._pages.push(pageView);
} }