mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
[api-minor] Extend general transfer function support to browsers without OffscreenCanvas
This patch extends PR 16115 to work in all browsers, regardless of their `OffscreenCanvas` support, such that transfer functions will be applied to general rendering (and not just image data). In order to do this we introduce the `BaseFilterFactory` that is then extended in browsers/Node.js environments, similar to all the other factories used in the API, such that we always have the necessary factory available in `src/display/canvas.js`. These changes help simplify the existing `putBinaryImageData` function, and the new method can easily be stubbed-out in the Firefox PDF Viewer. *Please note:* This patch removes the old *partial* transfer function support, which only applied to image data, from Node.js environments since the `node-canvas` package currently doesn't support filters. However, this should hopefully be fine given that: - Transfer functions are not very commonly used in PDF documents. - Browsers in general, and Firefox in particular, are the *primary* development target for the PDF.js library. - The FAQ only lists Node.js as *mostly* supported, see https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support
This commit is contained in:
parent
945855a2b8
commit
fc055dbd80
8 changed files with 92 additions and 102 deletions
|
@ -46,8 +46,8 @@ import {
|
|||
deprecated,
|
||||
DOMCanvasFactory,
|
||||
DOMCMapReaderFactory,
|
||||
DOMFilterFactory,
|
||||
DOMStandardFontDataFactory,
|
||||
FilterFactory,
|
||||
isDataScheme,
|
||||
isValidFetchUrl,
|
||||
loadScript,
|
||||
|
@ -71,17 +71,20 @@ const DELAYED_CLEANUP_TIMEOUT = 5000; // ms
|
|||
|
||||
let DefaultCanvasFactory = DOMCanvasFactory;
|
||||
let DefaultCMapReaderFactory = DOMCMapReaderFactory;
|
||||
let DefaultFilterFactory = DOMFilterFactory;
|
||||
let DefaultStandardFontDataFactory = DOMStandardFontDataFactory;
|
||||
|
||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS) {
|
||||
const {
|
||||
NodeCanvasFactory,
|
||||
NodeCMapReaderFactory,
|
||||
NodeFilterFactory,
|
||||
NodeStandardFontDataFactory,
|
||||
} = require("./node_utils.js");
|
||||
|
||||
DefaultCanvasFactory = NodeCanvasFactory;
|
||||
DefaultCMapReaderFactory = NodeCMapReaderFactory;
|
||||
DefaultFilterFactory = NodeFilterFactory;
|
||||
DefaultStandardFontDataFactory = NodeStandardFontDataFactory;
|
||||
}
|
||||
|
||||
|
@ -342,7 +345,7 @@ function getDocument(src) {
|
|||
const canvasFactory =
|
||||
src.canvasFactory || new DefaultCanvasFactory({ ownerDocument });
|
||||
const filterFactory =
|
||||
src.filterFactory || new FilterFactory({ docId, ownerDocument });
|
||||
src.filterFactory || new DefaultFilterFactory({ docId, ownerDocument });
|
||||
|
||||
// Parameters only intended for development/testing purposes.
|
||||
const styleElement =
|
||||
|
@ -784,6 +787,13 @@ class PDFDocumentProxy {
|
|||
return this._transport.annotationStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Object} The filter factory instance.
|
||||
*/
|
||||
get filterFactory() {
|
||||
return this._transport.filterFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {number} Total number of pages in the PDF file.
|
||||
*/
|
||||
|
@ -3324,7 +3334,7 @@ class InternalRenderTask {
|
|||
this.commonObjs,
|
||||
this.objs,
|
||||
this.canvasFactory,
|
||||
isOffscreenCanvasSupported ? this.filterFactory : null,
|
||||
this.filterFactory,
|
||||
{ optionalContentConfig },
|
||||
this.annotationCanvasMap,
|
||||
this.pageColors
|
||||
|
@ -3429,6 +3439,7 @@ export {
|
|||
build,
|
||||
DefaultCanvasFactory,
|
||||
DefaultCMapReaderFactory,
|
||||
DefaultFilterFactory,
|
||||
DefaultStandardFontDataFactory,
|
||||
getDocument,
|
||||
LoopbackPort,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue