1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Enable auto-formatting of the entire code-base using Prettier (issue 11444)

Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).

Prettier is being used for a couple of reasons:

 - To be consistent with `mozilla-central`, where Prettier is already in use across the tree.

 - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.

Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.

*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.

(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
This commit is contained in:
Jonas Jenwald 2019-12-25 15:59:37 +01:00
parent 8ec1dfde49
commit de36b2aaba
205 changed files with 40024 additions and 31859 deletions

View file

@ -15,16 +15,25 @@
/* eslint no-var: error */
import {
AnnotationBorderStyleType, AnnotationFieldFlag, AnnotationFlag,
AnnotationReplyType, AnnotationType, assert, isString, OPS, stringToBytes,
stringToPDFString, Util, warn
} from '../shared/util';
import { Catalog, FileSpec, ObjectLoader } from './obj';
import { Dict, isDict, isName, isRef, isStream } from './primitives';
import { ColorSpace } from './colorspace';
import { getInheritableProperty } from './core_utils';
import { OperatorList } from './operator_list';
import { Stream } from './stream';
AnnotationBorderStyleType,
AnnotationFieldFlag,
AnnotationFlag,
AnnotationReplyType,
AnnotationType,
assert,
isString,
OPS,
stringToBytes,
stringToPDFString,
Util,
warn,
} from "../shared/util";
import { Catalog, FileSpec, ObjectLoader } from "./obj";
import { Dict, isDict, isName, isRef, isStream } from "./primitives";
import { ColorSpace } from "./colorspace";
import { getInheritableProperty } from "./core_utils";
import { OperatorList } from "./operator_list";
import { Stream } from "./stream";
class AnnotationFactory {
/**
@ -40,8 +49,12 @@ class AnnotationFactory {
* instance.
*/
static create(xref, ref, pdfManager, idFactory) {
return pdfManager.ensure(this, '_create',
[xref, ref, pdfManager, idFactory]);
return pdfManager.ensure(this, "_create", [
xref,
ref,
pdfManager,
idFactory,
]);
}
/**
@ -55,7 +68,7 @@ class AnnotationFactory {
const id = isRef(ref) ? ref.toString() : `annot_${idFactory.createObjId()}`;
// Determine the annotation's subtype.
let subtype = dict.get('Subtype');
let subtype = dict.get("Subtype");
subtype = isName(subtype) ? subtype.name : null;
// Return the right annotation object based on the subtype and field type.
@ -68,79 +81,87 @@ class AnnotationFactory {
};
switch (subtype) {
case 'Link':
case "Link":
return new LinkAnnotation(parameters);
case 'Text':
case "Text":
return new TextAnnotation(parameters);
case 'Widget':
let fieldType = getInheritableProperty({ dict, key: 'FT', });
case "Widget":
let fieldType = getInheritableProperty({ dict, key: "FT" });
fieldType = isName(fieldType) ? fieldType.name : null;
switch (fieldType) {
case 'Tx':
case "Tx":
return new TextWidgetAnnotation(parameters);
case 'Btn':
case "Btn":
return new ButtonWidgetAnnotation(parameters);
case 'Ch':
case "Ch":
return new ChoiceWidgetAnnotation(parameters);
}
warn('Unimplemented widget field type "' + fieldType + '", ' +
'falling back to base field type.');
warn(
'Unimplemented widget field type "' +
fieldType +
'", ' +
"falling back to base field type."
);
return new WidgetAnnotation(parameters);
case 'Popup':
case "Popup":
return new PopupAnnotation(parameters);
case 'FreeText':
case "FreeText":
return new FreeTextAnnotation(parameters);
case 'Line':
case "Line":
return new LineAnnotation(parameters);
case 'Square':
case "Square":
return new SquareAnnotation(parameters);
case 'Circle':
case "Circle":
return new CircleAnnotation(parameters);
case 'PolyLine':
case "PolyLine":
return new PolylineAnnotation(parameters);
case 'Polygon':
case "Polygon":
return new PolygonAnnotation(parameters);
case 'Caret':
case "Caret":
return new CaretAnnotation(parameters);
case 'Ink':
case "Ink":
return new InkAnnotation(parameters);
case 'Highlight':
case "Highlight":
return new HighlightAnnotation(parameters);
case 'Underline':
case "Underline":
return new UnderlineAnnotation(parameters);
case 'Squiggly':
case "Squiggly":
return new SquigglyAnnotation(parameters);
case 'StrikeOut':
case "StrikeOut":
return new StrikeOutAnnotation(parameters);
case 'Stamp':
case "Stamp":
return new StampAnnotation(parameters);
case 'FileAttachment':
case "FileAttachment":
return new FileAttachmentAnnotation(parameters);
default:
if (!subtype) {
warn('Annotation is missing the required /Subtype.');
warn("Annotation is missing the required /Subtype.");
} else {
warn('Unimplemented annotation type "' + subtype + '", ' +
'falling back to base annotation.');
warn(
'Unimplemented annotation type "' +
subtype +
'", ' +
"falling back to base annotation."
);
}
return new Annotation(parameters);
}
@ -148,13 +169,13 @@ class AnnotationFactory {
}
function getQuadPoints(dict, rect) {
if (!dict.has('QuadPoints')) {
if (!dict.has("QuadPoints")) {
return null;
}
// The region is described as a number of quadrilaterals.
// Each quadrilateral must consist of eight coordinates.
const quadPoints = dict.getArray('QuadPoints');
const quadPoints = dict.getArray("QuadPoints");
if (!Array.isArray(quadPoints) || quadPoints.length % 8 > 0) {
return null;
}
@ -165,7 +186,7 @@ function getQuadPoints(dict, rect) {
// quadrilateral in the order [x1, y1, x2, y2, x3, y3, x4, y4].
// Convert this to an array of objects with x and y coordinates.
quadPointsLists.push([]);
for (let j = i * 8, jj = (i * 8) + 8; j < jj; j += 2) {
for (let j = i * 8, jj = i * 8 + 8; j < jj; j += 2) {
const x = quadPoints[j];
const y = quadPoints[j + 1];
@ -174,7 +195,7 @@ function getQuadPoints(dict, rect) {
if (x < rect[0] || x > rect[2] || y < rect[1] || y > rect[3]) {
return null;
}
quadPointsLists[i].push({ x, y, });
quadPointsLists[i].push({ x, y });
}
}
return quadPointsLists;
@ -182,8 +203,10 @@ function getQuadPoints(dict, rect) {
function getTransformMatrix(rect, bbox, matrix) {
// 12.5.5: Algorithm: Appearance streams
const [minX, minY, maxX, maxY] =
Util.getAxialAlignedBoundingBox(bbox, matrix);
const [minX, minY, maxX, maxY] = Util.getAxialAlignedBoundingBox(
bbox,
matrix
);
if (minX === maxX || minY === maxY) {
// From real-life file, bbox was [0, 0, 0, 0]. In this case,
// just apply the transform for rect
@ -198,7 +221,7 @@ function getTransformMatrix(rect, bbox, matrix) {
0,
yRatio,
rect[0] - minX * xRatio,
rect[1] - minY * yRatio
rect[1] - minY * yRatio,
];
}
@ -206,11 +229,11 @@ class Annotation {
constructor(params) {
const dict = params.dict;
this.setContents(dict.get('Contents'));
this.setModificationDate(dict.get('M'));
this.setFlags(dict.get('F'));
this.setRectangle(dict.getArray('Rect'));
this.setColor(dict.getArray('C'));
this.setContents(dict.get("Contents"));
this.setModificationDate(dict.get("M"));
this.setFlags(dict.get("F"));
this.setRectangle(dict.getArray("Rect"));
this.setColor(dict.getArray("C"));
this.setBorderStyle(dict);
this.setAppearance(dict);
@ -239,18 +262,22 @@ class Annotation {
* @private
*/
_isViewable(flags) {
return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
!this._hasFlag(flags, AnnotationFlag.HIDDEN) &&
!this._hasFlag(flags, AnnotationFlag.NOVIEW);
return (
!this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
!this._hasFlag(flags, AnnotationFlag.HIDDEN) &&
!this._hasFlag(flags, AnnotationFlag.NOVIEW)
);
}
/**
* @private
*/
_isPrintable(flags) {
return this._hasFlag(flags, AnnotationFlag.PRINT) &&
!this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
!this._hasFlag(flags, AnnotationFlag.HIDDEN);
return (
this._hasFlag(flags, AnnotationFlag.PRINT) &&
!this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
!this._hasFlag(flags, AnnotationFlag.HIDDEN)
);
}
/**
@ -283,7 +310,7 @@ class Annotation {
* description of the annotation's contents
*/
setContents(contents) {
this.contents = stringToPDFString(contents || '');
this.contents = stringToPDFString(contents || "");
}
/**
@ -295,8 +322,9 @@ class Annotation {
* annotation was last modified
*/
setModificationDate(modificationDate) {
this.modificationDate = isString(modificationDate) ?
modificationDate : null;
this.modificationDate = isString(modificationDate)
? modificationDate
: null;
}
/**
@ -309,7 +337,7 @@ class Annotation {
* @see {@link shared/util.js}
*/
setFlags(flags) {
this.flags = (Number.isInteger(flags) && flags > 0) ? flags : 0;
this.flags = Number.isInteger(flags) && flags > 0 ? flags : 0;
}
/**
@ -392,32 +420,35 @@ class Annotation {
* @param {Dict} borderStyle - The border style dictionary
*/
setBorderStyle(borderStyle) {
if (typeof PDFJSDev === 'undefined' ||
PDFJSDev.test('!PRODUCTION || TESTING')) {
assert(this.rectangle, 'setRectangle must have been called previously.');
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || TESTING")
) {
assert(this.rectangle, "setRectangle must have been called previously.");
}
this.borderStyle = new AnnotationBorderStyle();
if (!isDict(borderStyle)) {
return;
}
if (borderStyle.has('BS')) {
const dict = borderStyle.get('BS');
const dictType = dict.get('Type');
if (borderStyle.has("BS")) {
const dict = borderStyle.get("BS");
const dictType = dict.get("Type");
if (!dictType || isName(dictType, 'Border')) {
this.borderStyle.setWidth(dict.get('W'), this.rectangle);
this.borderStyle.setStyle(dict.get('S'));
this.borderStyle.setDashArray(dict.getArray('D'));
if (!dictType || isName(dictType, "Border")) {
this.borderStyle.setWidth(dict.get("W"), this.rectangle);
this.borderStyle.setStyle(dict.get("S"));
this.borderStyle.setDashArray(dict.getArray("D"));
}
} else if (borderStyle.has('Border')) {
const array = borderStyle.getArray('Border');
} else if (borderStyle.has("Border")) {
const array = borderStyle.getArray("Border");
if (Array.isArray(array) && array.length >= 3) {
this.borderStyle.setHorizontalCornerRadius(array[0]);
this.borderStyle.setVerticalCornerRadius(array[1]);
this.borderStyle.setWidth(array[2], this.rectangle);
if (array.length === 4) { // Dash array available
if (array.length === 4) {
// Dash array available
this.borderStyle.setDashArray(array[3]);
}
}
@ -441,13 +472,13 @@ class Annotation {
setAppearance(dict) {
this.appearance = null;
const appearanceStates = dict.get('AP');
const appearanceStates = dict.get("AP");
if (!isDict(appearanceStates)) {
return;
}
// In case the normal appearance is a stream, then it is used directly.
const normalAppearanceState = appearanceStates.get('N');
const normalAppearanceState = appearanceStates.get("N");
if (isStream(normalAppearanceState)) {
this.appearance = normalAppearanceState;
return;
@ -458,7 +489,7 @@ class Annotation {
// In case the normal appearance is a dictionary, the `AS` entry provides
// the key of the stream in this dictionary.
const as = dict.get('AS');
const as = dict.get("AS");
if (!isName(as) || !normalAppearanceState.has(as.name)) {
return;
}
@ -466,7 +497,7 @@ class Annotation {
}
loadResources(keys) {
return this.appearance.dict.getAsync('Resources').then((resources) => {
return this.appearance.dict.getAsync("Resources").then(resources => {
if (!resources) {
return undefined;
}
@ -486,30 +517,32 @@ class Annotation {
const data = this.data;
const appearanceDict = this.appearance.dict;
const resourcesPromise = this.loadResources([
'ExtGState',
'ColorSpace',
'Pattern',
'Shading',
'XObject',
'Font',
"ExtGState",
"ColorSpace",
"Pattern",
"Shading",
"XObject",
"Font",
]);
const bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
const matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0, 0];
const bbox = appearanceDict.getArray("BBox") || [0, 0, 1, 1];
const matrix = appearanceDict.getArray("Matrix") || [1, 0, 0, 1, 0, 0];
const transform = getTransformMatrix(data.rect, bbox, matrix);
return resourcesPromise.then((resources) => {
return resourcesPromise.then(resources => {
const opList = new OperatorList();
opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
return evaluator.getOperatorList({
stream: this.appearance,
task,
resources,
operatorList: opList,
}).then(() => {
opList.addOp(OPS.endAnnotation, []);
this.appearance.reset();
return opList;
});
return evaluator
.getOperatorList({
stream: this.appearance,
task,
resources,
operatorList: opList,
})
.then(() => {
opList.addOp(OPS.endAnnotation, []);
this.appearance.reset();
return opList;
});
});
}
}
@ -535,10 +568,14 @@ class AnnotationBorderStyle {
* @param {Array} rect - The annotation `Rect` entry.
*/
setWidth(width, rect = [0, 0, 0, 0]) {
if (typeof PDFJSDev === 'undefined' ||
PDFJSDev.test('!PRODUCTION || TESTING')) {
assert(Array.isArray(rect) && rect.length === 4,
'A valid `rect` parameter must be provided.');
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || TESTING")
) {
assert(
Array.isArray(rect) && rect.length === 4,
"A valid `rect` parameter must be provided."
);
}
// Some corrupt PDF generators may provide the width as a `Name`,
@ -555,8 +592,11 @@ class AnnotationBorderStyle {
// Ignore large `width`s, since they lead to the Annotation overflowing
// the size set by the `Rect` entry thus causing the `annotationLayer`
// to render it over the surrounding document (fixes bug1552113.pdf).
if ((maxWidth > 0 && maxHeight > 0) &&
(width > maxWidth || width > maxHeight)) {
if (
maxWidth > 0 &&
maxHeight > 0 &&
(width > maxWidth || width > maxHeight)
) {
warn(`AnnotationBorderStyle.setWidth - ignoring width: ${width}`);
width = 1;
}
@ -578,23 +618,23 @@ class AnnotationBorderStyle {
return;
}
switch (style.name) {
case 'S':
case "S":
this.style = AnnotationBorderStyleType.SOLID;
break;
case 'D':
case "D":
this.style = AnnotationBorderStyleType.DASHED;
break;
case 'B':
case "B":
this.style = AnnotationBorderStyleType.BEVELED;
break;
case 'I':
case "I":
this.style = AnnotationBorderStyleType.INSET;
break;
case 'U':
case "U":
this.style = AnnotationBorderStyleType.UNDERLINE;
break;
@ -620,7 +660,7 @@ class AnnotationBorderStyle {
let isValid = true;
let allZeros = true;
for (const element of dashArray) {
const validNumber = (+element >= 0);
const validNumber = +element >= 0;
if (!validNumber) {
isValid = false;
break;
@ -671,56 +711,56 @@ class MarkupAnnotation extends Annotation {
const dict = parameters.dict;
if (dict.has('IRT')) {
const rawIRT = dict.getRaw('IRT');
if (dict.has("IRT")) {
const rawIRT = dict.getRaw("IRT");
this.data.inReplyTo = isRef(rawIRT) ? rawIRT.toString() : null;
const rt = dict.get('RT');
const rt = dict.get("RT");
this.data.replyType = isName(rt) ? rt.name : AnnotationReplyType.REPLY;
}
if (this.data.replyType === AnnotationReplyType.GROUP) {
// Subordinate annotations in a group should inherit
// the group attributes from the primary annotation.
const parent = dict.get('IRT');
const parent = dict.get("IRT");
this.data.title = stringToPDFString(parent.get('T') || '');
this.data.title = stringToPDFString(parent.get("T") || "");
this.setContents(parent.get('Contents'));
this.setContents(parent.get("Contents"));
this.data.contents = this.contents;
if (!parent.has('CreationDate')) {
if (!parent.has("CreationDate")) {
this.data.creationDate = null;
} else {
this.setCreationDate(parent.get('CreationDate'));
this.setCreationDate(parent.get("CreationDate"));
this.data.creationDate = this.creationDate;
}
if (!parent.has('M')) {
if (!parent.has("M")) {
this.data.modificationDate = null;
} else {
this.setModificationDate(parent.get('M'));
this.setModificationDate(parent.get("M"));
this.data.modificationDate = this.modificationDate;
}
this.data.hasPopup = parent.has('Popup');
this.data.hasPopup = parent.has("Popup");
if (!parent.has('C')) {
if (!parent.has("C")) {
// Fall back to the default background color.
this.data.color = null;
} else {
this.setColor(parent.getArray('C'));
this.setColor(parent.getArray("C"));
this.data.color = this.color;
}
} else {
this.data.title = stringToPDFString(dict.get('T') || '');
this.data.title = stringToPDFString(dict.get("T") || "");
this.setCreationDate(dict.get('CreationDate'));
this.setCreationDate(dict.get("CreationDate"));
this.data.creationDate = this.creationDate;
this.data.hasPopup = dict.has('Popup');
this.data.hasPopup = dict.has("Popup");
if (!dict.has('C')) {
if (!dict.has("C")) {
// Fall back to the default background color.
this.data.color = null;
}
@ -749,16 +789,19 @@ class WidgetAnnotation extends Annotation {
data.annotationType = AnnotationType.WIDGET;
data.fieldName = this._constructFieldName(dict);
data.fieldValue = getInheritableProperty({ dict, key: 'V',
getArray: true, });
data.alternativeText = stringToPDFString(dict.get('TU') || '');
data.defaultAppearance = getInheritableProperty({ dict, key: 'DA', }) || '';
const fieldType = getInheritableProperty({ dict, key: 'FT', });
data.fieldValue = getInheritableProperty({
dict,
key: "V",
getArray: true,
});
data.alternativeText = stringToPDFString(dict.get("TU") || "");
data.defaultAppearance = getInheritableProperty({ dict, key: "DA" }) || "";
const fieldType = getInheritableProperty({ dict, key: "FT" });
data.fieldType = isName(fieldType) ? fieldType.name : null;
this.fieldResources = getInheritableProperty({ dict, key: 'DR', }) ||
Dict.empty;
this.fieldResources =
getInheritableProperty({ dict, key: "DR" }) || Dict.empty;
data.fieldFlags = getInheritableProperty({ dict, key: 'Ff', });
data.fieldFlags = getInheritableProperty({ dict, key: "Ff" });
if (!Number.isInteger(data.fieldFlags) || data.fieldFlags < 0) {
data.fieldFlags = 0;
}
@ -768,7 +811,7 @@ class WidgetAnnotation extends Annotation {
// Hide signatures because we cannot validate them, and unset the fieldValue
// since it's (most likely) a `Dict` which is non-serializable and will thus
// cause errors when sending annotations to the main-thread (issue 10347).
if (data.fieldType === 'Sig') {
if (data.fieldType === "Sig") {
data.fieldValue = null;
this.setFlags(AnnotationFlag.HIDDEN);
}
@ -786,26 +829,26 @@ class WidgetAnnotation extends Annotation {
_constructFieldName(dict) {
// Both the `Parent` and `T` fields are optional. While at least one of
// them should be provided, bad PDF generators may fail to do so.
if (!dict.has('T') && !dict.has('Parent')) {
warn('Unknown field name, falling back to empty field name.');
return '';
if (!dict.has("T") && !dict.has("Parent")) {
warn("Unknown field name, falling back to empty field name.");
return "";
}
// If no parent exists, the partial and fully qualified names are equal.
if (!dict.has('Parent')) {
return stringToPDFString(dict.get('T'));
if (!dict.has("Parent")) {
return stringToPDFString(dict.get("T"));
}
// Form the fully qualified field name by appending the partial name to
// the parent's fully qualified name, separated by a period.
const fieldName = [];
if (dict.has('T')) {
fieldName.unshift(stringToPDFString(dict.get('T')));
if (dict.has("T")) {
fieldName.unshift(stringToPDFString(dict.get("T")));
}
let loopDict = dict;
while (loopDict.has('Parent')) {
loopDict = loopDict.get('Parent');
while (loopDict.has("Parent")) {
loopDict = loopDict.get("Parent");
if (!isDict(loopDict)) {
// Even though it is not allowed according to the PDF specification,
// bad PDF generators may provide a `Parent` entry that is not a
@ -813,11 +856,11 @@ class WidgetAnnotation extends Annotation {
break;
}
if (loopDict.has('T')) {
fieldName.unshift(stringToPDFString(loopDict.get('T')));
if (loopDict.has("T")) {
fieldName.unshift(stringToPDFString(loopDict.get("T")));
}
}
return fieldName.join('.');
return fieldName.join(".");
}
/**
@ -851,17 +894,17 @@ class TextWidgetAnnotation extends WidgetAnnotation {
const dict = params.dict;
// The field value is always a string.
this.data.fieldValue = stringToPDFString(this.data.fieldValue || '');
this.data.fieldValue = stringToPDFString(this.data.fieldValue || "");
// Determine the alignment of text in the field.
let alignment = getInheritableProperty({ dict, key: 'Q', });
let alignment = getInheritableProperty({ dict, key: "Q" });
if (!Number.isInteger(alignment) || alignment < 0 || alignment > 2) {
alignment = null;
}
this.data.textAlignment = alignment;
// Determine the maximum length of text in the field.
let maximumLength = getInheritableProperty({ dict, key: 'MaxLen', });
let maximumLength = getInheritableProperty({ dict, key: "MaxLen" });
if (!Number.isInteger(maximumLength) || maximumLength < 0) {
maximumLength = null;
}
@ -869,11 +912,12 @@ class TextWidgetAnnotation extends WidgetAnnotation {
// Process field flags for the display layer.
this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) &&
!this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) &&
!this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) &&
!this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) &&
this.data.maxLen !== null;
this.data.comb =
this.hasFieldFlag(AnnotationFieldFlag.COMB) &&
!this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) &&
!this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) &&
!this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) &&
this.data.maxLen !== null;
}
getOperatorList(evaluator, task, renderForms) {
@ -890,14 +934,16 @@ class TextWidgetAnnotation extends WidgetAnnotation {
}
const stream = new Stream(stringToBytes(this.data.defaultAppearance));
return evaluator.getOperatorList({
stream,
task,
resources: this.fieldResources,
operatorList,
}).then(function () {
return operatorList;
});
return evaluator
.getOperatorList({
stream,
task,
resources: this.fieldResources,
operatorList,
})
.then(function() {
return operatorList;
});
}
}
@ -905,10 +951,12 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
constructor(params) {
super(params);
this.data.checkBox = !this.hasFieldFlag(AnnotationFieldFlag.RADIO) &&
!this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
this.data.radioButton = this.hasFieldFlag(AnnotationFieldFlag.RADIO) &&
!this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
this.data.checkBox =
!this.hasFieldFlag(AnnotationFieldFlag.RADIO) &&
!this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
this.data.radioButton =
this.hasFieldFlag(AnnotationFieldFlag.RADIO) &&
!this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
this.data.pushButton = this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
if (this.data.checkBox) {
@ -918,7 +966,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
} else if (this.data.pushButton) {
this._processPushButton(params);
} else {
warn('Invalid field flags for button widget annotation');
warn("Invalid field flags for button widget annotation");
}
}
@ -927,12 +975,12 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
this.data.fieldValue = this.data.fieldValue.name;
}
const customAppearance = params.dict.get('AP');
const customAppearance = params.dict.get("AP");
if (!isDict(customAppearance)) {
return;
}
const exportValueOptionsDict = customAppearance.get('D');
const exportValueOptionsDict = customAppearance.get("D");
if (!isDict(exportValueOptionsDict)) {
return;
}
@ -943,8 +991,8 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
return;
}
this.data.exportValue = exportValues[0] === 'Off' ?
exportValues[1] : exportValues[0];
this.data.exportValue =
exportValues[0] === "Off" ? exportValues[1] : exportValues[0];
}
_processRadioButton(params) {
@ -952,25 +1000,25 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
// The parent field's `V` entry holds a `Name` object with the appearance
// state of whichever child field is currently in the "on" state.
const fieldParent = params.dict.get('Parent');
if (isDict(fieldParent) && fieldParent.has('V')) {
const fieldParentValue = fieldParent.get('V');
const fieldParent = params.dict.get("Parent");
if (isDict(fieldParent) && fieldParent.has("V")) {
const fieldParentValue = fieldParent.get("V");
if (isName(fieldParentValue)) {
this.data.fieldValue = fieldParentValue.name;
}
}
// The button's value corresponds to its appearance state.
const appearanceStates = params.dict.get('AP');
const appearanceStates = params.dict.get("AP");
if (!isDict(appearanceStates)) {
return;
}
const normalAppearanceState = appearanceStates.get('N');
const normalAppearanceState = appearanceStates.get("N");
if (!isDict(normalAppearanceState)) {
return;
}
for (const key of normalAppearanceState.getKeys()) {
if (key !== 'Off') {
if (key !== "Off") {
this.data.buttonValue = key;
break;
}
@ -978,8 +1026,8 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
}
_processPushButton(params) {
if (!params.dict.has('A')) {
warn('Push buttons without action dictionaries are not supported');
if (!params.dict.has("A")) {
warn("Push buttons without action dictionaries are not supported");
return;
}
@ -1006,7 +1054,7 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
// inherit the options from a parent annotation (issue 8094).
this.data.options = [];
const options = getInheritableProperty({ dict: params.dict, key: 'Opt', });
const options = getInheritableProperty({ dict: params.dict, key: "Opt" });
if (Array.isArray(options)) {
const xref = params.xref;
for (let i = 0, ii = options.length; i < ii; i++) {
@ -1015,8 +1063,9 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
this.data.options[i] = {
exportValue: isOptionArray ? xref.fetchIfRef(option[0]) : option,
displayValue: stringToPDFString(isOptionArray ?
xref.fetchIfRef(option[1]) : option),
displayValue: stringToPDFString(
isOptionArray ? xref.fetchIfRef(option[1]) : option
),
};
}
}
@ -1044,17 +1093,16 @@ class TextAnnotation extends MarkupAnnotation {
this.data.annotationType = AnnotationType.TEXT;
if (this.data.hasAppearance) {
this.data.name = 'NoIcon';
this.data.name = "NoIcon";
} else {
this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
this.data.name = dict.has('Name') ?
dict.get('Name').name : 'Note';
this.data.name = dict.has("Name") ? dict.get("Name").name : "Note";
}
if (dict.has('State')) {
this.data.state = dict.get('State') || null;
this.data.stateModel = dict.get('StateModel') || null;
if (dict.has("State")) {
this.data.state = dict.get("State") || null;
this.data.stateModel = dict.get("StateModel") || null;
} else {
this.data.state = null;
this.data.stateModel = null;
@ -1087,36 +1135,36 @@ class PopupAnnotation extends Annotation {
this.data.annotationType = AnnotationType.POPUP;
let parentItem = parameters.dict.get('Parent');
let parentItem = parameters.dict.get("Parent");
if (!parentItem) {
warn('Popup annotation has a missing or invalid parent annotation.');
warn("Popup annotation has a missing or invalid parent annotation.");
return;
}
const parentSubtype = parentItem.get('Subtype');
const parentSubtype = parentItem.get("Subtype");
this.data.parentType = isName(parentSubtype) ? parentSubtype.name : null;
const rawParent = parameters.dict.getRaw('Parent');
const rawParent = parameters.dict.getRaw("Parent");
this.data.parentId = isRef(rawParent) ? rawParent.toString() : null;
const rt = parentItem.get('RT');
const rt = parentItem.get("RT");
if (isName(rt, AnnotationReplyType.GROUP)) {
// Subordinate annotations in a group should inherit
// the group attributes from the primary annotation.
parentItem = parentItem.get('IRT');
parentItem = parentItem.get("IRT");
}
if (!parentItem.has('M')) {
if (!parentItem.has("M")) {
this.data.modificationDate = null;
} else {
this.setModificationDate(parentItem.get('M'));
this.setModificationDate(parentItem.get("M"));
this.data.modificationDate = this.modificationDate;
}
if (!parentItem.has('C')) {
if (!parentItem.has("C")) {
// Fall back to the default background color.
this.data.color = null;
} else {
this.setColor(parentItem.getArray('C'));
this.setColor(parentItem.getArray("C"));
this.data.color = this.color;
}
@ -1124,14 +1172,14 @@ class PopupAnnotation extends Annotation {
// that is most likely a bug. Fallback to inherit the flags from the parent
// annotation (this is consistent with the behaviour in Adobe Reader).
if (!this.viewable) {
const parentFlags = parentItem.get('F');
const parentFlags = parentItem.get("F");
if (this._isViewable(parentFlags)) {
this.setFlags(parentFlags);
}
}
this.data.title = stringToPDFString(parentItem.get('T') || '');
this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
this.data.title = stringToPDFString(parentItem.get("T") || "");
this.data.contents = stringToPDFString(parentItem.get("Contents") || "");
}
}
@ -1149,8 +1197,9 @@ class LineAnnotation extends MarkupAnnotation {
this.data.annotationType = AnnotationType.LINE;
this.data.lineCoordinates =
Util.normalizeRect(parameters.dict.getArray('L'));
this.data.lineCoordinates = Util.normalizeRect(
parameters.dict.getArray("L")
);
}
}
@ -1179,7 +1228,7 @@ class PolylineAnnotation extends MarkupAnnotation {
// The vertices array is an array of numbers representing the alternating
// horizontal and vertical coordinates, respectively, of each vertex.
// Convert this to an array of objects with x and y coordinates.
const rawVertices = parameters.dict.getArray('Vertices');
const rawVertices = parameters.dict.getArray("Vertices");
this.data.vertices = [];
for (let i = 0, ii = rawVertices.length; i < ii; i += 2) {
this.data.vertices.push({
@ -1214,7 +1263,7 @@ class InkAnnotation extends MarkupAnnotation {
this.data.annotationType = AnnotationType.INK;
const xref = parameters.xref;
const originalInkLists = parameters.dict.getArray('InkList');
const originalInkLists = parameters.dict.getArray("InkList");
this.data.inkLists = [];
for (let i = 0, ii = originalInkLists.length; i < ii; ++i) {
// The raw ink lists array contains arrays of numbers representing
@ -1296,7 +1345,7 @@ class FileAttachmentAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);
const file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
const file = new FileSpec(parameters.dict.get("FS"), parameters.xref);
this.data.annotationType = AnnotationType.FILEATTACHMENT;
this.data.file = file.serializable;