mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
[api-minor] Add intent
support to the PDFPageProxy.getOperatorList
method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods. Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now. Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future. Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists). *Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
This commit is contained in:
parent
f1ae7d7b0e
commit
03cf28bf17
7 changed files with 121 additions and 17 deletions
|
@ -1689,6 +1689,12 @@ describe("annotation", function () {
|
|||
OPS.setFillRGBColor,
|
||||
OPS.endAnnotation,
|
||||
]);
|
||||
expect(operatorList.argsArray[0]).toEqual([
|
||||
"271R",
|
||||
[0, 0, 32, 10],
|
||||
[32, 0, 0, 10, 0, 0],
|
||||
[1, 0, 0, 1, 0, 0],
|
||||
]);
|
||||
expect(operatorList.argsArray[1]).toEqual(
|
||||
new Uint8ClampedArray([26, 51, 76])
|
||||
);
|
||||
|
@ -2324,6 +2330,12 @@ describe("annotation", function () {
|
|||
OPS.showText,
|
||||
OPS.endAnnotation,
|
||||
]);
|
||||
expect(operatorList.argsArray[0]).toEqual([
|
||||
"124R",
|
||||
[0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0],
|
||||
[1, 0, 0, 1, 0, 0],
|
||||
]);
|
||||
expect(operatorList.argsArray[3][0][0].unicode).toEqual("4");
|
||||
});
|
||||
|
||||
|
@ -2375,6 +2387,12 @@ describe("annotation", function () {
|
|||
OPS.setFillRGBColor,
|
||||
OPS.endAnnotation,
|
||||
]);
|
||||
expect(operatorList.argsArray[0]).toEqual([
|
||||
"124R",
|
||||
[0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0],
|
||||
[1, 0, 0, 1, 0, 0],
|
||||
]);
|
||||
expect(operatorList.argsArray[1]).toEqual(
|
||||
new Uint8ClampedArray([26, 51, 76])
|
||||
);
|
||||
|
@ -2393,6 +2411,12 @@ describe("annotation", function () {
|
|||
OPS.setFillRGBColor,
|
||||
OPS.endAnnotation,
|
||||
]);
|
||||
expect(operatorList.argsArray[0]).toEqual([
|
||||
"124R",
|
||||
[0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0],
|
||||
[1, 0, 0, 1, 0, 0],
|
||||
]);
|
||||
expect(operatorList.argsArray[1]).toEqual(
|
||||
new Uint8ClampedArray([76, 51, 26])
|
||||
);
|
||||
|
@ -2449,6 +2473,12 @@ describe("annotation", function () {
|
|||
OPS.setFillRGBColor,
|
||||
OPS.endAnnotation,
|
||||
]);
|
||||
expect(operatorList.argsArray[0]).toEqual([
|
||||
"1249R",
|
||||
[0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0],
|
||||
[1, 0, 0, 1, 0, 0],
|
||||
]);
|
||||
expect(operatorList.argsArray[1]).toEqual(
|
||||
new Uint8ClampedArray([26, 51, 76])
|
||||
);
|
||||
|
@ -2503,6 +2533,12 @@ describe("annotation", function () {
|
|||
OPS.setFillRGBColor,
|
||||
OPS.endAnnotation,
|
||||
]);
|
||||
expect(operatorList.argsArray[0]).toEqual([
|
||||
"124R",
|
||||
[0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0],
|
||||
[1, 0, 0, 1, 0, 0],
|
||||
]);
|
||||
expect(operatorList.argsArray[1]).toEqual(
|
||||
new Uint8ClampedArray([26, 51, 76])
|
||||
);
|
||||
|
@ -2700,6 +2736,12 @@ describe("annotation", function () {
|
|||
OPS.setFillRGBColor,
|
||||
OPS.endAnnotation,
|
||||
]);
|
||||
expect(operatorList.argsArray[0]).toEqual([
|
||||
"124R",
|
||||
[0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0],
|
||||
[1, 0, 0, 1, 0, 0],
|
||||
]);
|
||||
expect(operatorList.argsArray[1]).toEqual(
|
||||
new Uint8ClampedArray([26, 51, 76])
|
||||
);
|
||||
|
@ -2718,6 +2760,12 @@ describe("annotation", function () {
|
|||
OPS.setFillRGBColor,
|
||||
OPS.endAnnotation,
|
||||
]);
|
||||
expect(operatorList.argsArray[0]).toEqual([
|
||||
"124R",
|
||||
[0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0],
|
||||
[1, 0, 0, 1, 0, 0],
|
||||
]);
|
||||
expect(operatorList.argsArray[1]).toEqual(
|
||||
new Uint8ClampedArray([76, 51, 26])
|
||||
);
|
||||
|
@ -2772,6 +2820,12 @@ describe("annotation", function () {
|
|||
OPS.setFillRGBColor,
|
||||
OPS.endAnnotation,
|
||||
]);
|
||||
expect(operatorList.argsArray[0]).toEqual([
|
||||
"124R",
|
||||
[0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0],
|
||||
[1, 0, 0, 1, 0, 0],
|
||||
]);
|
||||
expect(operatorList.argsArray[1]).toEqual(
|
||||
new Uint8ClampedArray([76, 51, 26])
|
||||
);
|
||||
|
|
|
@ -1622,8 +1622,9 @@ describe("api", function () {
|
|||
|
||||
it("gets operator list", async function () {
|
||||
const operatorList = await page.getOperatorList();
|
||||
expect(!!operatorList.fnArray).toEqual(true);
|
||||
expect(!!operatorList.argsArray).toEqual(true);
|
||||
|
||||
expect(operatorList.fnArray.length).toBeGreaterThan(100);
|
||||
expect(operatorList.argsArray.length).toBeGreaterThan(100);
|
||||
expect(operatorList.lastChunk).toEqual(true);
|
||||
});
|
||||
|
||||
|
@ -1687,6 +1688,26 @@ describe("api", function () {
|
|||
}
|
||||
);
|
||||
|
||||
it("gets operator list, containing Annotation-operatorLists", async function () {
|
||||
const loadingTask = getDocument(
|
||||
buildGetDocumentParams("annotation-line.pdf")
|
||||
);
|
||||
const pdfDoc = await loadingTask.promise;
|
||||
const pdfPage = await pdfDoc.getPage(1);
|
||||
const operatorList = await pdfPage.getOperatorList();
|
||||
|
||||
expect(operatorList.fnArray.length).toBeGreaterThan(20);
|
||||
expect(operatorList.argsArray.length).toBeGreaterThan(20);
|
||||
expect(operatorList.lastChunk).toEqual(true);
|
||||
|
||||
// The `getOperatorList` method, similar to the `render` method,
|
||||
// is supposed to include any existing Annotation-operatorLists.
|
||||
expect(operatorList.fnArray.includes(OPS.beginAnnotation)).toEqual(true);
|
||||
expect(operatorList.fnArray.includes(OPS.endAnnotation)).toEqual(true);
|
||||
|
||||
await loadingTask.destroy();
|
||||
});
|
||||
|
||||
it("gets document stats after parsing page", async function () {
|
||||
const stats = await page.getOperatorList().then(function () {
|
||||
return pdfDocument.getStats();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue