Inline the default Factory-definitions in getDocument
- Most of the these are only used in the `src/display/api.js` file, and this leads to slightly shorter code. - A number of unit-tests need a `BaseCanvasFactory`-instance, however that one is available through the `PDFDocumentProxy`-instance nowadays. - For other unit-tests the remaining necessary default Factory-definitions can be moved into the `test/unit/test_utils.js` file.
This commit is contained in:
parent
6d12d2924f
commit
db43f158dc
@ -74,27 +74,6 @@ const DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
|
|||||||
const RENDERING_CANCELLED_TIMEOUT = 100; // ms
|
const RENDERING_CANCELLED_TIMEOUT = 100; // ms
|
||||||
const DELAYED_CLEANUP_TIMEOUT = 5000; // ms
|
const DELAYED_CLEANUP_TIMEOUT = 5000; // ms
|
||||||
|
|
||||||
const DefaultCanvasFactory =
|
|
||||||
typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
|
||||||
? NodeCanvasFactory
|
|
||||||
: DOMCanvasFactory;
|
|
||||||
const DefaultCMapReaderFactory =
|
|
||||||
typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
|
||||||
? NodeCMapReaderFactory
|
|
||||||
: DOMCMapReaderFactory;
|
|
||||||
const DefaultFilterFactory =
|
|
||||||
typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
|
||||||
? NodeFilterFactory
|
|
||||||
: DOMFilterFactory;
|
|
||||||
const DefaultStandardFontDataFactory =
|
|
||||||
typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
|
||||||
? NodeStandardFontDataFactory
|
|
||||||
: DOMStandardFontDataFactory;
|
|
||||||
const DefaultWasmFactory =
|
|
||||||
typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
|
||||||
? NodeWasmFactory
|
|
||||||
: DOMWasmFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef { Int8Array | Uint8Array | Uint8ClampedArray |
|
* @typedef { Int8Array | Uint8Array | Uint8ClampedArray |
|
||||||
* Int16Array | Uint16Array |
|
* Int16Array | Uint16Array |
|
||||||
@ -283,15 +262,26 @@ function getDocument(src = {}) {
|
|||||||
: null;
|
: null;
|
||||||
const cMapUrl = typeof src.cMapUrl === "string" ? src.cMapUrl : null;
|
const cMapUrl = typeof src.cMapUrl === "string" ? src.cMapUrl : null;
|
||||||
const cMapPacked = src.cMapPacked !== false;
|
const cMapPacked = src.cMapPacked !== false;
|
||||||
const CMapReaderFactory = src.CMapReaderFactory || DefaultCMapReaderFactory;
|
const CMapReaderFactory =
|
||||||
|
src.CMapReaderFactory ||
|
||||||
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
||||||
|
? NodeCMapReaderFactory
|
||||||
|
: DOMCMapReaderFactory);
|
||||||
const standardFontDataUrl =
|
const standardFontDataUrl =
|
||||||
typeof src.standardFontDataUrl === "string"
|
typeof src.standardFontDataUrl === "string"
|
||||||
? src.standardFontDataUrl
|
? src.standardFontDataUrl
|
||||||
: null;
|
: null;
|
||||||
const StandardFontDataFactory =
|
const StandardFontDataFactory =
|
||||||
src.StandardFontDataFactory || DefaultStandardFontDataFactory;
|
src.StandardFontDataFactory ||
|
||||||
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
||||||
|
? NodeStandardFontDataFactory
|
||||||
|
: DOMStandardFontDataFactory);
|
||||||
const wasmUrl = typeof src.wasmUrl === "string" ? src.wasmUrl : null;
|
const wasmUrl = typeof src.wasmUrl === "string" ? src.wasmUrl : null;
|
||||||
const WasmFactory = src.WasmFactory || DefaultWasmFactory;
|
const WasmFactory =
|
||||||
|
src.WasmFactory ||
|
||||||
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
||||||
|
? NodeWasmFactory
|
||||||
|
: DOMWasmFactory);
|
||||||
const ignoreErrors = src.stopAtErrors !== true;
|
const ignoreErrors = src.stopAtErrors !== true;
|
||||||
const maxImageSize =
|
const maxImageSize =
|
||||||
Number.isInteger(src.maxImageSize) && src.maxImageSize > -1
|
Number.isInteger(src.maxImageSize) && src.maxImageSize > -1
|
||||||
@ -324,8 +314,16 @@ function getDocument(src = {}) {
|
|||||||
const disableStream = src.disableStream === true;
|
const disableStream = src.disableStream === true;
|
||||||
const disableAutoFetch = src.disableAutoFetch === true;
|
const disableAutoFetch = src.disableAutoFetch === true;
|
||||||
const pdfBug = src.pdfBug === true;
|
const pdfBug = src.pdfBug === true;
|
||||||
const CanvasFactory = src.CanvasFactory || DefaultCanvasFactory;
|
const CanvasFactory =
|
||||||
const FilterFactory = src.FilterFactory || DefaultFilterFactory;
|
src.CanvasFactory ||
|
||||||
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
||||||
|
? NodeCanvasFactory
|
||||||
|
: DOMCanvasFactory);
|
||||||
|
const FilterFactory =
|
||||||
|
src.FilterFactory ||
|
||||||
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
||||||
|
? NodeFilterFactory
|
||||||
|
: DOMFilterFactory);
|
||||||
const enableHWA = src.enableHWA === true;
|
const enableHWA = src.enableHWA === true;
|
||||||
|
|
||||||
// Parameters whose default values depend on other parameters.
|
// Parameters whose default values depend on other parameters.
|
||||||
@ -3534,11 +3532,6 @@ const build =
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
build,
|
build,
|
||||||
DefaultCanvasFactory,
|
|
||||||
DefaultCMapReaderFactory,
|
|
||||||
DefaultFilterFactory,
|
|
||||||
DefaultStandardFontDataFactory,
|
|
||||||
DefaultWasmFactory,
|
|
||||||
getDocument,
|
getDocument,
|
||||||
LoopbackPort,
|
LoopbackPort,
|
||||||
PDFDataRangeTransport,
|
PDFDataRangeTransport,
|
||||||
|
|||||||
@ -34,13 +34,11 @@ import {
|
|||||||
import {
|
import {
|
||||||
CMAP_URL,
|
CMAP_URL,
|
||||||
createIdFactory,
|
createIdFactory,
|
||||||
|
DefaultCMapReaderFactory,
|
||||||
|
DefaultStandardFontDataFactory,
|
||||||
STANDARD_FONT_DATA_URL,
|
STANDARD_FONT_DATA_URL,
|
||||||
XRefMock,
|
XRefMock,
|
||||||
} from "./test_utils.js";
|
} from "./test_utils.js";
|
||||||
import {
|
|
||||||
DefaultCMapReaderFactory,
|
|
||||||
DefaultStandardFontDataFactory,
|
|
||||||
} from "../../src/display/api.js";
|
|
||||||
import { Dict, Name, Ref, RefSetCache } from "../../src/core/primitives.js";
|
import { Dict, Name, Ref, RefSetCache } from "../../src/core/primitives.js";
|
||||||
import { Lexer, Parser } from "../../src/core/parser.js";
|
import { Lexer, Parser } from "../../src/core/parser.js";
|
||||||
import { FlateStream } from "../../src/core/flate_stream.js";
|
import { FlateStream } from "../../src/core/flate_stream.js";
|
||||||
|
|||||||
@ -37,7 +37,12 @@ import {
|
|||||||
TestPdfsServer,
|
TestPdfsServer,
|
||||||
} from "./test_utils.js";
|
} from "./test_utils.js";
|
||||||
import {
|
import {
|
||||||
DefaultCanvasFactory,
|
fetchData as fetchDataDOM,
|
||||||
|
PageViewport,
|
||||||
|
RenderingCancelledException,
|
||||||
|
StatTimer,
|
||||||
|
} from "../../src/display/display_utils.js";
|
||||||
|
import {
|
||||||
getDocument,
|
getDocument,
|
||||||
PDFDataRangeTransport,
|
PDFDataRangeTransport,
|
||||||
PDFDocumentLoadingTask,
|
PDFDocumentLoadingTask,
|
||||||
@ -46,12 +51,6 @@ import {
|
|||||||
PDFWorker,
|
PDFWorker,
|
||||||
RenderTask,
|
RenderTask,
|
||||||
} from "../../src/display/api.js";
|
} from "../../src/display/api.js";
|
||||||
import {
|
|
||||||
fetchData as fetchDataDOM,
|
|
||||||
PageViewport,
|
|
||||||
RenderingCancelledException,
|
|
||||||
StatTimer,
|
|
||||||
} from "../../src/display/display_utils.js";
|
|
||||||
import { AutoPrintRegExp } from "../../web/ui_utils.js";
|
import { AutoPrintRegExp } from "../../web/ui_utils.js";
|
||||||
import { GlobalImageCache } from "../../src/core/image_utils.js";
|
import { GlobalImageCache } from "../../src/core/image_utils.js";
|
||||||
import { GlobalWorkerOptions } from "../../src/display/worker_options.js";
|
import { GlobalWorkerOptions } from "../../src/display/worker_options.js";
|
||||||
@ -67,17 +66,11 @@ describe("api", function () {
|
|||||||
const tracemonkeyGetDocumentParams =
|
const tracemonkeyGetDocumentParams =
|
||||||
buildGetDocumentParams(tracemonkeyFileName);
|
buildGetDocumentParams(tracemonkeyFileName);
|
||||||
|
|
||||||
let CanvasFactory;
|
|
||||||
|
|
||||||
beforeAll(async function () {
|
beforeAll(async function () {
|
||||||
CanvasFactory = new DefaultCanvasFactory({});
|
|
||||||
|
|
||||||
await TestPdfsServer.ensureStarted();
|
await TestPdfsServer.ensureStarted();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async function () {
|
afterAll(async function () {
|
||||||
CanvasFactory = null;
|
|
||||||
|
|
||||||
await TestPdfsServer.ensureStopped();
|
await TestPdfsServer.ensureStopped();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -4280,7 +4273,8 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
const viewport = pdfPage.getViewport({ scale: 1 });
|
const viewport = pdfPage.getViewport({ scale: 1 });
|
||||||
expect(viewport instanceof PageViewport).toEqual(true);
|
expect(viewport instanceof PageViewport).toEqual(true);
|
||||||
|
|
||||||
const canvasAndCtx = CanvasFactory.create(
|
const { canvasFactory } = pdfDoc;
|
||||||
|
const canvasAndCtx = canvasFactory.create(
|
||||||
viewport.width,
|
viewport.width,
|
||||||
viewport.height
|
viewport.height
|
||||||
);
|
);
|
||||||
@ -4307,7 +4301,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
expect(statEntryThree.name).toEqual("Overall");
|
expect(statEntryThree.name).toEqual("Overall");
|
||||||
expect(statEntryThree.end - statEntryThree.start).toBeGreaterThan(0);
|
expect(statEntryThree.end - statEntryThree.start).toBeGreaterThan(0);
|
||||||
|
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -4315,7 +4309,8 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
const viewport = page.getViewport({ scale: 1 });
|
const viewport = page.getViewport({ scale: 1 });
|
||||||
expect(viewport instanceof PageViewport).toEqual(true);
|
expect(viewport instanceof PageViewport).toEqual(true);
|
||||||
|
|
||||||
const canvasAndCtx = CanvasFactory.create(
|
const { canvasFactory } = pdfDocument;
|
||||||
|
const canvasAndCtx = canvasFactory.create(
|
||||||
viewport.width,
|
viewport.width,
|
||||||
viewport.height
|
viewport.height
|
||||||
);
|
);
|
||||||
@ -4338,14 +4333,15 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
expect(reason.extraDelay).toEqual(0);
|
expect(reason.extraDelay).toEqual(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("re-render page, using the same canvas, after cancelling rendering", async function () {
|
it("re-render page, using the same canvas, after cancelling rendering", async function () {
|
||||||
const viewport = page.getViewport({ scale: 1 });
|
const viewport = page.getViewport({ scale: 1 });
|
||||||
expect(viewport instanceof PageViewport).toEqual(true);
|
expect(viewport instanceof PageViewport).toEqual(true);
|
||||||
|
|
||||||
const canvasAndCtx = CanvasFactory.create(
|
const { canvasFactory } = pdfDocument;
|
||||||
|
const canvasAndCtx = canvasFactory.create(
|
||||||
viewport.width,
|
viewport.width,
|
||||||
viewport.height
|
viewport.height
|
||||||
);
|
);
|
||||||
@ -4375,7 +4371,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
await reRenderTask.promise;
|
await reRenderTask.promise;
|
||||||
expect(reRenderTask.separateAnnots).toEqual(false);
|
expect(reRenderTask.separateAnnots).toEqual(false);
|
||||||
|
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("multiple render() on the same canvas", async function () {
|
it("multiple render() on the same canvas", async function () {
|
||||||
@ -4385,7 +4381,8 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
const viewport = page.getViewport({ scale: 1 });
|
const viewport = page.getViewport({ scale: 1 });
|
||||||
expect(viewport instanceof PageViewport).toEqual(true);
|
expect(viewport instanceof PageViewport).toEqual(true);
|
||||||
|
|
||||||
const canvasAndCtx = CanvasFactory.create(
|
const { canvasFactory } = pdfDocument;
|
||||||
|
const canvasAndCtx = canvasFactory.create(
|
||||||
viewport.width,
|
viewport.width,
|
||||||
viewport.height
|
viewport.height
|
||||||
);
|
);
|
||||||
@ -4416,6 +4413,8 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("cleans up document resources after rendering of page", async function () {
|
it("cleans up document resources after rendering of page", async function () {
|
||||||
@ -4426,7 +4425,8 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
const viewport = pdfPage.getViewport({ scale: 1 });
|
const viewport = pdfPage.getViewport({ scale: 1 });
|
||||||
expect(viewport instanceof PageViewport).toEqual(true);
|
expect(viewport instanceof PageViewport).toEqual(true);
|
||||||
|
|
||||||
const canvasAndCtx = CanvasFactory.create(
|
const { canvasFactory } = pdfDoc;
|
||||||
|
const canvasAndCtx = canvasFactory.create(
|
||||||
viewport.width,
|
viewport.width,
|
||||||
viewport.height
|
viewport.height
|
||||||
);
|
);
|
||||||
@ -4442,7 +4442,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
await pdfDoc.cleanup();
|
await pdfDoc.cleanup();
|
||||||
expect(true).toEqual(true);
|
expect(true).toEqual(true);
|
||||||
|
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -4454,7 +4454,8 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
const viewport = pdfPage.getViewport({ scale: 1 });
|
const viewport = pdfPage.getViewport({ scale: 1 });
|
||||||
expect(viewport instanceof PageViewport).toEqual(true);
|
expect(viewport instanceof PageViewport).toEqual(true);
|
||||||
|
|
||||||
const canvasAndCtx = CanvasFactory.create(
|
const { canvasFactory } = pdfDoc;
|
||||||
|
const canvasAndCtx = canvasFactory.create(
|
||||||
viewport.width,
|
viewport.width,
|
||||||
viewport.height
|
viewport.height
|
||||||
);
|
);
|
||||||
@ -4489,7 +4490,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
const { data } = canvasAndCtx.context.getImageData(0, 0, 1, 1);
|
const { data } = canvasAndCtx.context.getImageData(0, 0, 1, 1);
|
||||||
expect(data).toEqual(new Uint8ClampedArray([255, 0, 0, 255]));
|
expect(data).toEqual(new Uint8ClampedArray([255, 0, 0, 255]));
|
||||||
|
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -4505,6 +4506,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
const pdfDoc = await loadingTask.promise;
|
const pdfDoc = await loadingTask.promise;
|
||||||
|
const { canvasFactory } = pdfDoc;
|
||||||
let checkedCopyLocalImage = false,
|
let checkedCopyLocalImage = false,
|
||||||
firstImgData = null,
|
firstImgData = null,
|
||||||
firstStatsOverall = null;
|
firstStatsOverall = null;
|
||||||
@ -4513,7 +4515,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
const pdfPage = await pdfDoc.getPage(i);
|
const pdfPage = await pdfDoc.getPage(i);
|
||||||
const viewport = pdfPage.getViewport({ scale: 1 });
|
const viewport = pdfPage.getViewport({ scale: 1 });
|
||||||
|
|
||||||
const canvasAndCtx = CanvasFactory.create(
|
const canvasAndCtx = canvasFactory.create(
|
||||||
viewport.width,
|
viewport.width,
|
||||||
viewport.height
|
viewport.height
|
||||||
);
|
);
|
||||||
@ -4526,7 +4528,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
const opList = renderTask.getOperatorList();
|
const opList = renderTask.getOperatorList();
|
||||||
// The canvas is no longer necessary, since we only care about
|
// The canvas is no longer necessary, since we only care about
|
||||||
// the image-data below.
|
// the image-data below.
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
|
|
||||||
const [statsOverall] = pdfPage.stats.times
|
const [statsOverall] = pdfPage.stats.times
|
||||||
.filter(time => time.name === "Overall")
|
.filter(time => time.name === "Overall")
|
||||||
@ -4609,6 +4611,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
const pdfDoc = await loadingTask.promise;
|
const pdfDoc = await loadingTask.promise;
|
||||||
|
const { canvasFactory } = pdfDoc;
|
||||||
let checkedCopyLocalImage = false,
|
let checkedCopyLocalImage = false,
|
||||||
firstStatsOverall = null;
|
firstStatsOverall = null;
|
||||||
|
|
||||||
@ -4616,7 +4619,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
const pdfPage = await pdfDoc.getPage(i);
|
const pdfPage = await pdfDoc.getPage(i);
|
||||||
const viewport = pdfPage.getViewport({ scale: 1 });
|
const viewport = pdfPage.getViewport({ scale: 1 });
|
||||||
|
|
||||||
const canvasAndCtx = CanvasFactory.create(
|
const canvasAndCtx = canvasFactory.create(
|
||||||
viewport.width,
|
viewport.width,
|
||||||
viewport.height
|
viewport.height
|
||||||
);
|
);
|
||||||
@ -4628,7 +4631,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
await renderTask.promise;
|
await renderTask.promise;
|
||||||
// The canvas is no longer necessary, since we only care about
|
// The canvas is no longer necessary, since we only care about
|
||||||
// the stats below.
|
// the stats below.
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
|
|
||||||
const [statsOverall] = pdfPage.stats.times
|
const [statsOverall] = pdfPage.stats.times
|
||||||
.filter(time => time.name === "Overall")
|
.filter(time => time.name === "Overall")
|
||||||
@ -4656,13 +4659,14 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
|
|
||||||
const loadingTask = getDocument(buildGetDocumentParams("issue18042.pdf"));
|
const loadingTask = getDocument(buildGetDocumentParams("issue18042.pdf"));
|
||||||
const pdfDoc = await loadingTask.promise;
|
const pdfDoc = await loadingTask.promise;
|
||||||
|
const { canvasFactory } = pdfDoc;
|
||||||
let checkedGlobalDecodeFailed = false;
|
let checkedGlobalDecodeFailed = false;
|
||||||
|
|
||||||
for (let i = 1; i <= pdfDoc.numPages; i++) {
|
for (let i = 1; i <= pdfDoc.numPages; i++) {
|
||||||
const pdfPage = await pdfDoc.getPage(i);
|
const pdfPage = await pdfDoc.getPage(i);
|
||||||
const viewport = pdfPage.getViewport({ scale: 1 });
|
const viewport = pdfPage.getViewport({ scale: 1 });
|
||||||
|
|
||||||
const canvasAndCtx = CanvasFactory.create(
|
const canvasAndCtx = canvasFactory.create(
|
||||||
viewport.width,
|
viewport.width,
|
||||||
viewport.height
|
viewport.height
|
||||||
);
|
);
|
||||||
@ -4675,7 +4679,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
const opList = renderTask.getOperatorList();
|
const opList = renderTask.getOperatorList();
|
||||||
// The canvas is no longer necessary, since we only care about
|
// The canvas is no longer necessary, since we only care about
|
||||||
// the image-data below.
|
// the image-data below.
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
|
|
||||||
const { commonObjs, objs } = pdfPage;
|
const { commonObjs, objs } = pdfPage;
|
||||||
const imgIndex = opList.fnArray.indexOf(OPS.paintImageXObject);
|
const imgIndex = opList.fnArray.indexOf(OPS.paintImageXObject);
|
||||||
@ -4712,7 +4716,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
|
|
||||||
it("render for printing, with `printAnnotationStorage` set", async function () {
|
it("render for printing, with `printAnnotationStorage` set", async function () {
|
||||||
async function getPrintData(printAnnotationStorage = null) {
|
async function getPrintData(printAnnotationStorage = null) {
|
||||||
const canvasAndCtx = CanvasFactory.create(
|
const canvasAndCtx = canvasFactory.create(
|
||||||
viewport.width,
|
viewport.width,
|
||||||
viewport.height
|
viewport.height
|
||||||
);
|
);
|
||||||
@ -4728,7 +4732,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
expect(renderTask.separateAnnots).toEqual(false);
|
expect(renderTask.separateAnnots).toEqual(false);
|
||||||
|
|
||||||
const printData = canvasAndCtx.canvas.toDataURL();
|
const printData = canvasAndCtx.canvas.toDataURL();
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
|
|
||||||
return printData;
|
return printData;
|
||||||
}
|
}
|
||||||
@ -4737,6 +4741,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
buildGetDocumentParams("annotation-tx.pdf")
|
buildGetDocumentParams("annotation-tx.pdf")
|
||||||
);
|
);
|
||||||
const pdfDoc = await loadingTask.promise;
|
const pdfDoc = await loadingTask.promise;
|
||||||
|
const { canvasFactory } = pdfDoc;
|
||||||
const pdfPage = await pdfDoc.getPage(1);
|
const pdfPage = await pdfDoc.getPage(1);
|
||||||
const viewport = pdfPage.getViewport({ scale: 1 });
|
const viewport = pdfPage.getViewport({ scale: 1 });
|
||||||
|
|
||||||
@ -4797,7 +4802,8 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
const viewport = page.getViewport({ scale: 1.2 });
|
const viewport = page.getViewport({ scale: 1.2 });
|
||||||
expect(viewport instanceof PageViewport).toEqual(true);
|
expect(viewport instanceof PageViewport).toEqual(true);
|
||||||
|
|
||||||
const canvasAndCtx = CanvasFactory.create(
|
const { canvasFactory } = pdf;
|
||||||
|
const canvasAndCtx = canvasFactory.create(
|
||||||
viewport.width,
|
viewport.width,
|
||||||
viewport.height
|
viewport.height
|
||||||
);
|
);
|
||||||
@ -4809,7 +4815,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
|
|||||||
expect(renderTask.separateAnnots).toEqual(false);
|
expect(renderTask.separateAnnots).toEqual(false);
|
||||||
|
|
||||||
const data = canvasAndCtx.canvas.toDataURL();
|
const data = canvasAndCtx.canvas.toDataURL();
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,8 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { CMap, CMapFactory, IdentityCMap } from "../../src/core/cmap.js";
|
import { CMap, CMapFactory, IdentityCMap } from "../../src/core/cmap.js";
|
||||||
import { CMAP_URL } from "./test_utils.js";
|
import { CMAP_URL, DefaultCMapReaderFactory } from "./test_utils.js";
|
||||||
import { DefaultCMapReaderFactory } from "../../src/display/api.js";
|
|
||||||
import { Name } from "../../src/core/primitives.js";
|
import { Name } from "../../src/core/primitives.js";
|
||||||
import { StringStream } from "../../src/core/stream.js";
|
import { StringStream } from "../../src/core/stream.js";
|
||||||
|
|
||||||
|
|||||||
@ -13,8 +13,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { DefaultCanvasFactory, getDocument } from "../../src/display/api.js";
|
|
||||||
import { buildGetDocumentParams } from "./test_utils.js";
|
import { buildGetDocumentParams } from "./test_utils.js";
|
||||||
|
import { getDocument } from "../../src/display/api.js";
|
||||||
|
|
||||||
function getTopLeftPixel(canvasContext) {
|
function getTopLeftPixel(canvasContext) {
|
||||||
const imgData = canvasContext.getImageData(0, 0, 1, 1);
|
const imgData = canvasContext.getImageData(0, 0, 1, 1);
|
||||||
@ -30,28 +30,24 @@ describe("custom canvas rendering", function () {
|
|||||||
const transparentGetDocumentParams =
|
const transparentGetDocumentParams =
|
||||||
buildGetDocumentParams("transparent.pdf");
|
buildGetDocumentParams("transparent.pdf");
|
||||||
|
|
||||||
let CanvasFactory;
|
let loadingTask, doc, page;
|
||||||
let loadingTask;
|
|
||||||
let page;
|
|
||||||
|
|
||||||
beforeAll(async function () {
|
beforeAll(async function () {
|
||||||
CanvasFactory = new DefaultCanvasFactory({});
|
|
||||||
|
|
||||||
loadingTask = getDocument(transparentGetDocumentParams);
|
loadingTask = getDocument(transparentGetDocumentParams);
|
||||||
const doc = await loadingTask.promise;
|
doc = await loadingTask.promise;
|
||||||
const data = await doc.getPage(1);
|
page = await doc.getPage(1);
|
||||||
page = data;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async function () {
|
afterAll(async function () {
|
||||||
CanvasFactory = null;
|
doc = null;
|
||||||
page = null;
|
page = null;
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders to canvas with a default white background", async function () {
|
it("renders to canvas with a default white background", async function () {
|
||||||
const viewport = page.getViewport({ scale: 1 });
|
const viewport = page.getViewport({ scale: 1 });
|
||||||
const canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
const { canvasFactory } = doc;
|
||||||
|
const canvasAndCtx = canvasFactory.create(viewport.width, viewport.height);
|
||||||
|
|
||||||
const renderTask = page.render({
|
const renderTask = page.render({
|
||||||
canvasContext: canvasAndCtx.context,
|
canvasContext: canvasAndCtx.context,
|
||||||
@ -65,12 +61,13 @@ describe("custom canvas rendering", function () {
|
|||||||
b: 255,
|
b: 255,
|
||||||
a: 255,
|
a: 255,
|
||||||
});
|
});
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders to canvas with a custom background", async function () {
|
it("renders to canvas with a custom background", async function () {
|
||||||
const viewport = page.getViewport({ scale: 1 });
|
const viewport = page.getViewport({ scale: 1 });
|
||||||
const canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
const { canvasFactory } = doc;
|
||||||
|
const canvasAndCtx = canvasFactory.create(viewport.width, viewport.height);
|
||||||
|
|
||||||
const renderTask = page.render({
|
const renderTask = page.render({
|
||||||
canvasContext: canvasAndCtx.context,
|
canvasContext: canvasAndCtx.context,
|
||||||
@ -85,7 +82,7 @@ describe("custom canvas rendering", function () {
|
|||||||
b: 0,
|
b: 0,
|
||||||
a: 255,
|
a: 255,
|
||||||
});
|
});
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -137,17 +134,15 @@ describe("custom ownerDocument", function () {
|
|||||||
getElementsByTagName: () => [{ append: () => {} }],
|
getElementsByTagName: () => [{ append: () => {} }],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const CanvasFactory = new DefaultCanvasFactory({ ownerDocument });
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
elements,
|
elements,
|
||||||
ownerDocument,
|
ownerDocument,
|
||||||
CanvasFactory,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should use given document for loading fonts (with Font Loading API)", async function () {
|
it("should use given document for loading fonts (with Font Loading API)", async function () {
|
||||||
const { ownerDocument, elements, CanvasFactory } = getMocks();
|
const { ownerDocument, elements } = getMocks();
|
||||||
const getDocumentParams = buildGetDocumentParams(
|
const getDocumentParams = buildGetDocumentParams(
|
||||||
"TrueType_without_cmap.pdf",
|
"TrueType_without_cmap.pdf",
|
||||||
{
|
{
|
||||||
@ -161,7 +156,8 @@ describe("custom ownerDocument", function () {
|
|||||||
const page = await doc.getPage(1);
|
const page = await doc.getPage(1);
|
||||||
|
|
||||||
const viewport = page.getViewport({ scale: 1 });
|
const viewport = page.getViewport({ scale: 1 });
|
||||||
const canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
const { canvasFactory } = doc;
|
||||||
|
const canvasAndCtx = canvasFactory.create(viewport.width, viewport.height);
|
||||||
|
|
||||||
await page.render({
|
await page.render({
|
||||||
canvasContext: canvasAndCtx.context,
|
canvasContext: canvasAndCtx.context,
|
||||||
@ -174,12 +170,12 @@ describe("custom ownerDocument", function () {
|
|||||||
expect(Array.from(ownerDocument.fonts).find(checkFont)).toBeTruthy();
|
expect(Array.from(ownerDocument.fonts).find(checkFont)).toBeTruthy();
|
||||||
|
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
expect(ownerDocument.fonts.size).toBe(0);
|
expect(ownerDocument.fonts.size).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should use given document for loading fonts (with CSS rules)", async function () {
|
it("should use given document for loading fonts (with CSS rules)", async function () {
|
||||||
const { ownerDocument, elements, CanvasFactory } = getMocks();
|
const { ownerDocument, elements } = getMocks();
|
||||||
ownerDocument.fonts = null;
|
ownerDocument.fonts = null;
|
||||||
const getDocumentParams = buildGetDocumentParams(
|
const getDocumentParams = buildGetDocumentParams(
|
||||||
"TrueType_without_cmap.pdf",
|
"TrueType_without_cmap.pdf",
|
||||||
@ -194,7 +190,8 @@ describe("custom ownerDocument", function () {
|
|||||||
const page = await doc.getPage(1);
|
const page = await doc.getPage(1);
|
||||||
|
|
||||||
const viewport = page.getViewport({ scale: 1 });
|
const viewport = page.getViewport({ scale: 1 });
|
||||||
const canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
const { canvasFactory } = doc;
|
||||||
|
const canvasAndCtx = canvasFactory.create(viewport.width, viewport.height);
|
||||||
|
|
||||||
await page.render({
|
await page.render({
|
||||||
canvasContext: canvasAndCtx.context,
|
canvasContext: canvasAndCtx.context,
|
||||||
@ -206,7 +203,7 @@ describe("custom ownerDocument", function () {
|
|||||||
expect(style.sheet.cssRules.find(checkFontFaceRule)).toBeTruthy();
|
expect(style.sheet.cssRules.find(checkFontFaceRule)).toBeTruthy();
|
||||||
|
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
expect(style.remove.called).toBe(true);
|
expect(style.remove.called).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -14,10 +14,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { assert, isNodeJS } from "../../src/shared/util.js";
|
import { assert, isNodeJS } from "../../src/shared/util.js";
|
||||||
|
import {
|
||||||
|
fetchData as fetchDataNode,
|
||||||
|
NodeCMapReaderFactory,
|
||||||
|
NodeStandardFontDataFactory,
|
||||||
|
} from "../../src/display/node_utils.js";
|
||||||
import { NullStream, StringStream } from "../../src/core/stream.js";
|
import { NullStream, StringStream } from "../../src/core/stream.js";
|
||||||
import { Page, PDFDocument } from "../../src/core/document.js";
|
import { Page, PDFDocument } from "../../src/core/document.js";
|
||||||
|
import { DOMCMapReaderFactory } from "../../src/display/cmap_reader_factory.js";
|
||||||
|
import { DOMStandardFontDataFactory } from "../../src/display/standard_fontdata_factory.js";
|
||||||
import { fetchData as fetchDataDOM } from "../../src/display/display_utils.js";
|
import { fetchData as fetchDataDOM } from "../../src/display/display_utils.js";
|
||||||
import { fetchData as fetchDataNode } from "../../src/display/node_utils.js";
|
|
||||||
import { Ref } from "../../src/core/primitives.js";
|
import { Ref } from "../../src/core/primitives.js";
|
||||||
|
|
||||||
const TEST_PDFS_PATH = isNodeJS ? "./test/pdfs/" : "../pdfs/";
|
const TEST_PDFS_PATH = isNodeJS ? "./test/pdfs/" : "../pdfs/";
|
||||||
@ -40,6 +46,16 @@ class DefaultFileReaderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DefaultCMapReaderFactory =
|
||||||
|
typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
||||||
|
? NodeCMapReaderFactory
|
||||||
|
: DOMCMapReaderFactory;
|
||||||
|
|
||||||
|
const DefaultStandardFontDataFactory =
|
||||||
|
typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
||||||
|
? NodeStandardFontDataFactory
|
||||||
|
: DOMStandardFontDataFactory;
|
||||||
|
|
||||||
function buildGetDocumentParams(filename, options) {
|
function buildGetDocumentParams(filename, options) {
|
||||||
const params = Object.create(null);
|
const params = Object.create(null);
|
||||||
params.url = isNodeJS
|
params.url = isNodeJS
|
||||||
@ -234,7 +250,9 @@ export {
|
|||||||
buildGetDocumentParams,
|
buildGetDocumentParams,
|
||||||
CMAP_URL,
|
CMAP_URL,
|
||||||
createIdFactory,
|
createIdFactory,
|
||||||
|
DefaultCMapReaderFactory,
|
||||||
DefaultFileReaderFactory,
|
DefaultFileReaderFactory,
|
||||||
|
DefaultStandardFontDataFactory,
|
||||||
getCrossOriginHostname,
|
getCrossOriginHostname,
|
||||||
STANDARD_FONT_DATA_URL,
|
STANDARD_FONT_DATA_URL,
|
||||||
TEST_PDFS_PATH,
|
TEST_PDFS_PATH,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user