diff options
Diffstat (limited to 'js/pdfjs/build/pdf.js')
-rw-r--r-- | js/pdfjs/build/pdf.js | 1166 |
1 files changed, 694 insertions, 472 deletions
diff --git a/js/pdfjs/build/pdf.js b/js/pdfjs/build/pdf.js index 33b6253..fde8904 100644 --- a/js/pdfjs/build/pdf.js +++ b/js/pdfjs/build/pdf.js @@ -46,59 +46,22 @@ exports.addLinkAttributes = addLinkAttributes; exports.deprecated = deprecated; exports.getFilenameFromUrl = getFilenameFromUrl; exports.getPdfFilenameFromUrl = getPdfFilenameFromUrl; +exports.getXfaPageViewport = getXfaPageViewport; exports.isDataScheme = isDataScheme; -exports.isFetchSupported = isFetchSupported; exports.isPdfFile = isPdfFile; exports.isValidFetchUrl = isValidFetchUrl; exports.loadScript = loadScript; -exports.StatTimer = exports.RenderingCancelledException = exports.PDFDateString = exports.PageViewport = exports.LinkTarget = exports.DOMSVGFactory = exports.DOMCMapReaderFactory = exports.DOMCanvasFactory = exports.DEFAULT_LINK_REL = exports.BaseCMapReaderFactory = exports.BaseCanvasFactory = void 0; +exports.StatTimer = exports.RenderingCancelledException = exports.PDFDateString = exports.PageViewport = exports.LinkTarget = exports.DOMSVGFactory = exports.DOMStandardFontDataFactory = exports.DOMCMapReaderFactory = exports.DOMCanvasFactory = exports.DEFAULT_LINK_REL = void 0; var _util = __w_pdfjs_require__(2); +var _base_factory = __w_pdfjs_require__(5); + const DEFAULT_LINK_REL = "noopener noreferrer nofollow"; exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL; const SVG_NS = "http://www.w3.org/2000/svg"; -class BaseCanvasFactory { - constructor() { - if (this.constructor === BaseCanvasFactory) { - (0, _util.unreachable)("Cannot initialize BaseCanvasFactory."); - } - } - - create(width, height) { - (0, _util.unreachable)("Abstract method `create` called."); - } - - reset(canvasAndContext, width, height) { - if (!canvasAndContext.canvas) { - throw new Error("Canvas is not specified"); - } - - if (width <= 0 || height <= 0) { - throw new Error("Invalid canvas size"); - } - - canvasAndContext.canvas.width = width; - canvasAndContext.canvas.height = height; - } - - destroy(canvasAndContext) { - if (!canvasAndContext.canvas) { - throw new Error("Canvas is not specified"); - } - - canvasAndContext.canvas.width = 0; - canvasAndContext.canvas.height = 0; - canvasAndContext.canvas = null; - canvasAndContext.context = null; - } - -} - -exports.BaseCanvasFactory = BaseCanvasFactory; - -class DOMCanvasFactory extends BaseCanvasFactory { +class DOMCanvasFactory extends _base_factory.BaseCanvasFactory { constructor({ ownerDocument = globalThis.document } = {}) { @@ -106,123 +69,71 @@ class DOMCanvasFactory extends BaseCanvasFactory { this._document = ownerDocument; } - create(width, height) { - if (width <= 0 || height <= 0) { - throw new Error("Invalid canvas size"); - } - + _createCanvas(width, height) { const canvas = this._document.createElement("canvas"); - const context = canvas.getContext("2d"); canvas.width = width; canvas.height = height; - return { - canvas, - context - }; + return canvas; } } exports.DOMCanvasFactory = DOMCanvasFactory; -class BaseCMapReaderFactory { - constructor({ - baseUrl = null, - isCompressed = false - }) { - if (this.constructor === BaseCMapReaderFactory) { - (0, _util.unreachable)("Cannot initialize BaseCMapReaderFactory."); - } - - this.baseUrl = baseUrl; - this.isCompressed = isCompressed; - } - - async fetch({ - name - }) { - if (!this.baseUrl) { - throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.'); - } +async function fetchData(url, asTypedArray = false) { + if (isValidFetchUrl(url, document.baseURI)) { + const response = await fetch(url); - if (!name) { - throw new Error("CMap name must be specified."); + if (!response.ok) { + throw new Error(response.statusText); } - const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : ""); - const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE; - return this._fetchData(url, compressionType).catch(reason => { - throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`); - }); - } - - _fetchData(url, compressionType) { - (0, _util.unreachable)("Abstract method `_fetchData` called."); + return asTypedArray ? new Uint8Array(await response.arrayBuffer()) : (0, _util.stringToBytes)(await response.text()); } -} + return new Promise((resolve, reject) => { + const request = new XMLHttpRequest(); + request.open("GET", url, true); -exports.BaseCMapReaderFactory = BaseCMapReaderFactory; + if (asTypedArray) { + request.responseType = "arraybuffer"; + } -class DOMCMapReaderFactory extends BaseCMapReaderFactory { - _fetchData(url, compressionType) { - if (isFetchSupported() && isValidFetchUrl(url, document.baseURI)) { - return fetch(url).then(async response => { - if (!response.ok) { - throw new Error(response.statusText); - } + request.onreadystatechange = () => { + if (request.readyState !== XMLHttpRequest.DONE) { + return; + } - let cMapData; + if (request.status === 200 || request.status === 0) { + let data; - if (this.isCompressed) { - cMapData = new Uint8Array(await response.arrayBuffer()); - } else { - cMapData = (0, _util.stringToBytes)(await response.text()); + if (asTypedArray && request.response) { + data = new Uint8Array(request.response); + } else if (!asTypedArray && request.responseText) { + data = (0, _util.stringToBytes)(request.responseText); } - return { - cMapData, - compressionType - }; - }); - } - - return new Promise((resolve, reject) => { - const request = new XMLHttpRequest(); - request.open("GET", url, true); - - if (this.isCompressed) { - request.responseType = "arraybuffer"; - } - - request.onreadystatechange = () => { - if (request.readyState !== XMLHttpRequest.DONE) { + if (data) { + resolve(data); return; } + } - if (request.status === 200 || request.status === 0) { - let cMapData; - - if (this.isCompressed && request.response) { - cMapData = new Uint8Array(request.response); - } else if (!this.isCompressed && request.responseText) { - cMapData = (0, _util.stringToBytes)(request.responseText); - } + reject(new Error(request.statusText)); + }; - if (cMapData) { - resolve({ - cMapData, - compressionType - }); - return; - } - } + request.send(null); + }); +} - reject(new Error(request.statusText)); +class DOMCMapReaderFactory extends _base_factory.BaseCMapReaderFactory { + _fetchData(url, compressionType) { + return fetchData(url, this.isCompressed).then(data => { + return { + cMapData: data, + compressionType }; - - request.send(null); }); } @@ -230,20 +141,17 @@ class DOMCMapReaderFactory extends BaseCMapReaderFactory { exports.DOMCMapReaderFactory = DOMCMapReaderFactory; -class DOMSVGFactory { - create(width, height) { - (0, _util.assert)(width > 0 && height > 0, "Invalid SVG dimensions"); - const svg = document.createElementNS(SVG_NS, "svg:svg"); - svg.setAttribute("version", "1.1"); - svg.setAttribute("width", width + "px"); - svg.setAttribute("height", height + "px"); - svg.setAttribute("preserveAspectRatio", "none"); - svg.setAttribute("viewBox", "0 0 " + width + " " + height); - return svg; +class DOMStandardFontDataFactory extends _base_factory.BaseStandardFontDataFactory { + _fetchData(url) { + return fetchData(url, true); } - createElement(type) { - (0, _util.assert)(typeof type === "string", "Invalid SVG element type"); +} + +exports.DOMStandardFontDataFactory = DOMStandardFontDataFactory; + +class DOMSVGFactory extends _base_factory.BaseSVGFactory { + _createSVG(type) { return document.createElementNS(SVG_NS, type); } @@ -535,10 +443,6 @@ class StatTimer { exports.StatTimer = StatTimer; -function isFetchSupported() { - return typeof fetch !== "undefined" && typeof Response !== "undefined" && "body" in Response.prototype && typeof ReadableStream !== "undefined"; -} - function isValidFetchUrl(url, baseUrl) { try { const { @@ -625,6 +529,22 @@ class PDFDateString { exports.PDFDateString = PDFDateString; +function getXfaPageViewport(xfaPage, { + scale = 1, + rotation = 0 +}) { + const { + width, + height + } = xfaPage.attributes.style; + const viewBox = [0, 0, parseInt(width), parseInt(height)]; + return new PageViewport({ + viewBox, + scale, + rotation + }); +} + /***/ }), /* 2 */ /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => { @@ -844,6 +764,7 @@ exports.StreamType = StreamType; const FontType = { UNKNOWN: "UNKNOWN", TYPE1: "TYPE1", + TYPE1STANDARD: "TYPE1STANDARD", TYPE1C: "TYPE1C", CIDFONTTYPE0: "CIDFONTTYPE0", CIDFONTTYPE0C: "CIDFONTTYPE0C", @@ -1557,21 +1478,197 @@ exports.isNodeJS = isNodeJS; Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.BaseSVGFactory = exports.BaseStandardFontDataFactory = exports.BaseCMapReaderFactory = exports.BaseCanvasFactory = void 0; + +var _util = __w_pdfjs_require__(2); + +class BaseCanvasFactory { + constructor() { + if (this.constructor === BaseCanvasFactory) { + (0, _util.unreachable)("Cannot initialize BaseCanvasFactory."); + } + } + + create(width, height) { + if (width <= 0 || height <= 0) { + throw new Error("Invalid canvas size"); + } + + const canvas = this._createCanvas(width, height); + + return { + canvas, + context: canvas.getContext("2d") + }; + } + + reset(canvasAndContext, width, height) { + if (!canvasAndContext.canvas) { + throw new Error("Canvas is not specified"); + } + + if (width <= 0 || height <= 0) { + throw new Error("Invalid canvas size"); + } + + canvasAndContext.canvas.width = width; + canvasAndContext.canvas.height = height; + } + + destroy(canvasAndContext) { + if (!canvasAndContext.canvas) { + throw new Error("Canvas is not specified"); + } + + canvasAndContext.canvas.width = 0; + canvasAndContext.canvas.height = 0; + canvasAndContext.canvas = null; + canvasAndContext.context = null; + } + + _createCanvas(width, height) { + (0, _util.unreachable)("Abstract method `_createCanvas` called."); + } + +} + +exports.BaseCanvasFactory = BaseCanvasFactory; + +class BaseCMapReaderFactory { + constructor({ + baseUrl = null, + isCompressed = false + }) { + if (this.constructor === BaseCMapReaderFactory) { + (0, _util.unreachable)("Cannot initialize BaseCMapReaderFactory."); + } + + this.baseUrl = baseUrl; + this.isCompressed = isCompressed; + } + + async fetch({ + name + }) { + if (!this.baseUrl) { + throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.'); + } + + if (!name) { + throw new Error("CMap name must be specified."); + } + + const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : ""); + const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE; + return this._fetchData(url, compressionType).catch(reason => { + throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`); + }); + } + + _fetchData(url, compressionType) { + (0, _util.unreachable)("Abstract method `_fetchData` called."); + } + +} + +exports.BaseCMapReaderFactory = BaseCMapReaderFactory; + +class BaseStandardFontDataFactory { + constructor({ + baseUrl = null + }) { + if (this.constructor === BaseStandardFontDataFactory) { + (0, _util.unreachable)("Cannot initialize BaseStandardFontDataFactory."); + } + + this.baseUrl = baseUrl; + } + + async fetch({ + filename + }) { + if (!this.baseUrl) { + throw new Error('The standard font "baseUrl" parameter must be specified, ensure that ' + 'the "standardFontDataUrl" API parameter is provided.'); + } + + if (!filename) { + throw new Error("Font filename must be specified."); + } + + const url = `${this.baseUrl}${filename}`; + return this._fetchData(url).catch(reason => { + throw new Error(`Unable to load font data at: ${url}`); + }); + } + + _fetchData(url) { + (0, _util.unreachable)("Abstract method `_fetchData` called."); + } + +} + +exports.BaseStandardFontDataFactory = BaseStandardFontDataFactory; + +class BaseSVGFactory { + constructor() { + if (this.constructor === BaseSVGFactory) { + (0, _util.unreachable)("Cannot initialize BaseSVGFactory."); + } + } + + create(width, height) { + if (width <= 0 || height <= 0) { + throw new Error("Invalid SVG dimensions"); + } + + const svg = this._createSVG("svg:svg"); + + svg.setAttribute("version", "1.1"); + svg.setAttribute("width", `${width}px`); + svg.setAttribute("height", `${height}px`); + svg.setAttribute("preserveAspectRatio", "none"); + svg.setAttribute("viewBox", `0 0 ${width} ${height}`); + return svg; + } + + createElement(type) { + if (typeof type !== "string") { + throw new Error("Invalid SVG element type"); + } + + return this._createSVG(type); + } + + _createSVG(type) { + (0, _util.unreachable)("Abstract method `_createSVG` called."); + } + +} + +exports.BaseSVGFactory = BaseSVGFactory; + +/***/ }), +/* 6 */ +/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => { + + + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); exports.getDocument = getDocument; exports.setPDFNetworkStreamFactory = setPDFNetworkStreamFactory; -exports.version = exports.PDFWorker = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFDataRangeTransport = exports.LoopbackPort = exports.DefaultCMapReaderFactory = exports.DefaultCanvasFactory = exports.build = void 0; +exports.version = exports.PDFWorker = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFDataRangeTransport = exports.LoopbackPort = exports.DefaultStandardFontDataFactory = exports.DefaultCMapReaderFactory = exports.DefaultCanvasFactory = exports.build = void 0; var _util = __w_pdfjs_require__(2); var _display_utils = __w_pdfjs_require__(1); -var _font_loader = __w_pdfjs_require__(6); - -var _node_utils = __w_pdfjs_require__(7); +var _font_loader = __w_pdfjs_require__(7); -var _annotation_storage = __w_pdfjs_require__(8); +var _node_utils = __w_pdfjs_require__(8); -var _api_compatibility = __w_pdfjs_require__(9); +var _annotation_storage = __w_pdfjs_require__(9); var _canvas = __w_pdfjs_require__(10); @@ -1593,6 +1690,8 @@ const DefaultCanvasFactory = _is_node.isNodeJS ? _node_utils.NodeCanvasFactory : exports.DefaultCanvasFactory = DefaultCanvasFactory; const DefaultCMapReaderFactory = _is_node.isNodeJS ? _node_utils.NodeCMapReaderFactory : _display_utils.DOMCMapReaderFactory; exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory; +const DefaultStandardFontDataFactory = _is_node.isNodeJS ? _node_utils.NodeStandardFontDataFactory : _display_utils.DOMStandardFontDataFactory; +exports.DefaultStandardFontDataFactory = DefaultStandardFontDataFactory; let createPDFNetworkStream; function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) { @@ -1681,6 +1780,7 @@ function getDocument(src) { params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE; params.CMapReaderFactory = params.CMapReaderFactory || DefaultCMapReaderFactory; + params.StandardFontDataFactory = params.StandardFontDataFactory || DefaultStandardFontDataFactory; params.ignoreErrors = params.stopAtErrors !== true; params.fontExtraProperties = params.fontExtraProperties === true; params.pdfBug = params.pdfBug === true; @@ -1694,12 +1794,20 @@ function getDocument(src) { params.maxImageSize = -1; } + if (typeof params.useWorkerFetch !== "boolean") { + params.useWorkerFetch = params.CMapReaderFactory === _display_utils.DOMCMapReaderFactory && params.StandardFontDataFactory === _display_utils.DOMStandardFontDataFactory; + } + if (typeof params.isEvalSupported !== "boolean") { params.isEvalSupported = true; } if (typeof params.disableFontFace !== "boolean") { - params.disableFontFace = _api_compatibility.apiCompatibilityParams.disableFontFace || false; + params.disableFontFace = _is_node.isNodeJS; + } + + if (typeof params.useSystemFonts !== "boolean") { + params.useSystemFonts = !_is_node.isNodeJS && !params.disableFontFace; } if (typeof params.ownerDocument === "undefined") { @@ -1792,7 +1900,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { return worker.messageHandler.sendWithPromise("GetDocRequest", { docId, - apiVersion: '2.9.359', + apiVersion: '2.10.377', source: { data: source.data, url: source.url, @@ -1808,7 +1916,10 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { ignoreErrors: source.ignoreErrors, isEvalSupported: source.isEvalSupported, fontExtraProperties: source.fontExtraProperties, - enableXfa: source.enableXfa + enableXfa: source.enableXfa, + useSystemFonts: source.useSystemFonts, + cMapUrl: source.useWorkerFetch ? source.cMapUrl : null, + standardFontDataUrl: source.useWorkerFetch ? source.standardFontDataUrl : null }).then(function (workerId) { if (worker.destroyed) { throw new Error("Worker was destroyed"); @@ -1933,6 +2044,13 @@ class PDFDocumentProxy { constructor(pdfInfo, transport) { this._pdfInfo = pdfInfo; this._transport = transport; + Object.defineProperty(this, "fingerprint", { + get() { + (0, _display_utils.deprecated)("`PDFDocumentProxy.fingerprint`, " + "please use `PDFDocumentProxy.fingerprints` instead."); + return this.fingerprints[0]; + } + + }); } get annotationStorage() { @@ -1943,12 +2061,16 @@ class PDFDocumentProxy { return this._pdfInfo.numPages; } - get fingerprint() { - return this._pdfInfo.fingerprint; + get fingerprints() { + return this._pdfInfo.fingerprints; } get isPureXfa() { - return this._pdfInfo.isPureXfa; + return !!this._transport._htmlForXfa; + } + + get allXfaHtml() { + return this._transport._htmlForXfa; } getPage(pageNumber) { @@ -2048,10 +2170,6 @@ class PDFDocumentProxy { } saveDocument() { - if (arguments.length > 0) { - (0, _display_utils.deprecated)("saveDocument no longer accepts any options."); - } - if (this._transport.annotationStorage.size <= 0) { (0, _display_utils.deprecated)("saveDocument called while `annotationStorage` is empty, " + "please use the getData-method instead."); } @@ -2131,9 +2249,11 @@ class PDFPageProxy { getAnnotations({ intent = null } = {}) { - if (!this._annotationsPromise || this._annotationsIntent !== intent) { - this._annotationsPromise = this._transport.getAnnotations(this._pageIndex, intent); - this._annotationsIntent = intent; + const renderingIntent = intent === "display" || intent === "print" ? intent : null; + + if (!this._annotationsPromise || this._annotationsIntent !== renderingIntent) { + this._annotationsPromise = this._transport.getAnnotations(this._pageIndex, renderingIntent); + this._annotationsIntent = renderingIntent; } return this._annotationsPromise; @@ -2143,8 +2263,8 @@ class PDFPageProxy { return this._jsActionsPromise || (this._jsActionsPromise = this._transport.getPageJSActions(this._pageIndex)); } - getXfa() { - return this._xfaPromise || (this._xfaPromise = this._transport.getPageXfa(this._pageIndex)); + async getXfa() { + return this._transport._htmlForXfa?.children[this._pageIndex] || null; } render({ @@ -2161,11 +2281,6 @@ class PDFPageProxy { }) { var _intentState; - if (arguments[0]?.annotationStorage !== undefined) { - (0, _display_utils.deprecated)("render no longer accepts an `annotationStorage` option, " + "please use the `includeAnnotationStorage`-boolean instead."); - includeAnnotationStorage || (includeAnnotationStorage = !!arguments[0].annotationStorage); - } - if (this._stats) { this._stats.time("Overall"); } @@ -2280,7 +2395,9 @@ class PDFPageProxy { return renderTask; } - getOperatorList() { + getOperatorList({ + intent = "display" + } = {}) { function operatorListChanged() { if (intentState.operatorList.lastChunk) { intentState.opListReadCapability.resolve(intentState.operatorList); @@ -2288,7 +2405,7 @@ class PDFPageProxy { } } - const renderingIntent = "oplist"; + const renderingIntent = `oplist-${intent === "print" ? "print" : "display"}`; let intentState = this._intentStates.get(renderingIntent); @@ -2391,7 +2508,7 @@ class PDFPageProxy { force: true }); - if (intent === "oplist") { + if (intent.startsWith("oplist-")) { continue; } @@ -2404,7 +2521,6 @@ class PDFPageProxy { this.objs.clear(); this._annotationsPromise = null; this._jsActionsPromise = null; - this._xfaPromise = null; this._structTreePromise = null; this.pendingCleanup = false; return Promise.all(waitOn); @@ -2434,7 +2550,6 @@ class PDFPageProxy { this.objs.clear(); this._annotationsPromise = null; this._jsActionsPromise = null; - this._xfaPromise = null; this._structTreePromise = null; if (resetStats && this._stats) { @@ -2600,6 +2715,10 @@ class LoopbackPort { postMessage(obj, transfers) { function cloneValue(value) { + if (typeof value === "function" || typeof value === "symbol" || value instanceof URL) { + throw new Error(`LoopbackPort.postMessage - cannot clone: ${value?.toString()}`); + } + if (typeof value !== "object" || value === null) { return value; } @@ -2643,10 +2762,6 @@ class LoopbackPort { return result; } - if (value instanceof URL) { - throw new Error(`LoopbackPort.postMessage - cannot clone: ${value}`); - } - result = Array.isArray(value) ? [] : Object.create(null); cloned.set(value, result); @@ -2662,11 +2777,7 @@ class LoopbackPort { continue; } - if (typeof desc.value === "function") { - if (value.hasOwnProperty?.(i)) { - throw new Error(`LoopbackPort.postMessage - cannot clone: ${value[i]}`); - } - + if (typeof desc.value === "function" && !value.hasOwnProperty?.(i)) { continue; } @@ -3011,13 +3122,21 @@ class WorkerTransport { this.fontLoader = new _font_loader.FontLoader({ docId: loadingTask.docId, onUnsupportedFeature: this._onUnsupportedFeature.bind(this), - ownerDocument: params.ownerDocument + ownerDocument: params.ownerDocument, + styleElement: params.styleElement }); this._params = params; - this.CMapReaderFactory = new params.CMapReaderFactory({ - baseUrl: params.cMapUrl, - isCompressed: params.cMapPacked - }); + + if (!params.useWorkerFetch) { + this.CMapReaderFactory = new params.CMapReaderFactory({ + baseUrl: params.cMapUrl, + isCompressed: params.cMapPacked + }); + this.StandardFontDataFactory = new params.StandardFontDataFactory({ + baseUrl: params.standardFontDataUrl + }); + } + this.destroyed = false; this.destroyCapability = null; this._passwordCapability = null; @@ -3196,6 +3315,8 @@ class WorkerTransport { pdfInfo }) => { this._numPages = pdfInfo.numPages; + this._htmlForXfa = pdfInfo.htmlForXfa; + delete pdfInfo.htmlForXfa; loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this)); }); @@ -3356,6 +3477,10 @@ class WorkerTransport { break; + case "Pattern": + pageProxy.objs.resolve(id, imageData); + break; + default: throw new Error(`Got unknown object type ${type}`); } @@ -3375,27 +3500,27 @@ class WorkerTransport { } }); messageHandler.on("UnsupportedFeature", this._onUnsupportedFeature.bind(this)); - messageHandler.on("FetchBuiltInCMap", (data, sink) => { + messageHandler.on("FetchBuiltInCMap", data => { if (this.destroyed) { - sink.error(new Error("Worker was destroyed")); - return; + return Promise.reject(new Error("Worker was destroyed.")); } - let fetched = false; + if (!this.CMapReaderFactory) { + return Promise.reject(new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter.")); + } - sink.onPull = () => { - if (fetched) { - sink.close(); - return; - } + return this.CMapReaderFactory.fetch(data); + }); + messageHandler.on("FetchStandardFontData", data => { + if (this.destroyed) { + return Promise.reject(new Error("Worker was destroyed.")); + } - fetched = true; - this.CMapReaderFactory.fetch(data).then(function (builtInCMap) { - sink.enqueue(builtInCMap, 1, [builtInCMap.cMapData.buffer]); - }).catch(function (reason) { - sink.error(reason); - }); - }; + if (!this.StandardFontDataFactory) { + return Promise.reject(new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter.")); + } + + return this.StandardFontDataFactory.fetch(data); }); } @@ -3458,6 +3583,7 @@ class WorkerTransport { saveDocument() { return this.messageHandler.sendWithPromise("SaveDocument", { + isPureXfa: !!this._htmlForXfa, numPages: this._numPages, annotationStorage: this.annotationStorage.serializable, filename: this._fullReader?.filename ?? null @@ -3530,12 +3656,6 @@ class WorkerTransport { }); } - getPageXfa(pageIndex) { - return this.messageHandler.sendWithPromise("GetPageXfa", { - pageIndex - }); - } - getStructTree(pageIndex) { return this.messageHandler.sendWithPromise("GetStructTree", { pageIndex @@ -3608,8 +3728,7 @@ class WorkerTransport { get loadingParams() { const params = this._params; return (0, _util.shadow)(this, "loadingParams", { - disableAutoFetch: params.disableAutoFetch, - disableFontFace: params.disableFontFace + disableAutoFetch: params.disableAutoFetch }); } @@ -3855,13 +3974,13 @@ const InternalRenderTask = function InternalRenderTaskClosure() { return InternalRenderTask; }(); -const version = '2.9.359'; +const version = '2.10.377'; exports.version = version; -const build = 'e667c8cbc'; +const build = '156762c48'; exports.build = build; /***/ }), -/* 6 */ +/* 7 */ /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => { @@ -3877,7 +3996,8 @@ class BaseFontLoader { constructor({ docId, onUnsupportedFeature, - ownerDocument = globalThis.document + ownerDocument = globalThis.document, + styleElement = null }) { if (this.constructor === BaseFontLoader) { (0, _util.unreachable)("Cannot initialize BaseFontLoader."); @@ -3974,7 +4094,8 @@ class BaseFontLoader { } get isFontLoadingAPISupported() { - return (0, _util.shadow)(this, "isFontLoadingAPISupported", !!this._document?.fonts); + const hasFonts = !!this._document?.fonts; + return (0, _util.shadow)(this, "isFontLoadingAPISupported", hasFonts); } get isSyncFontLoadingSupported() { @@ -4272,7 +4393,7 @@ class FontFaceObject { exports.FontFaceObject = FontFaceObject; /***/ }), -/* 7 */ +/* 8 */ /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => { @@ -4280,9 +4401,9 @@ exports.FontFaceObject = FontFaceObject; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.NodeCMapReaderFactory = exports.NodeCanvasFactory = void 0; +exports.NodeStandardFontDataFactory = exports.NodeCMapReaderFactory = exports.NodeCanvasFactory = void 0; -var _display_utils = __w_pdfjs_require__(1); +var _base_factory = __w_pdfjs_require__(5); var _is_node = __w_pdfjs_require__(4); @@ -4302,48 +4423,59 @@ let NodeCMapReaderFactory = class { }; exports.NodeCMapReaderFactory = NodeCMapReaderFactory; +let NodeStandardFontDataFactory = class { + constructor() { + (0, _util.unreachable)("Not implemented: NodeStandardFontDataFactory"); + } + +}; +exports.NodeStandardFontDataFactory = NodeStandardFontDataFactory; if (_is_node.isNodeJS) { - exports.NodeCanvasFactory = NodeCanvasFactory = class extends _display_utils.BaseCanvasFactory { - create(width, height) { - if (width <= 0 || height <= 0) { - throw new Error("Invalid canvas size"); - } + const fetchData = function (url) { + return new Promise((resolve, reject) => { + const fs = require("fs"); + + fs.readFile(url, (error, data) => { + if (error || !data) { + reject(new Error(error)); + return; + } + resolve(new Uint8Array(data)); + }); + }); + }; + + exports.NodeCanvasFactory = NodeCanvasFactory = class extends _base_factory.BaseCanvasFactory { + _createCanvas(width, height) { const Canvas = require("canvas"); - const canvas = Canvas.createCanvas(width, height); - return { - canvas, - context: canvas.getContext("2d") - }; + return Canvas.createCanvas(width, height); } }; - exports.NodeCMapReaderFactory = NodeCMapReaderFactory = class extends _display_utils.BaseCMapReaderFactory { + exports.NodeCMapReaderFactory = NodeCMapReaderFactory = class extends _base_factory.BaseCMapReaderFactory { _fetchData(url, compressionType) { - return new Promise((resolve, reject) => { - const fs = require("fs"); - - fs.readFile(url, (error, data) => { - if (error || !data) { - reject(new Error(error)); - return; - } - - resolve({ - cMapData: new Uint8Array(data), - compressionType - }); - }); + return fetchData(url).then(data => { + return { + cMapData: data, + compressionType + }; }); } }; + exports.NodeStandardFontDataFactory = NodeStandardFontDataFactory = class extends _base_factory.BaseStandardFontDataFactory { + _fetchData(url) { + return fetchData(url); + } + + }; } /***/ }), -/* 8 */ +/* 9 */ /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => { @@ -4429,30 +4561,6 @@ class AnnotationStorage { exports.AnnotationStorage = AnnotationStorage; /***/ }), -/* 9 */ -/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => { - - - -Object.defineProperty(exports, "__esModule", ({ - value: true -})); -exports.apiCompatibilityParams = void 0; - -var _is_node = __w_pdfjs_require__(4); - -const compatibilityParams = Object.create(null); -{ - (function checkFontFace() { - if (_is_node.isNodeJS) { - compatibilityParams.disableFontFace = true; - } - })(); -} -const apiCompatibilityParams = Object.freeze(compatibilityParams); -exports.apiCompatibilityParams = apiCompatibilityParams; - -/***/ }), /* 10 */ /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => { @@ -4549,10 +4657,10 @@ function addContextCurrentTransform(ctx) { ctx.scale = function ctxScale(x, y) { const m = this._transformMatrix; - m[0] = m[0] * x; - m[1] = m[1] * x; - m[2] = m[2] * y; - m[3] = m[3] * y; + m[0] *= x; + m[1] *= x; + m[2] *= y; + m[3] *= y; this._originalScale(x, y); }; @@ -5200,6 +5308,7 @@ const CanvasGraphics = function CanvasGraphicsClosure() { this.markedContentStack = []; this.optionalContentConfig = optionalContentConfig; this.cachedCanvases = new CachedCanvases(this.canvasFactory); + this.cachedPatterns = new Map(); if (canvasCtx) { addContextCurrentTransform(canvasCtx); @@ -5318,12 +5427,100 @@ const CanvasGraphics = function CanvasGraphicsClosure() { } this.cachedCanvases.clear(); + this.cachedPatterns.clear(); if (this.imageLayer) { this.imageLayer.endLayout(); } } + _scaleImage(img, inverseTransform) { + const width = img.width; + const height = img.height; + let widthScale = Math.max(Math.hypot(inverseTransform[0], inverseTransform[1]), 1); + let heightScale = Math.max(Math.hypot(inverseTransform[2], inverseTransform[3]), 1); + let paintWidth = width, + paintHeight = height; + let tmpCanvasId = "prescale1"; + let tmpCanvas, tmpCtx; + + while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) { + let newWidth = paintWidth, + newHeight = paintHeight; + + if (widthScale > 2 && paintWidth > 1) { + newWidth = Math.ceil(paintWidth / 2); + widthScale /= paintWidth / newWidth; + } + + if (heightScale > 2 && paintHeight > 1) { + newHeight = Math.ceil(paintHeight / 2); + heightScale /= paintHeight / newHeight; + } + + tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight); + tmpCtx = tmpCanvas.context; + tmpCtx.clearRect(0, 0, newWidth, newHeight); + tmpCtx.drawImage(img, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight); + img = tmpCanvas.canvas; + paintWidth = newWidth; + paintHeight = newHeight; + tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1"; + } + + return { + img, + paintWidth, + paintHeight + }; + } + + _createMaskCanvas(img) { + const ctx = this.ctx; + const width = img.width, + height = img.height; + const fillColor = this.current.fillColor; + const isPatternFill = this.current.patternFill; + const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height); + const maskCtx = maskCanvas.context; + putBinaryImageMask(maskCtx, img); + const objToCanvas = ctx.mozCurrentTransform; + + let maskToCanvas = _util.Util.transform(objToCanvas, [1 / width, 0, 0, -1 / height, 0, 0]); + + maskToCanvas = _util.Util.transform(maskToCanvas, [1, 0, 0, 1, 0, -height]); + + const cord1 = _util.Util.applyTransform([0, 0], maskToCanvas); + + const cord2 = _util.Util.applyTransform([width, height], maskToCanvas); + + const rect = _util.Util.normalizeRect([cord1[0], cord1[1], cord2[0], cord2[1]]); + + const drawnWidth = Math.ceil(rect[2] - rect[0]); + const drawnHeight = Math.ceil(rect[3] - rect[1]); + const fillCanvas = this.cachedCanvases.getCanvas("fillCanvas", drawnWidth, drawnHeight, true); + const fillCtx = fillCanvas.context; + const offsetX = Math.min(cord1[0], cord2[0]); + const offsetY = Math.min(cord1[1], cord2[1]); + fillCtx.translate(-offsetX, -offsetY); + fillCtx.transform.apply(fillCtx, maskToCanvas); + + const scaled = this._scaleImage(maskCanvas.canvas, fillCtx.mozCurrentTransformInverse); + + fillCtx.drawImage(scaled.img, 0, 0, scaled.img.width, scaled.img.height, 0, 0, width, height); + fillCtx.globalCompositeOperation = "source-in"; + + const inverse = _util.Util.transform(fillCtx.mozCurrentTransformInverse, [1, 0, 0, 1, -offsetX, -offsetY]); + + fillCtx.fillStyle = isPatternFill ? fillColor.getPattern(ctx, this, inverse, false) : fillColor; + fillCtx.fillRect(0, 0, width, height); + return { + canvas: fillCanvas.canvas, + offsetX: Math.round(offsetX), + offsetY: Math.round(offsetY) + }; + } + setLineWidth(width) { this.current.lineWidth = width; this.ctx.lineWidth = width; @@ -5607,7 +5804,7 @@ const CanvasGraphics = function CanvasGraphicsClosure() { if (typeof strokeColor === "object" && strokeColor?.getPattern) { const lineWidth = this.getSinglePixelWidth(); ctx.save(); - ctx.strokeStyle = strokeColor.getPattern(ctx, this); + ctx.strokeStyle = strokeColor.getPattern(ctx, this, ctx.mozCurrentTransformInverse); ctx.lineWidth = Math.max(lineWidth, this.current.lineWidth); ctx.stroke(); ctx.restore(); @@ -5648,7 +5845,7 @@ const CanvasGraphics = function CanvasGraphicsClosure() { if (isPatternFill) { ctx.save(); - ctx.fillStyle = fillColor.getPattern(ctx, this); + ctx.fillStyle = fillColor.getPattern(ctx, this, ctx.mozCurrentTransformInverse); needRestore = true; } @@ -5957,7 +6154,7 @@ const CanvasGraphics = function CanvasGraphicsClosure() { if (current.patternFill) { ctx.save(); - const pattern = current.fillColor.getPattern(ctx, this); + const pattern = current.fillColor.getPattern(ctx, this, ctx.mozCurrentTransformInverse); patternTransform = ctx.mozCurrentTransform; ctx.restore(); ctx.fillStyle = pattern; @@ -6161,7 +6358,7 @@ const CanvasGraphics = function CanvasGraphicsClosure() { }; pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform); } else { - pattern = (0, _pattern_helper.getShadingPattern)(IR); + pattern = this._getPattern(IR[1]); } return pattern; @@ -6191,15 +6388,27 @@ const CanvasGraphics = function CanvasGraphicsClosure() { this.current.patternFill = false; } - shadingFill(patternIR) { + _getPattern(objId) { + if (this.cachedPatterns.has(objId)) { + return this.cachedPatterns.get(objId); + } + + const pattern = (0, _pattern_helper.getShadingPattern)(this.objs.get(objId)); + this.cachedPatterns.set(objId, pattern); + return pattern; + } + + shadingFill(objId) { if (!this.contentVisible) { return; } const ctx = this.ctx; this.save(); - const pattern = (0, _pattern_helper.getShadingPattern)(patternIR); - ctx.fillStyle = pattern.getPattern(ctx, this, true); + + const pattern = this._getPattern(objId); + + ctx.fillStyle = pattern.getPattern(ctx, this, ctx.mozCurrentTransformInverse, true); const inv = ctx.mozCurrentTransformInverse; if (inv) { @@ -6389,7 +6598,7 @@ const CanvasGraphics = function CanvasGraphicsClosure() { this.restore(); } - beginAnnotation(rect, transform, matrix) { + beginAnnotation(id, rect, transform, matrix) { this.save(); resetCtxToDefault(this.ctx); this.current = new CanvasExtraState(); @@ -6418,8 +6627,6 @@ const CanvasGraphics = function CanvasGraphicsClosure() { const ctx = this.ctx; const width = img.width, height = img.height; - const fillColor = this.current.fillColor; - const isPatternFill = this.current.patternFill; const glyph = this.processingType3; if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) { @@ -6439,15 +6646,13 @@ const CanvasGraphics = function CanvasGraphicsClosure() { return; } - const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height); - const maskCtx = maskCanvas.context; - maskCtx.save(); - putBinaryImageMask(maskCtx, img); - maskCtx.globalCompositeOperation = "source-in"; - maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor; - maskCtx.fillRect(0, 0, width, height); - maskCtx.restore(); - this.paintInlineImageXObject(maskCanvas.canvas); + const mask = this._createMaskCanvas(img); + + const maskCanvas = mask.canvas; + ctx.save(); + ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.drawImage(maskCanvas, mask.offsetX, mask.offsetY); + ctx.restore(); } paintImageMaskXObjectRepeat(imgData, scaleX, skewX = 0, skewY = 0, scaleY, positions) { @@ -6455,27 +6660,24 @@ const CanvasGraphics = function CanvasGraphicsClosure() { return; } - const width = imgData.width; - const height = imgData.height; - const fillColor = this.current.fillColor; - const isPatternFill = this.current.patternFill; - const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height); - const maskCtx = maskCanvas.context; - maskCtx.save(); - putBinaryImageMask(maskCtx, imgData); - maskCtx.globalCompositeOperation = "source-in"; - maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor; - maskCtx.fillRect(0, 0, width, height); - maskCtx.restore(); const ctx = this.ctx; + ctx.save(); + const currentTransform = ctx.mozCurrentTransform; + ctx.transform(scaleX, skewX, skewY, scaleY, 0, 0); + + const mask = this._createMaskCanvas(imgData); + + ctx.setTransform(1, 0, 0, 1, 0, 0); for (let i = 0, ii = positions.length; i < ii; i += 2) { - ctx.save(); - ctx.transform(scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]); - ctx.scale(1, -1); - ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1); - ctx.restore(); + const trans = _util.Util.transform(currentTransform, [scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]]); + + const [x, y] = _util.Util.applyTransform([0, 0], trans); + + ctx.drawImage(mask.canvas, x, y); } + + ctx.restore(); } paintImageMaskXObjectGroup(images) { @@ -6496,7 +6698,7 @@ const CanvasGraphics = function CanvasGraphicsClosure() { maskCtx.save(); putBinaryImageMask(maskCtx, image); maskCtx.globalCompositeOperation = "source-in"; - maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor; + maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this, ctx.mozCurrentTransformInverse, false) : fillColor; maskCtx.fillRect(0, 0, width, height); maskCtx.restore(); ctx.save(); @@ -6561,49 +6763,20 @@ const CanvasGraphics = function CanvasGraphicsClosure() { const ctx = this.ctx; this.save(); ctx.scale(1 / width, -1 / height); - const currentTransform = ctx.mozCurrentTransformInverse; - let widthScale = Math.max(Math.hypot(currentTransform[0], currentTransform[1]), 1); - let heightScale = Math.max(Math.hypot(currentTransform[2], currentTransform[3]), 1); - let imgToPaint, tmpCanvas, tmpCtx; + let imgToPaint; if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) { imgToPaint = imgData; } else { - tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height); - tmpCtx = tmpCanvas.context; + const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height); + const tmpCtx = tmpCanvas.context; putBinaryImageData(tmpCtx, imgData, this.current.transferMaps); imgToPaint = tmpCanvas.canvas; } - let paintWidth = width, - paintHeight = height; - let tmpCanvasId = "prescale1"; - - while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) { - let newWidth = paintWidth, - newHeight = paintHeight; - - if (widthScale > 2 && paintWidth > 1) { - newWidth = Math.ceil(paintWidth / 2); - widthScale /= paintWidth / newWidth; - } - - if (heightScale > 2 && paintHeight > 1) { - newHeight = Math.ceil(paintHeight / 2); - heightScale /= paintHeight / newHeight; - } - - tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight); - tmpCtx = tmpCanvas.context; - tmpCtx.clearRect(0, 0, newWidth, newHeight); - tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight); - imgToPaint = tmpCanvas.canvas; - paintWidth = newWidth; - paintHeight = newHeight; - tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1"; - } + const scaled = this._scaleImage(imgToPaint, ctx.mozCurrentTransformInverse); - ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height); + ctx.drawImage(scaled.img, 0, 0, scaled.paintWidth, scaled.paintHeight, 0, -height, width, height); if (this.imageLayer) { const position = this.getCanvasPosition(0, -height); @@ -6611,8 +6784,8 @@ const CanvasGraphics = function CanvasGraphicsClosure() { imgData, left: position[0], top: position[1], - width: width / currentTransform[0], - height: height / currentTransform[3] + width: width / ctx.mozCurrentTransformInverse[0], + height: height / ctx.mozCurrentTransformInverse[3] }); } @@ -6770,20 +6943,6 @@ exports.TilingPattern = void 0; var _util = __w_pdfjs_require__(2); -let svgElement; - -function createMatrix(matrix) { - if (typeof DOMMatrix !== "undefined") { - return new DOMMatrix(matrix); - } - - if (!svgElement) { - svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg"); - } - - return svgElement.createSVGMatrix(matrix); -} - function applyBoundingBox(ctx, bbox) { if (!bbox || typeof Path2D === "undefined") { return; @@ -6820,42 +6979,65 @@ class RadialAxialShadingPattern extends BaseShadingPattern { this._r0 = IR[6]; this._r1 = IR[7]; this._matrix = IR[8]; + this._patternCache = null; } - getPattern(ctx, owner, shadingFill) { - const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", ctx.canvas.width, ctx.canvas.height, true); - const tmpCtx = tmpCanvas.context; - tmpCtx.clearRect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height); - tmpCtx.beginPath(); - tmpCtx.rect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height); - - if (!shadingFill) { - tmpCtx.setTransform.apply(tmpCtx, owner.baseTransform); - - if (this._matrix) { - tmpCtx.transform.apply(tmpCtx, this._matrix); - } - } else { - tmpCtx.setTransform.apply(tmpCtx, ctx.mozCurrentTransform); - } - - applyBoundingBox(tmpCtx, this._bbox); + _createGradient(ctx) { let grad; if (this._type === "axial") { - grad = tmpCtx.createLinearGradient(this._p0[0], this._p0[1], this._p1[0], this._p1[1]); + grad = ctx.createLinearGradient(this._p0[0], this._p0[1], this._p1[0], this._p1[1]); } else if (this._type === "radial") { - grad = tmpCtx.createRadialGradient(this._p0[0], this._p0[1], this._r0, this._p1[0], this._p1[1], this._r1); + grad = ctx.createRadialGradient(this._p0[0], this._p0[1], this._r0, this._p1[0], this._p1[1], this._r1); } for (const colorStop of this._colorStops) { grad.addColorStop(colorStop[0], colorStop[1]); } - tmpCtx.fillStyle = grad; - tmpCtx.fill(); - const pattern = ctx.createPattern(tmpCanvas.canvas, "repeat"); - pattern.setTransform(createMatrix(ctx.mozCurrentTransformInverse)); + return grad; + } + + getPattern(ctx, owner, inverse, shadingFill = false) { + let pattern; + + if (this._patternCache) { + pattern = this._patternCache; + } else { + if (!shadingFill) { + const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", owner.ctx.canvas.width, owner.ctx.canvas.height, true); + const tmpCtx = tmpCanvas.context; + tmpCtx.clearRect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height); + tmpCtx.beginPath(); + tmpCtx.rect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height); + tmpCtx.setTransform.apply(tmpCtx, owner.baseTransform); + + if (this._matrix) { + tmpCtx.transform.apply(tmpCtx, this._matrix); + } + + applyBoundingBox(tmpCtx, this._bbox); + tmpCtx.fillStyle = this._createGradient(tmpCtx); + tmpCtx.fill(); + pattern = ctx.createPattern(tmpCanvas.canvas, "repeat"); + } else { + applyBoundingBox(ctx, this._bbox); + pattern = this._createGradient(ctx); + } + + this._patternCache = pattern; + } + + if (!shadingFill) { + const domMatrix = new DOMMatrix(inverse); + + try { + pattern.setTransform(domMatrix); + } catch (ex) { + (0, _util.warn)(`RadialAxialShadingPattern.getPattern: "${ex?.message}".`); + } + } + return pattern; } @@ -6926,8 +7108,6 @@ function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) { if (y < y1) { k = 0; - } else if (y1 === y2) { - k = 1; } else { k = (y1 - y) / (y1 - y2); } @@ -7086,7 +7266,7 @@ class MeshShadingPattern extends BaseShadingPattern { }; } - getPattern(ctx, owner, shadingFill) { + getPattern(ctx, owner, inverse, shadingFill = false) { applyBoundingBox(ctx, this._bbox); let scale; @@ -7192,15 +7372,33 @@ class TilingPattern { const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx); graphics.groupLevel = owner.groupLevel; this.setFillAndStrokeStyleToContext(graphics, paintType, color); + let adjustedX0 = x0; + let adjustedY0 = y0; + let adjustedX1 = x1; + let adjustedY1 = y1; + + if (x0 < 0) { + adjustedX0 = 0; + adjustedX1 += Math.abs(x0); + } + + if (y0 < 0) { + adjustedY0 = 0; + adjustedY1 += Math.abs(y0); + } + + tmpCtx.translate(-(dimx.scale * adjustedX0), -(dimy.scale * adjustedY0)); graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0); - this.clipBbox(graphics, bbox, x0, y0, x1, y1); + this.clipBbox(graphics, adjustedX0, adjustedY0, adjustedX1, adjustedY1); graphics.baseTransform = graphics.ctx.mozCurrentTransform.slice(); graphics.executeOperatorList(operatorList); graphics.endDrawing(); return { canvas: tmpCanvas.canvas, scaleX: dimx.scale, - scaleY: dimy.scale + scaleY: dimy.scale, + offsetX: adjustedX0, + offsetY: adjustedY0 }; } @@ -7221,14 +7419,12 @@ class TilingPattern { }; } - clipBbox(graphics, bbox, x0, y0, x1, y1) { - if (Array.isArray(bbox) && bbox.length === 4) { - const bboxWidth = x1 - x0; - const bboxHeight = y1 - y0; - graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight); - graphics.clip(); - graphics.endPath(); - } + clipBbox(graphics, x0, y0, x1, y1) { + const bboxWidth = x1 - x0; + const bboxHeight = y1 - y0; + graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight); + graphics.clip(); + graphics.endPath(); } setFillAndStrokeStyleToContext(graphics, paintType, color) { @@ -7258,9 +7454,8 @@ class TilingPattern { } } - getPattern(ctx, owner, shadingFill) { - ctx = this.ctx; - let matrix = ctx.mozCurrentTransformInverse; + getPattern(ctx, owner, inverse, shadingFill = false) { + let matrix = inverse; if (!shadingFill) { matrix = _util.Util.transform(matrix, owner.baseTransform); @@ -7271,10 +7466,17 @@ class TilingPattern { } const temporaryPatternCanvas = this.createPatternCanvas(owner); - let domMatrix = createMatrix(matrix); + let domMatrix = new DOMMatrix(matrix); + domMatrix = domMatrix.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY); domMatrix = domMatrix.scale(1 / temporaryPatternCanvas.scaleX, 1 / temporaryPatternCanvas.scaleY); const pattern = ctx.createPattern(temporaryPatternCanvas.canvas, "repeat"); - pattern.setTransform(domMatrix); + + try { + pattern.setTransform(domMatrix); + } catch (ex) { + (0, _util.warn)(`TilingPattern.getPattern: "${ex?.message}".`); + } + return pattern; } @@ -8421,7 +8623,7 @@ var _display_utils = __w_pdfjs_require__(1); var _util = __w_pdfjs_require__(2); -var _annotation_storage = __w_pdfjs_require__(8); +var _annotation_storage = __w_pdfjs_require__(9); var _scripting_utils = __w_pdfjs_require__(18); @@ -8558,8 +8760,8 @@ class AnnotationElement { container.style.borderWidth = `${data.borderStyle.width}px`; if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) { - width = width - 2 * data.borderStyle.width; - height = height - 2 * data.borderStyle.width; + width -= 2 * data.borderStyle.width; + height -= 2 * data.borderStyle.width; } const horizontalRadius = data.borderStyle.horizontalCornerRadius; @@ -12048,9 +12250,7 @@ exports.SVGGraphics = SVGGraphics; const paintType = args[7]; const tilingId = `shading${shadingCount++}`; - const [tx0, ty0] = _util.Util.applyTransform([x0, y0], matrix); - - const [tx1, ty1] = _util.Util.applyTransform([x1, y1], matrix); + const [tx0, ty0, tx1, ty1] = _util.Util.normalizeRect([..._util.Util.applyTransform([x0, y0], matrix), ..._util.Util.applyTransform([x1, y1], matrix)]); const [xscale, yscale] = _util.Util.singularValueDecompose2dScale(matrix); @@ -12576,48 +12776,54 @@ Object.defineProperty(exports, "__esModule", ({ exports.XfaLayer = void 0; class XfaLayer { - static setupStorage(html, fieldId, element, storage) { - const storedData = storage.getValue(fieldId, { + static setupStorage(html, id, element, storage, intent) { + const storedData = storage.getValue(id, { value: null }); switch (element.name) { case "textarea": - html.textContent = storedData.value !== null ? storedData.value : ""; + if (storedData.value !== null) { + html.textContent = storedData.value; + } + + if (intent === "print") { + break; + } + html.addEventListener("input", event => { - storage.setValue(fieldId, { + storage.setValue(id, { value: event.target.value }); }); break; case "input": - if (storedData.value !== null) { - html.setAttribute("value", storedData.value); - } + if (element.attributes.type === "radio" || element.attributes.type === "checkbox") { + if (storedData.value === element.attributes.xfaOn) { + html.setAttribute("checked", true); + } - if (element.attributes.type === "radio") { - html.addEventListener("change", event => { - const { - target - } = event; - - for (const radio of document.getElementsByName(target.name)) { - if (radio !== target) { - const id = radio.id; - storage.setValue(id.split("-")[0], { - value: false - }); - } - } + if (intent === "print") { + break; + } - storage.setValue(fieldId, { - value: target.checked + html.addEventListener("change", event => { + storage.setValue(id, { + value: event.target.getAttribute("xfaOn") }); }); } else { + if (storedData.value !== null) { + html.setAttribute("value", storedData.value); + } + + if (intent === "print") { + break; + } + html.addEventListener("input", event => { - storage.setValue(fieldId, { + storage.setValue(id, { value: event.target.value }); }); @@ -12636,8 +12842,8 @@ class XfaLayer { html.addEventListener("input", event => { const options = event.target.options; - const value = options.selectedIndex === -1 ? null : options[options.selectedIndex].value; - storage.setValue(fieldId, { + const value = options.selectedIndex === -1 ? "" : options[options.selectedIndex].value; + storage.setValue(id, { value }); }); @@ -12645,19 +12851,25 @@ class XfaLayer { } } - static setAttributes(html, element, storage) { + static setAttributes(html, element, storage, intent) { const { attributes } = element; + if (attributes.type === "radio") { + attributes.name = `${attributes.name}-${intent}`; + } + for (const [key, value] of Object.entries(attributes)) { - if (value === null || value === undefined || key === "fieldId") { + if (value === null || value === undefined || key === "dataId") { continue; } if (key !== "style") { if (key === "textContent") { html.textContent = value; + } else if (key === "class") { + html.setAttribute(key, value.join(" ")); } else { html.setAttribute(key, value); } @@ -12666,14 +12878,15 @@ class XfaLayer { } } - if (storage && attributes.fieldId !== undefined) { - this.setupStorage(html, attributes.fieldId, element, storage); + if (storage && attributes.dataId) { + this.setupStorage(html, attributes.dataId, element, storage); } } static render(parameters) { const storage = parameters.annotationStorage; const root = parameters.xfa; + const intent = parameters.intent || "display"; const rootHtml = document.createElement(root.name); if (root.attributes) { @@ -12683,8 +12896,8 @@ class XfaLayer { const stack = [[root, -1, rootHtml]]; const rootDiv = parameters.div; rootDiv.appendChild(rootHtml); - const coeffs = parameters.viewport.transform.join(","); - rootDiv.style.transform = `matrix(${coeffs})`; + const transform = `matrix(${parameters.viewport.transform.join(",")})`; + rootDiv.style.transform = transform; rootDiv.setAttribute("class", "xfaLayer xfaFont"); while (stack.length > 0) { @@ -12710,11 +12923,18 @@ class XfaLayer { continue; } - const childHtml = document.createElement(name); + let childHtml; + + if (child?.attributes?.xmlns) { + childHtml = document.createElementNS(child.attributes.xmlns, name); + } else { + childHtml = document.createElement(name); + } + html.appendChild(childHtml); if (child.attributes) { - this.setAttributes(childHtml, child, storage); + this.setAttributes(childHtml, child, storage, intent); } if (child.children && child.children.length > 0) { @@ -12723,6 +12943,10 @@ class XfaLayer { childHtml.appendChild(document.createTextNode(child.value)); } } + + for (const el of rootDiv.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea")) { + el.setAttribute("readOnly", true); + } } static update(parameters) { @@ -14367,6 +14591,12 @@ Object.defineProperty(exports, "getPdfFilenameFromUrl", ({ return _display_utils.getPdfFilenameFromUrl; } })); +Object.defineProperty(exports, "getXfaPageViewport", ({ + enumerable: true, + get: function () { + return _display_utils.getXfaPageViewport; + } +})); Object.defineProperty(exports, "isPdfFile", ({ enumerable: true, get: function () { @@ -14529,12 +14759,6 @@ Object.defineProperty(exports, "AnnotationLayer", ({ return _annotation_layer.AnnotationLayer; } })); -Object.defineProperty(exports, "apiCompatibilityParams", ({ - enumerable: true, - get: function () { - return _api_compatibility.apiCompatibilityParams; - } -})); Object.defineProperty(exports, "GlobalWorkerOptions", ({ enumerable: true, get: function () { @@ -14562,46 +14786,44 @@ Object.defineProperty(exports, "XfaLayer", ({ var _display_utils = __w_pdfjs_require__(1); -var _api = __w_pdfjs_require__(5); +var _api = __w_pdfjs_require__(6); var _util = __w_pdfjs_require__(2); var _annotation_layer = __w_pdfjs_require__(17); -var _api_compatibility = __w_pdfjs_require__(9); - var _worker_options = __w_pdfjs_require__(12); +var _is_node = __w_pdfjs_require__(4); + var _text_layer = __w_pdfjs_require__(19); var _svg = __w_pdfjs_require__(20); var _xfa_layer = __w_pdfjs_require__(21); -const pdfjsVersion = '2.9.359'; -const pdfjsBuild = 'e667c8cbc'; +const pdfjsVersion = '2.10.377'; +const pdfjsBuild = '156762c48'; { - const { - isNodeJS - } = __w_pdfjs_require__(4); - - if (isNodeJS) { - const PDFNodeStream = __w_pdfjs_require__(22).PDFNodeStream; + if (_is_node.isNodeJS) { + const { + PDFNodeStream + } = __w_pdfjs_require__(22); (0, _api.setPDFNetworkStreamFactory)(params => { return new PDFNodeStream(params); }); } else { - const PDFNetworkStream = __w_pdfjs_require__(25).PDFNetworkStream; - - let PDFFetchStream; + const { + PDFNetworkStream + } = __w_pdfjs_require__(25); - if ((0, _display_utils.isFetchSupported)()) { - PDFFetchStream = __w_pdfjs_require__(26).PDFFetchStream; - } + const { + PDFFetchStream + } = __w_pdfjs_require__(26); (0, _api.setPDFNetworkStreamFactory)(params => { - if (PDFFetchStream && (0, _display_utils.isValidFetchUrl)(params.url)) { + if ((0, _display_utils.isValidFetchUrl)(params.url)) { return new PDFFetchStream(params); } |