mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Merge pull request #13867 from Snuffleupagus/RenderingIntentFlag
[api-minor] Re-factor the *internal* renderingIntent, and change the default `intent` value in the `PDFPageProxy.getAnnotations` method
This commit is contained in:
commit
952f6366bf
6 changed files with 96 additions and 43 deletions
|
@ -25,6 +25,7 @@ import {
|
|||
isString,
|
||||
OPS,
|
||||
PageActionEventType,
|
||||
RenderingIntentFlag,
|
||||
shadow,
|
||||
stringToBytes,
|
||||
stringToPDFString,
|
||||
|
@ -319,14 +320,7 @@ class Page {
|
|||
});
|
||||
}
|
||||
|
||||
getOperatorList({
|
||||
handler,
|
||||
sink,
|
||||
task,
|
||||
intent,
|
||||
renderInteractiveForms,
|
||||
annotationStorage,
|
||||
}) {
|
||||
getOperatorList({ handler, sink, task, intent, annotationStorage }) {
|
||||
const contentStreamPromise = this.getContentStream(handler);
|
||||
const resourcesPromise = this.loadResources([
|
||||
"ColorSpace",
|
||||
|
@ -383,26 +377,26 @@ class Page {
|
|||
pageOpList.flush(true);
|
||||
return { length: pageOpList.totalLength };
|
||||
}
|
||||
const renderForms = !!(intent & RenderingIntentFlag.ANNOTATION_FORMS),
|
||||
intentAny = !!(intent & RenderingIntentFlag.ANY),
|
||||
intentDisplay = !!(intent & RenderingIntentFlag.DISPLAY),
|
||||
intentPrint = !!(intent & RenderingIntentFlag.PRINT);
|
||||
|
||||
// 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 (
|
||||
(annotationIntent === "display" &&
|
||||
annotation.mustBeViewed(annotationStorage)) ||
|
||||
(annotationIntent === "print" &&
|
||||
annotation.mustBePrinted(annotationStorage))
|
||||
intentAny ||
|
||||
(intentDisplay && annotation.mustBeViewed(annotationStorage)) ||
|
||||
(intentPrint && annotation.mustBePrinted(annotationStorage))
|
||||
) {
|
||||
opListPromises.push(
|
||||
annotation
|
||||
.getOperatorList(
|
||||
partialEvaluator,
|
||||
task,
|
||||
renderInteractiveForms,
|
||||
renderForms,
|
||||
annotationStorage
|
||||
)
|
||||
.catch(function (reason) {
|
||||
|
@ -496,15 +490,23 @@ class Page {
|
|||
getAnnotationsData(intent) {
|
||||
return this._parsedAnnotations.then(function (annotations) {
|
||||
const annotationsData = [];
|
||||
for (let i = 0, ii = annotations.length; i < ii; i++) {
|
||||
|
||||
if (annotations.length === 0) {
|
||||
return annotationsData;
|
||||
}
|
||||
const intentAny = !!(intent & RenderingIntentFlag.ANY),
|
||||
intentDisplay = !!(intent & RenderingIntentFlag.DISPLAY),
|
||||
intentPrint = !!(intent & RenderingIntentFlag.PRINT);
|
||||
|
||||
for (const annotation of annotations) {
|
||||
// Get the annotation even if it's hidden because
|
||||
// JS can change its display.
|
||||
if (
|
||||
!intent ||
|
||||
(intent === "display" && annotations[i].viewable) ||
|
||||
(intent === "print" && annotations[i].printable)
|
||||
intentAny ||
|
||||
(intentDisplay && annotation.viewable) ||
|
||||
(intentPrint && annotation.printable)
|
||||
) {
|
||||
annotationsData.push(annotations[i].data);
|
||||
annotationsData.push(annotation.data);
|
||||
}
|
||||
}
|
||||
return annotationsData;
|
||||
|
|
|
@ -13,7 +13,14 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { assert, ImageKind, OPS, shadow, warn } from "../shared/util.js";
|
||||
import {
|
||||
assert,
|
||||
ImageKind,
|
||||
OPS,
|
||||
RenderingIntentFlag,
|
||||
shadow,
|
||||
warn,
|
||||
} from "../shared/util.js";
|
||||
|
||||
function addState(parentState, pattern, checkFn, iterateFn, processFn) {
|
||||
let state = parentState;
|
||||
|
@ -597,11 +604,11 @@ class OperatorList {
|
|||
return shadow(this, "CHUNK_SIZE_ABOUT", this.CHUNK_SIZE - 5);
|
||||
}
|
||||
|
||||
constructor(intent, streamSink) {
|
||||
constructor(intent = 0, streamSink) {
|
||||
this._streamSink = streamSink;
|
||||
this.fnArray = [];
|
||||
this.argsArray = [];
|
||||
if (streamSink && !(intent && intent.startsWith("oplist-"))) {
|
||||
if (streamSink && !(intent & RenderingIntentFlag.OPLIST)) {
|
||||
this.optimizer = new QueueOptimizer(this);
|
||||
} else {
|
||||
this.optimizer = new NullOptimizer(this);
|
||||
|
|
|
@ -688,7 +688,6 @@ class WorkerMessageHandler {
|
|||
sink,
|
||||
task,
|
||||
intent: data.intent,
|
||||
renderInteractiveForms: data.renderInteractiveForms,
|
||||
annotationStorage: data.annotationStorage,
|
||||
})
|
||||
.then(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue