1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #13746 from Snuffleupagus/getOperatorList-intent

[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
This commit is contained in:
Tim van der Meij 2021-07-18 13:28:08 +02:00 committed by GitHub
commit 668c58d68d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 121 additions and 17 deletions

View file

@ -702,7 +702,13 @@ class Annotation {
return resourcesPromise.then(resources => {
const opList = new OperatorList();
opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
opList.addOp(OPS.beginAnnotation, [
data.id,
data.rect,
transform,
matrix,
]);
return evaluator
.getOperatorList({
stream: appearance,
@ -1307,6 +1313,7 @@ class WidgetAnnotation extends Annotation {
const transform = getTransformMatrix(this.data.rect, bbox, matrix);
operatorList.addOp(OPS.beginAnnotation, [
this.data.id,
this.data.rect,
transform,
matrix,

View file

@ -366,12 +366,16 @@ class Page {
// Collect the operator list promises for the annotations. Each promise
// is resolved with the complete operator list for a single annotation.
const annotationIntent = intent.startsWith("oplist-")
? intent.split("-")[1]
: intent;
const opListPromises = [];
for (const annotation of annotations) {
if (
(intent === "display" &&
(annotationIntent === "display" &&
annotation.mustBeViewed(annotationStorage)) ||
(intent === "print" && annotation.mustBePrinted(annotationStorage))
(annotationIntent === "print" &&
annotation.mustBePrinted(annotationStorage))
) {
opListPromises.push(
annotation

View file

@ -594,14 +594,14 @@ class OperatorList {
// Close to chunk size.
static get CHUNK_SIZE_ABOUT() {
return shadow(this, "CHUNK_SIZE_ABOUT", OperatorList.CHUNK_SIZE - 5);
return shadow(this, "CHUNK_SIZE_ABOUT", this.CHUNK_SIZE - 5);
}
constructor(intent, streamSink) {
this._streamSink = streamSink;
this.fnArray = [];
this.argsArray = [];
if (streamSink && intent !== "oplist") {
if (streamSink && !(intent && intent.startsWith("oplist-"))) {
this.optimizer = new QueueOptimizer(this);
} else {
this.optimizer = new NullOptimizer(this);

View file

@ -1149,7 +1149,7 @@ class PDFDocumentProxy {
* Page annotation parameters.
*
* @typedef {Object} GetAnnotationsParameters
* @property {string} intent - Determines the annotations that will be fetched,
* @property {string} [intent] - Determines the annotations that are fetched,
* can be either 'display' (viewable annotations) or 'print' (printable
* annotations). If the parameter is omitted, all annotations are fetched.
*/
@ -1187,6 +1187,14 @@ class PDFDocumentProxy {
* states set.
*/
/**
* Page getOperatorList parameters.
*
* @typedef {Object} GetOperatorListParameters
* @property {string} [intent] - Rendering intent, can be 'display' or 'print'.
* The default value is 'display'.
*/
/**
* Structure tree node. The root node will have a role "Root".
*
@ -1299,12 +1307,18 @@ class PDFPageProxy {
* {Array} of the annotation objects.
*/
getAnnotations({ intent = null } = {}) {
if (!this._annotationsPromise || this._annotationsIntent !== intent) {
const renderingIntent =
intent === "display" || intent === "print" ? intent : null;
if (
!this._annotationsPromise ||
this._annotationsIntent !== renderingIntent
) {
this._annotationsPromise = this._transport.getAnnotations(
this._pageIndex,
intent
renderingIntent
);
this._annotationsIntent = intent;
this._annotationsIntent = renderingIntent;
}
return this._annotationsPromise;
}
@ -1332,7 +1346,7 @@ class PDFPageProxy {
/**
* Begins the process of rendering a page to the desired context.
*
* @param {RenderParameters} params Page render parameters.
* @param {RenderParameters} params - Page render parameters.
* @returns {RenderTask} An object that contains a promise that is
* resolved when the page finishes rendering.
*/
@ -1473,10 +1487,12 @@ class PDFPageProxy {
}
/**
* @param {GetOperatorListParameters} params - Page getOperatorList
* parameters.
* @returns {Promise<PDFOperatorList>} A promise resolved with an
* {@link PDFOperatorList} object that represents page's operator list.
* {@link PDFOperatorList} object that represents the page's operator list.
*/
getOperatorList() {
getOperatorList({ intent = "display" } = {}) {
function operatorListChanged() {
if (intentState.operatorList.lastChunk) {
intentState.opListReadCapability.resolve(intentState.operatorList);
@ -1485,7 +1501,9 @@ class PDFPageProxy {
}
}
const renderingIntent = "oplist";
const renderingIntent = `oplist-${
intent === "print" ? "print" : "display"
}`;
let intentState = this._intentStates.get(renderingIntent);
if (!intentState) {
intentState = Object.create(null);
@ -1600,7 +1618,7 @@ class PDFPageProxy {
force: true,
});
if (intent === "oplist") {
if (intent.startsWith("oplist-")) {
// Avoid errors below, since the renderTasks are just stubs.
continue;
}

View file

@ -2401,7 +2401,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();