|
|
@ -24,12 +24,7 @@ import { ColorSpace } from './colorspace'; |
|
|
|
import { OperatorList } from './evaluator'; |
|
|
|
import { OperatorList } from './evaluator'; |
|
|
|
import { Stream } from './stream'; |
|
|
|
import { Stream } from './stream'; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
class AnnotationFactory { |
|
|
|
* @class |
|
|
|
|
|
|
|
* @alias AnnotationFactory |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function AnnotationFactory() {} |
|
|
|
|
|
|
|
AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ { |
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param {XRef} xref |
|
|
|
* @param {XRef} xref |
|
|
|
* @param {Object} ref |
|
|
|
* @param {Object} ref |
|
|
@ -37,19 +32,19 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ { |
|
|
|
* @param {Object} idFactory |
|
|
|
* @param {Object} idFactory |
|
|
|
* @returns {Annotation} |
|
|
|
* @returns {Annotation} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
create: function AnnotationFactory_create(xref, ref, pdfManager, idFactory) { |
|
|
|
create(xref, ref, pdfManager, idFactory) { |
|
|
|
var dict = xref.fetchIfRef(ref); |
|
|
|
let dict = xref.fetchIfRef(ref); |
|
|
|
if (!isDict(dict)) { |
|
|
|
if (!isDict(dict)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var id = isRef(ref) ? ref.toString() : 'annot_' + idFactory.createObjId(); |
|
|
|
let id = isRef(ref) ? ref.toString() : 'annot_' + idFactory.createObjId(); |
|
|
|
|
|
|
|
|
|
|
|
// Determine the annotation's subtype.
|
|
|
|
// Determine the annotation's subtype.
|
|
|
|
var subtype = dict.get('Subtype'); |
|
|
|
let subtype = dict.get('Subtype'); |
|
|
|
subtype = isName(subtype) ? subtype.name : null; |
|
|
|
subtype = isName(subtype) ? subtype.name : null; |
|
|
|
|
|
|
|
|
|
|
|
// Return the right annotation object based on the subtype and field type.
|
|
|
|
// Return the right annotation object based on the subtype and field type.
|
|
|
|
var parameters = { |
|
|
|
let parameters = { |
|
|
|
xref, |
|
|
|
xref, |
|
|
|
dict, |
|
|
|
dict, |
|
|
|
ref: isRef(ref) ? ref : null, |
|
|
|
ref: isRef(ref) ? ref : null, |
|
|
@ -66,7 +61,7 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ { |
|
|
|
return new TextAnnotation(parameters); |
|
|
|
return new TextAnnotation(parameters); |
|
|
|
|
|
|
|
|
|
|
|
case 'Widget': |
|
|
|
case 'Widget': |
|
|
|
var fieldType = Util.getInheritableProperty(dict, 'FT'); |
|
|
|
let fieldType = Util.getInheritableProperty(dict, 'FT'); |
|
|
|
fieldType = isName(fieldType) ? fieldType.name : null; |
|
|
|
fieldType = isName(fieldType) ? fieldType.name : null; |
|
|
|
|
|
|
|
|
|
|
|
switch (fieldType) { |
|
|
|
switch (fieldType) { |
|
|
@ -111,17 +106,16 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ { |
|
|
|
} |
|
|
|
} |
|
|
|
return new Annotation(parameters); |
|
|
|
return new Annotation(parameters); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var Annotation = (function AnnotationClosure() { |
|
|
|
function getTransformMatrix(rect, bbox, matrix) { |
|
|
|
// 12.5.5: Algorithm: Appearance streams
|
|
|
|
// 12.5.5: Algorithm: Appearance streams
|
|
|
|
function getTransformMatrix(rect, bbox, matrix) { |
|
|
|
let bounds = Util.getAxialAlignedBoundingBox(bbox, matrix); |
|
|
|
var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix); |
|
|
|
let minX = bounds[0]; |
|
|
|
var minX = bounds[0]; |
|
|
|
let minY = bounds[1]; |
|
|
|
var minY = bounds[1]; |
|
|
|
let maxX = bounds[2]; |
|
|
|
var maxX = bounds[2]; |
|
|
|
let maxY = bounds[3]; |
|
|
|
var maxY = bounds[3]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (minX === maxX || minY === maxY) { |
|
|
|
if (minX === maxX || minY === maxY) { |
|
|
|
// From real-life file, bbox was [0, 0, 0, 0]. In this case,
|
|
|
|
// From real-life file, bbox was [0, 0, 0, 0]. In this case,
|
|
|
@ -129,8 +123,8 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
return [1, 0, 0, 1, rect[0], rect[1]]; |
|
|
|
return [1, 0, 0, 1, rect[0], rect[1]]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var xRatio = (rect[2] - rect[0]) / (maxX - minX); |
|
|
|
let xRatio = (rect[2] - rect[0]) / (maxX - minX); |
|
|
|
var yRatio = (rect[3] - rect[1]) / (maxY - minY); |
|
|
|
let yRatio = (rect[3] - rect[1]) / (maxY - minY); |
|
|
|
return [ |
|
|
|
return [ |
|
|
|
xRatio, |
|
|
|
xRatio, |
|
|
|
0, |
|
|
|
0, |
|
|
@ -139,10 +133,11 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
rect[0] - minX * xRatio, |
|
|
|
rect[0] - minX * xRatio, |
|
|
|
rect[1] - minY * yRatio |
|
|
|
rect[1] - minY * yRatio |
|
|
|
]; |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function Annotation(params) { |
|
|
|
class Annotation { |
|
|
|
var dict = params.dict; |
|
|
|
constructor(params) { |
|
|
|
|
|
|
|
let dict = params.dict; |
|
|
|
|
|
|
|
|
|
|
|
this.setFlags(dict.get('F')); |
|
|
|
this.setFlags(dict.get('F')); |
|
|
|
this.setRectangle(dict.getArray('Rect')); |
|
|
|
this.setRectangle(dict.getArray('Rect')); |
|
|
@ -151,41 +146,41 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
this.setAppearance(dict); |
|
|
|
this.setAppearance(dict); |
|
|
|
|
|
|
|
|
|
|
|
// Expose public properties using a data object.
|
|
|
|
// Expose public properties using a data object.
|
|
|
|
this.data = {}; |
|
|
|
this.data = { |
|
|
|
this.data.id = params.id; |
|
|
|
annotationFlags: this.flags, |
|
|
|
this.data.subtype = params.subtype; |
|
|
|
borderStyle: this.borderStyle, |
|
|
|
this.data.annotationFlags = this.flags; |
|
|
|
color: this.color, |
|
|
|
this.data.rect = this.rectangle; |
|
|
|
hasAppearance: !!this.appearance, |
|
|
|
this.data.color = this.color; |
|
|
|
id: params.id, |
|
|
|
this.data.borderStyle = this.borderStyle; |
|
|
|
rect: this.rectangle, |
|
|
|
this.data.hasAppearance = !!this.appearance; |
|
|
|
subtype: params.subtype, |
|
|
|
|
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Annotation.prototype = { |
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @private |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
_hasFlag: function Annotation_hasFlag(flags, flag) { |
|
|
|
_hasFlag(flags, flag) { |
|
|
|
return !!(flags & flag); |
|
|
|
return !!(flags & flag); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @private |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
_isViewable: function Annotation_isViewable(flags) { |
|
|
|
_isViewable(flags) { |
|
|
|
return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && |
|
|
|
return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && |
|
|
|
!this._hasFlag(flags, AnnotationFlag.HIDDEN) && |
|
|
|
!this._hasFlag(flags, AnnotationFlag.HIDDEN) && |
|
|
|
!this._hasFlag(flags, AnnotationFlag.NOVIEW); |
|
|
|
!this._hasFlag(flags, AnnotationFlag.NOVIEW); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @private |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
_isPrintable: function AnnotationFlag_isPrintable(flags) { |
|
|
|
_isPrintable(flags) { |
|
|
|
return this._hasFlag(flags, AnnotationFlag.PRINT) && |
|
|
|
return this._hasFlag(flags, AnnotationFlag.PRINT) && |
|
|
|
!this._hasFlag(flags, AnnotationFlag.INVISIBLE) && |
|
|
|
!this._hasFlag(flags, AnnotationFlag.INVISIBLE) && |
|
|
|
!this._hasFlag(flags, AnnotationFlag.HIDDEN); |
|
|
|
!this._hasFlag(flags, AnnotationFlag.HIDDEN); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return {boolean} |
|
|
|
* @return {boolean} |
|
|
@ -195,7 +190,7 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return this._isViewable(this.flags); |
|
|
|
return this._isViewable(this.flags); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return {boolean} |
|
|
|
* @return {boolean} |
|
|
@ -205,7 +200,7 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
return this._isPrintable(this.flags); |
|
|
|
return this._isPrintable(this.flags); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the flags. |
|
|
|
* Set the flags. |
|
|
@ -216,9 +211,9 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
* characteristics |
|
|
|
* characteristics |
|
|
|
* @see {@link shared/util.js} |
|
|
|
* @see {@link shared/util.js} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
setFlags: function Annotation_setFlags(flags) { |
|
|
|
setFlags(flags) { |
|
|
|
this.flags = (isInt(flags) && flags > 0) ? flags : 0; |
|
|
|
this.flags = (isInt(flags) && flags > 0) ? flags : 0; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Check if a provided flag is set. |
|
|
|
* Check if a provided flag is set. |
|
|
@ -230,9 +225,9 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
* @return {boolean} |
|
|
|
* @return {boolean} |
|
|
|
* @see {@link shared/util.js} |
|
|
|
* @see {@link shared/util.js} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
hasFlag: function Annotation_hasFlag(flag) { |
|
|
|
hasFlag(flag) { |
|
|
|
return this._hasFlag(this.flags, flag); |
|
|
|
return this._hasFlag(this.flags, flag); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the rectangle. |
|
|
|
* Set the rectangle. |
|
|
@ -241,13 +236,13 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
* @memberof Annotation |
|
|
|
* @memberof Annotation |
|
|
|
* @param {Array} rectangle - The rectangle array with exactly four entries |
|
|
|
* @param {Array} rectangle - The rectangle array with exactly four entries |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
setRectangle: function Annotation_setRectangle(rectangle) { |
|
|
|
setRectangle(rectangle) { |
|
|
|
if (isArray(rectangle) && rectangle.length === 4) { |
|
|
|
if (isArray(rectangle) && rectangle.length === 4) { |
|
|
|
this.rectangle = Util.normalizeRect(rectangle); |
|
|
|
this.rectangle = Util.normalizeRect(rectangle); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.rectangle = [0, 0, 0, 0]; |
|
|
|
this.rectangle = [0, 0, 0, 0]; |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the color and take care of color space conversion. |
|
|
|
* Set the color and take care of color space conversion. |
|
|
@ -258,8 +253,8 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
* (transparent), 1 (grayscale), 3 (RGB) or |
|
|
|
* (transparent), 1 (grayscale), 3 (RGB) or |
|
|
|
* 4 (CMYK) elements |
|
|
|
* 4 (CMYK) elements |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
setColor: function Annotation_setColor(color) { |
|
|
|
setColor(color) { |
|
|
|
var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
|
|
|
|
let rgbColor = new Uint8Array(3); // Black in RGB color space (default)
|
|
|
|
if (!isArray(color)) { |
|
|
|
if (!isArray(color)) { |
|
|
|
this.color = rgbColor; |
|
|
|
this.color = rgbColor; |
|
|
|
return; |
|
|
|
return; |
|
|
@ -289,7 +284,7 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
this.color = rgbColor; |
|
|
|
this.color = rgbColor; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the border style (as AnnotationBorderStyle object). |
|
|
|
* Set the border style (as AnnotationBorderStyle object). |
|
|
@ -298,14 +293,14 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
* @memberof Annotation |
|
|
|
* @memberof Annotation |
|
|
|
* @param {Dict} borderStyle - The border style dictionary |
|
|
|
* @param {Dict} borderStyle - The border style dictionary |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
setBorderStyle: function Annotation_setBorderStyle(borderStyle) { |
|
|
|
setBorderStyle(borderStyle) { |
|
|
|
this.borderStyle = new AnnotationBorderStyle(); |
|
|
|
this.borderStyle = new AnnotationBorderStyle(); |
|
|
|
if (!isDict(borderStyle)) { |
|
|
|
if (!isDict(borderStyle)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (borderStyle.has('BS')) { |
|
|
|
if (borderStyle.has('BS')) { |
|
|
|
var dict = borderStyle.get('BS'); |
|
|
|
let dict = borderStyle.get('BS'); |
|
|
|
var dictType = dict.get('Type'); |
|
|
|
let dictType = dict.get('Type'); |
|
|
|
|
|
|
|
|
|
|
|
if (!dictType || isName(dictType, 'Border')) { |
|
|
|
if (!dictType || isName(dictType, 'Border')) { |
|
|
|
this.borderStyle.setWidth(dict.get('W')); |
|
|
|
this.borderStyle.setWidth(dict.get('W')); |
|
|
@ -313,7 +308,7 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
this.borderStyle.setDashArray(dict.getArray('D')); |
|
|
|
this.borderStyle.setDashArray(dict.getArray('D')); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (borderStyle.has('Border')) { |
|
|
|
} else if (borderStyle.has('Border')) { |
|
|
|
var array = borderStyle.getArray('Border'); |
|
|
|
let array = borderStyle.getArray('Border'); |
|
|
|
if (isArray(array) && array.length >= 3) { |
|
|
|
if (isArray(array) && array.length >= 3) { |
|
|
|
this.borderStyle.setHorizontalCornerRadius(array[0]); |
|
|
|
this.borderStyle.setHorizontalCornerRadius(array[0]); |
|
|
|
this.borderStyle.setVerticalCornerRadius(array[1]); |
|
|
|
this.borderStyle.setVerticalCornerRadius(array[1]); |
|
|
@ -331,7 +326,7 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
// See also https://github.com/mozilla/pdf.js/issues/6179.
|
|
|
|
// See also https://github.com/mozilla/pdf.js/issues/6179.
|
|
|
|
this.borderStyle.setWidth(0); |
|
|
|
this.borderStyle.setWidth(0); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the (normal) appearance. |
|
|
|
* Set the (normal) appearance. |
|
|
@ -340,16 +335,16 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
* @memberof Annotation |
|
|
|
* @memberof Annotation |
|
|
|
* @param {Dict} dict - The annotation's data dictionary |
|
|
|
* @param {Dict} dict - The annotation's data dictionary |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
setAppearance: function Annotation_setAppearance(dict) { |
|
|
|
setAppearance(dict) { |
|
|
|
this.appearance = null; |
|
|
|
this.appearance = null; |
|
|
|
|
|
|
|
|
|
|
|
var appearanceStates = dict.get('AP'); |
|
|
|
let appearanceStates = dict.get('AP'); |
|
|
|
if (!isDict(appearanceStates)) { |
|
|
|
if (!isDict(appearanceStates)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// In case the normal appearance is a stream, then it is used directly.
|
|
|
|
// In case the normal appearance is a stream, then it is used directly.
|
|
|
|
var normalAppearanceState = appearanceStates.get('N'); |
|
|
|
let normalAppearanceState = appearanceStates.get('N'); |
|
|
|
if (isStream(normalAppearanceState)) { |
|
|
|
if (isStream(normalAppearanceState)) { |
|
|
|
this.appearance = normalAppearanceState; |
|
|
|
this.appearance = normalAppearanceState; |
|
|
|
return; |
|
|
|
return; |
|
|
@ -360,12 +355,12 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
|
|
|
|
|
|
|
|
// In case the normal appearance is a dictionary, the `AS` entry provides
|
|
|
|
// In case the normal appearance is a dictionary, the `AS` entry provides
|
|
|
|
// the key of the stream in this dictionary.
|
|
|
|
// the key of the stream in this dictionary.
|
|
|
|
var as = dict.get('AS'); |
|
|
|
let as = dict.get('AS'); |
|
|
|
if (!isName(as) || !normalAppearanceState.has(as.name)) { |
|
|
|
if (!isName(as) || !normalAppearanceState.has(as.name)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
this.appearance = normalAppearanceState.get(as.name); |
|
|
|
this.appearance = normalAppearanceState.get(as.name); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Prepare the annotation for working with a popup in the display layer. |
|
|
|
* Prepare the annotation for working with a popup in the display layer. |
|
|
@ -374,7 +369,7 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
* @memberof Annotation |
|
|
|
* @memberof Annotation |
|
|
|
* @param {Dict} dict - The annotation's data dictionary |
|
|
|
* @param {Dict} dict - The annotation's data dictionary |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
_preparePopup: function Annotation_preparePopup(dict) { |
|
|
|
_preparePopup(dict) { |
|
|
|
if (!dict.has('C')) { |
|
|
|
if (!dict.has('C')) { |
|
|
|
// Fall back to the default background color.
|
|
|
|
// Fall back to the default background color.
|
|
|
|
this.data.color = null; |
|
|
|
this.data.color = null; |
|
|
@ -383,9 +378,9 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
this.data.hasPopup = dict.has('Popup'); |
|
|
|
this.data.hasPopup = dict.has('Popup'); |
|
|
|
this.data.title = stringToPDFString(dict.get('T') || ''); |
|
|
|
this.data.title = stringToPDFString(dict.get('T') || ''); |
|
|
|
this.data.contents = stringToPDFString(dict.get('Contents') || ''); |
|
|
|
this.data.contents = stringToPDFString(dict.get('Contents') || ''); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
loadResources: function Annotation_loadResources(keys) { |
|
|
|
loadResources(keys) { |
|
|
|
return this.appearance.dict.getAsync('Resources').then((resources) => { |
|
|
|
return this.appearance.dict.getAsync('Resources').then((resources) => { |
|
|
|
if (!resources) { |
|
|
|
if (!resources) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -396,32 +391,31 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
return resources; |
|
|
|
return resources; |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getOperatorList: function Annotation_getOperatorList(evaluator, task, |
|
|
|
getOperatorList(evaluator, task, renderForms) { |
|
|
|
renderForms) { |
|
|
|
|
|
|
|
if (!this.appearance) { |
|
|
|
if (!this.appearance) { |
|
|
|
return Promise.resolve(new OperatorList()); |
|
|
|
return Promise.resolve(new OperatorList()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var data = this.data; |
|
|
|
let data = this.data; |
|
|
|
var appearanceDict = this.appearance.dict; |
|
|
|
let appearanceDict = this.appearance.dict; |
|
|
|
var resourcesPromise = this.loadResources([ |
|
|
|
let resourcesPromise = this.loadResources([ |
|
|
|
'ExtGState', |
|
|
|
'ExtGState', |
|
|
|
'ColorSpace', |
|
|
|
'ColorSpace', |
|
|
|
'Pattern', |
|
|
|
'Pattern', |
|
|
|
'Shading', |
|
|
|
'Shading', |
|
|
|
'XObject', |
|
|
|
'XObject', |
|
|
|
'Font' |
|
|
|
'Font', |
|
|
|
// ProcSet
|
|
|
|
// ProcSet
|
|
|
|
// Properties
|
|
|
|
// Properties
|
|
|
|
]); |
|
|
|
]); |
|
|
|
var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1]; |
|
|
|
let bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1]; |
|
|
|
var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0, 0]; |
|
|
|
let matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0, 0]; |
|
|
|
var transform = getTransformMatrix(data.rect, bbox, matrix); |
|
|
|
let transform = getTransformMatrix(data.rect, bbox, matrix); |
|
|
|
|
|
|
|
|
|
|
|
return resourcesPromise.then((resources) => { |
|
|
|
return resourcesPromise.then((resources) => { |
|
|
|
var opList = new OperatorList(); |
|
|
|
let opList = new OperatorList(); |
|
|
|
opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]); |
|
|
|
opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]); |
|
|
|
return evaluator.getOperatorList({ |
|
|
|
return evaluator.getOperatorList({ |
|
|
|
stream: this.appearance, |
|
|
|
stream: this.appearance, |
|
|
@ -434,23 +428,14 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
return opList; |
|
|
|
return opList; |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return Annotation; |
|
|
|
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Contains all data regarding an annotation's border style. |
|
|
|
* Contains all data regarding an annotation's border style. |
|
|
|
* |
|
|
|
|
|
|
|
* @class |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() { |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @constructor |
|
|
|
|
|
|
|
* @private |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function AnnotationBorderStyle() { |
|
|
|
class AnnotationBorderStyle { |
|
|
|
|
|
|
|
constructor() { |
|
|
|
this.width = 1; |
|
|
|
this.width = 1; |
|
|
|
this.style = AnnotationBorderStyleType.SOLID; |
|
|
|
this.style = AnnotationBorderStyleType.SOLID; |
|
|
|
this.dashArray = [3]; |
|
|
|
this.dashArray = [3]; |
|
|
@ -458,7 +443,6 @@ var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() { |
|
|
|
this.verticalCornerRadius = 0; |
|
|
|
this.verticalCornerRadius = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
AnnotationBorderStyle.prototype = { |
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the width. |
|
|
|
* Set the width. |
|
|
|
* |
|
|
|
* |
|
|
@ -466,11 +450,11 @@ var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() { |
|
|
|
* @memberof AnnotationBorderStyle |
|
|
|
* @memberof AnnotationBorderStyle |
|
|
|
* @param {integer} width - The width |
|
|
|
* @param {integer} width - The width |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
setWidth: function AnnotationBorderStyle_setWidth(width) { |
|
|
|
setWidth(width) { |
|
|
|
if (width === (width | 0)) { |
|
|
|
if (width === (width | 0)) { |
|
|
|
this.width = width; |
|
|
|
this.width = width; |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the style. |
|
|
|
* Set the style. |
|
|
@ -480,7 +464,7 @@ var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() { |
|
|
|
* @param {Object} style - The style object |
|
|
|
* @param {Object} style - The style object |
|
|
|
* @see {@link shared/util.js} |
|
|
|
* @see {@link shared/util.js} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
setStyle: function AnnotationBorderStyle_setStyle(style) { |
|
|
|
setStyle(style) { |
|
|
|
if (!style) { |
|
|
|
if (!style) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -508,7 +492,7 @@ var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() { |
|
|
|
default: |
|
|
|
default: |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the dash array. |
|
|
|
* Set the dash array. |
|
|
@ -517,18 +501,18 @@ var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() { |
|
|
|
* @memberof AnnotationBorderStyle |
|
|
|
* @memberof AnnotationBorderStyle |
|
|
|
* @param {Array} dashArray - The dash array with at least one element |
|
|
|
* @param {Array} dashArray - The dash array with at least one element |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) { |
|
|
|
setDashArray(dashArray) { |
|
|
|
// We validate the dash array, but we do not use it because CSS does not
|
|
|
|
// We validate the dash array, but we do not use it because CSS does not
|
|
|
|
// allow us to change spacing of dashes. For more information, visit
|
|
|
|
// allow us to change spacing of dashes. For more information, visit
|
|
|
|
// http://www.w3.org/TR/css3-background/#the-border-style.
|
|
|
|
// http://www.w3.org/TR/css3-background/#the-border-style.
|
|
|
|
if (isArray(dashArray) && dashArray.length > 0) { |
|
|
|
if (isArray(dashArray) && dashArray.length > 0) { |
|
|
|
// According to the PDF specification: the elements in a dashArray
|
|
|
|
// According to the PDF specification: the elements in `dashArray`
|
|
|
|
// shall be numbers that are nonnegative and not all equal to zero.
|
|
|
|
// shall be numbers that are nonnegative and not all equal to zero.
|
|
|
|
var isValid = true; |
|
|
|
let isValid = true; |
|
|
|
var allZeros = true; |
|
|
|
let allZeros = true; |
|
|
|
for (var i = 0, len = dashArray.length; i < len; i++) { |
|
|
|
for (let i = 0, len = dashArray.length; i < len; i++) { |
|
|
|
var element = dashArray[i]; |
|
|
|
let element = dashArray[i]; |
|
|
|
var validNumber = (+element >= 0); |
|
|
|
let validNumber = (+element >= 0); |
|
|
|
if (!validNumber) { |
|
|
|
if (!validNumber) { |
|
|
|
isValid = false; |
|
|
|
isValid = false; |
|
|
|
break; |
|
|
|
break; |
|
|
@ -544,7 +528,7 @@ var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() { |
|
|
|
} else if (dashArray) { |
|
|
|
} else if (dashArray) { |
|
|
|
this.width = 0; // Adobe behavior when the array is invalid.
|
|
|
|
this.width = 0; // Adobe behavior when the array is invalid.
|
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the horizontal corner radius (from a Border dictionary). |
|
|
|
* Set the horizontal corner radius (from a Border dictionary). |
|
|
@ -553,12 +537,11 @@ var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() { |
|
|
|
* @memberof AnnotationBorderStyle |
|
|
|
* @memberof AnnotationBorderStyle |
|
|
|
* @param {integer} radius - The horizontal corner radius |
|
|
|
* @param {integer} radius - The horizontal corner radius |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
setHorizontalCornerRadius: |
|
|
|
setHorizontalCornerRadius(radius) { |
|
|
|
function AnnotationBorderStyle_setHorizontalCornerRadius(radius) { |
|
|
|
|
|
|
|
if (radius === (radius | 0)) { |
|
|
|
if (radius === (radius | 0)) { |
|
|
|
this.horizontalCornerRadius = radius; |
|
|
|
this.horizontalCornerRadius = radius; |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the vertical corner radius (from a Border dictionary). |
|
|
|
* Set the vertical corner radius (from a Border dictionary). |
|
|
@ -567,23 +550,19 @@ var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() { |
|
|
|
* @memberof AnnotationBorderStyle |
|
|
|
* @memberof AnnotationBorderStyle |
|
|
|
* @param {integer} radius - The vertical corner radius |
|
|
|
* @param {integer} radius - The vertical corner radius |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
setVerticalCornerRadius: |
|
|
|
setVerticalCornerRadius(radius) { |
|
|
|
function AnnotationBorderStyle_setVerticalCornerRadius(radius) { |
|
|
|
|
|
|
|
if (radius === (radius | 0)) { |
|
|
|
if (radius === (radius | 0)) { |
|
|
|
this.verticalCornerRadius = radius; |
|
|
|
this.verticalCornerRadius = radius; |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return AnnotationBorderStyle; |
|
|
|
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var WidgetAnnotation = (function WidgetAnnotationClosure() { |
|
|
|
class WidgetAnnotation extends Annotation { |
|
|
|
function WidgetAnnotation(params) { |
|
|
|
constructor(params) { |
|
|
|
Annotation.call(this, params); |
|
|
|
super(params); |
|
|
|
|
|
|
|
|
|
|
|
var dict = params.dict; |
|
|
|
let dict = params.dict; |
|
|
|
var data = this.data; |
|
|
|
let data = this.data; |
|
|
|
|
|
|
|
|
|
|
|
data.annotationType = AnnotationType.WIDGET; |
|
|
|
data.annotationType = AnnotationType.WIDGET; |
|
|
|
data.fieldName = this._constructFieldName(dict); |
|
|
|
data.fieldName = this._constructFieldName(dict); |
|
|
@ -591,7 +570,7 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() { |
|
|
|
/* getArray = */ true); |
|
|
|
/* getArray = */ true); |
|
|
|
data.alternativeText = stringToPDFString(dict.get('TU') || ''); |
|
|
|
data.alternativeText = stringToPDFString(dict.get('TU') || ''); |
|
|
|
data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || ''; |
|
|
|
data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || ''; |
|
|
|
var fieldType = Util.getInheritableProperty(dict, 'FT'); |
|
|
|
let fieldType = Util.getInheritableProperty(dict, 'FT'); |
|
|
|
data.fieldType = isName(fieldType) ? fieldType.name : null; |
|
|
|
data.fieldType = isName(fieldType) ? fieldType.name : null; |
|
|
|
this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty; |
|
|
|
this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty; |
|
|
|
|
|
|
|
|
|
|
@ -608,7 +587,6 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Util.inherit(WidgetAnnotation, Annotation, { |
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Construct the (fully qualified) field name from the (partial) field |
|
|
|
* Construct the (fully qualified) field name from the (partial) field |
|
|
|
* names of the field and its ancestors. |
|
|
|
* names of the field and its ancestors. |
|
|
@ -618,7 +596,7 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() { |
|
|
|
* @param {Dict} dict - Complete widget annotation dictionary |
|
|
|
* @param {Dict} dict - Complete widget annotation dictionary |
|
|
|
* @return {string} |
|
|
|
* @return {string} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
_constructFieldName: function WidgetAnnotation_constructFieldName(dict) { |
|
|
|
_constructFieldName(dict) { |
|
|
|
// Both the `Parent` and `T` fields are optional. While at least one of
|
|
|
|
// 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.
|
|
|
|
// them should be provided, bad PDF generators may fail to do so.
|
|
|
|
if (!dict.has('T') && !dict.has('Parent')) { |
|
|
|
if (!dict.has('T') && !dict.has('Parent')) { |
|
|
@ -633,12 +611,12 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() { |
|
|
|
|
|
|
|
|
|
|
|
// Form the fully qualified field name by appending the partial name to
|
|
|
|
// Form the fully qualified field name by appending the partial name to
|
|
|
|
// the parent's fully qualified name, separated by a period.
|
|
|
|
// the parent's fully qualified name, separated by a period.
|
|
|
|
var fieldName = []; |
|
|
|
let fieldName = []; |
|
|
|
if (dict.has('T')) { |
|
|
|
if (dict.has('T')) { |
|
|
|
fieldName.unshift(stringToPDFString(dict.get('T'))); |
|
|
|
fieldName.unshift(stringToPDFString(dict.get('T'))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var loopDict = dict; |
|
|
|
let loopDict = dict; |
|
|
|
while (loopDict.has('Parent')) { |
|
|
|
while (loopDict.has('Parent')) { |
|
|
|
loopDict = loopDict.get('Parent'); |
|
|
|
loopDict = loopDict.get('Parent'); |
|
|
|
if (!isDict(loopDict)) { |
|
|
|
if (!isDict(loopDict)) { |
|
|
@ -653,7 +631,7 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return fieldName.join('.'); |
|
|
|
return fieldName.join('.'); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Check if a provided field flag is set. |
|
|
|
* Check if a provided field flag is set. |
|
|
@ -665,30 +643,27 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() { |
|
|
|
* @return {boolean} |
|
|
|
* @return {boolean} |
|
|
|
* @see {@link shared/util.js} |
|
|
|
* @see {@link shared/util.js} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) { |
|
|
|
hasFieldFlag(flag) { |
|
|
|
return !!(this.data.fieldFlags & flag); |
|
|
|
return !!(this.data.fieldFlags & flag); |
|
|
|
}, |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return WidgetAnnotation; |
|
|
|
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() { |
|
|
|
class TextWidgetAnnotation extends WidgetAnnotation { |
|
|
|
function TextWidgetAnnotation(params) { |
|
|
|
constructor(params) { |
|
|
|
WidgetAnnotation.call(this, params); |
|
|
|
super(params); |
|
|
|
|
|
|
|
|
|
|
|
// The field value is always a string.
|
|
|
|
// 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.
|
|
|
|
// Determine the alignment of text in the field.
|
|
|
|
var alignment = Util.getInheritableProperty(params.dict, 'Q'); |
|
|
|
let alignment = Util.getInheritableProperty(params.dict, 'Q'); |
|
|
|
if (!isInt(alignment) || alignment < 0 || alignment > 2) { |
|
|
|
if (!isInt(alignment) || alignment < 0 || alignment > 2) { |
|
|
|
alignment = null; |
|
|
|
alignment = null; |
|
|
|
} |
|
|
|
} |
|
|
|
this.data.textAlignment = alignment; |
|
|
|
this.data.textAlignment = alignment; |
|
|
|
|
|
|
|
|
|
|
|
// Determine the maximum length of text in the field.
|
|
|
|
// Determine the maximum length of text in the field.
|
|
|
|
var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen'); |
|
|
|
let maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen'); |
|
|
|
if (!isInt(maximumLength) || maximumLength < 0) { |
|
|
|
if (!isInt(maximumLength) || maximumLength < 0) { |
|
|
|
maximumLength = null; |
|
|
|
maximumLength = null; |
|
|
|
} |
|
|
|
} |
|
|
@ -703,11 +678,8 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() { |
|
|
|
this.data.maxLen !== null; |
|
|
|
this.data.maxLen !== null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, { |
|
|
|
getOperatorList(evaluator, task, renderForms) { |
|
|
|
getOperatorList: |
|
|
|
let operatorList = new OperatorList(); |
|
|
|
function TextWidgetAnnotation_getOperatorList(evaluator, task, |
|
|
|
|
|
|
|
renderForms) { |
|
|
|
|
|
|
|
var operatorList = new OperatorList(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Do not render form elements on the canvas when interactive forms are
|
|
|
|
// Do not render form elements on the canvas when interactive forms are
|
|
|
|
// enabled. The display layer is responsible for rendering them instead.
|
|
|
|
// enabled. The display layer is responsible for rendering them instead.
|
|
|
@ -726,7 +698,7 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() { |
|
|
|
return Promise.resolve(operatorList); |
|
|
|
return Promise.resolve(operatorList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var stream = new Stream(stringToBytes(this.data.defaultAppearance)); |
|
|
|
let stream = new Stream(stringToBytes(this.data.defaultAppearance)); |
|
|
|
return evaluator.getOperatorList({ |
|
|
|
return evaluator.getOperatorList({ |
|
|
|
stream, |
|
|
|
stream, |
|
|
|
task, |
|
|
|
task, |
|
|
@ -735,15 +707,12 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() { |
|
|
|
}).then(function () { |
|
|
|
}).then(function () { |
|
|
|
return operatorList; |
|
|
|
return operatorList; |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return TextWidgetAnnotation; |
|
|
|
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ButtonWidgetAnnotation = (function ButtonWidgetAnnotationClosure() { |
|
|
|
class ButtonWidgetAnnotation extends WidgetAnnotation { |
|
|
|
function ButtonWidgetAnnotation(params) { |
|
|
|
constructor(params) { |
|
|
|
WidgetAnnotation.call(this, params); |
|
|
|
super(params); |
|
|
|
|
|
|
|
|
|
|
|
this.data.checkBox = !this.hasFieldFlag(AnnotationFieldFlag.RADIO) && |
|
|
|
this.data.checkBox = !this.hasFieldFlag(AnnotationFieldFlag.RADIO) && |
|
|
|
!this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON); |
|
|
|
!this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON); |
|
|
@ -761,25 +730,25 @@ var ButtonWidgetAnnotation = (function ButtonWidgetAnnotationClosure() { |
|
|
|
|
|
|
|
|
|
|
|
// The parent field's `V` entry holds a `Name` object with the appearance
|
|
|
|
// The parent field's `V` entry holds a `Name` object with the appearance
|
|
|
|
// state of whichever child field is currently in the "on" state.
|
|
|
|
// state of whichever child field is currently in the "on" state.
|
|
|
|
var fieldParent = params.dict.get('Parent'); |
|
|
|
let fieldParent = params.dict.get('Parent'); |
|
|
|
if (isDict(fieldParent) && fieldParent.has('V')) { |
|
|
|
if (isDict(fieldParent) && fieldParent.has('V')) { |
|
|
|
var fieldParentValue = fieldParent.get('V'); |
|
|
|
let fieldParentValue = fieldParent.get('V'); |
|
|
|
if (isName(fieldParentValue)) { |
|
|
|
if (isName(fieldParentValue)) { |
|
|
|
this.data.fieldValue = fieldParentValue.name; |
|
|
|
this.data.fieldValue = fieldParentValue.name; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// The button's value corresponds to its appearance state.
|
|
|
|
// The button's value corresponds to its appearance state.
|
|
|
|
var appearanceStates = params.dict.get('AP'); |
|
|
|
let appearanceStates = params.dict.get('AP'); |
|
|
|
if (!isDict(appearanceStates)) { |
|
|
|
if (!isDict(appearanceStates)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var normalAppearanceState = appearanceStates.get('N'); |
|
|
|
let normalAppearanceState = appearanceStates.get('N'); |
|
|
|
if (!isDict(normalAppearanceState)) { |
|
|
|
if (!isDict(normalAppearanceState)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var keys = normalAppearanceState.getKeys(); |
|
|
|
let keys = normalAppearanceState.getKeys(); |
|
|
|
for (var i = 0, ii = keys.length; i < ii; i++) { |
|
|
|
for (let i = 0, ii = keys.length; i < ii; i++) { |
|
|
|
if (keys[i] !== 'Off') { |
|
|
|
if (keys[i] !== 'Off') { |
|
|
|
this.data.buttonValue = keys[i]; |
|
|
|
this.data.buttonValue = keys[i]; |
|
|
|
break; |
|
|
|
break; |
|
|
@ -788,11 +757,8 @@ var ButtonWidgetAnnotation = (function ButtonWidgetAnnotationClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Util.inherit(ButtonWidgetAnnotation, WidgetAnnotation, { |
|
|
|
getOperatorList(evaluator, task, renderForms) { |
|
|
|
getOperatorList: |
|
|
|
let operatorList = new OperatorList(); |
|
|
|
function ButtonWidgetAnnotation_getOperatorList(evaluator, task, |
|
|
|
|
|
|
|
renderForms) { |
|
|
|
|
|
|
|
var operatorList = new OperatorList(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Do not render form elements on the canvas when interactive forms are
|
|
|
|
// Do not render form elements on the canvas when interactive forms are
|
|
|
|
// enabled. The display layer is responsible for rendering them instead.
|
|
|
|
// enabled. The display layer is responsible for rendering them instead.
|
|
|
@ -805,15 +771,12 @@ var ButtonWidgetAnnotation = (function ButtonWidgetAnnotationClosure() { |
|
|
|
renderForms); |
|
|
|
renderForms); |
|
|
|
} |
|
|
|
} |
|
|
|
return Promise.resolve(operatorList); |
|
|
|
return Promise.resolve(operatorList); |
|
|
|
}, |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ButtonWidgetAnnotation; |
|
|
|
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ChoiceWidgetAnnotation = (function ChoiceWidgetAnnotationClosure() { |
|
|
|
class ChoiceWidgetAnnotation extends WidgetAnnotation { |
|
|
|
function ChoiceWidgetAnnotation(params) { |
|
|
|
constructor(params) { |
|
|
|
WidgetAnnotation.call(this, params); |
|
|
|
super(params); |
|
|
|
|
|
|
|
|
|
|
|
// Determine the options. The options array may consist of strings or
|
|
|
|
// Determine the options. The options array may consist of strings or
|
|
|
|
// arrays. If the array consists of arrays, then the first element of
|
|
|
|
// arrays. If the array consists of arrays, then the first element of
|
|
|
@ -826,12 +789,12 @@ var ChoiceWidgetAnnotation = (function ChoiceWidgetAnnotationClosure() { |
|
|
|
// inherit the options from a parent annotation (issue 8094).
|
|
|
|
// inherit the options from a parent annotation (issue 8094).
|
|
|
|
this.data.options = []; |
|
|
|
this.data.options = []; |
|
|
|
|
|
|
|
|
|
|
|
var options = Util.getInheritableProperty(params.dict, 'Opt'); |
|
|
|
let options = Util.getInheritableProperty(params.dict, 'Opt'); |
|
|
|
if (isArray(options)) { |
|
|
|
if (isArray(options)) { |
|
|
|
var xref = params.xref; |
|
|
|
let xref = params.xref; |
|
|
|
for (var i = 0, ii = options.length; i < ii; i++) { |
|
|
|
for (let i = 0, ii = options.length; i < ii; i++) { |
|
|
|
var option = xref.fetchIfRef(options[i]); |
|
|
|
let option = xref.fetchIfRef(options[i]); |
|
|
|
var isOptionArray = isArray(option); |
|
|
|
let isOptionArray = isArray(option); |
|
|
|
|
|
|
|
|
|
|
|
this.data.options[i] = { |
|
|
|
this.data.options[i] = { |
|
|
|
exportValue: isOptionArray ? xref.fetchIfRef(option[0]) : option, |
|
|
|
exportValue: isOptionArray ? xref.fetchIfRef(option[0]) : option, |
|
|
@ -852,11 +815,8 @@ var ChoiceWidgetAnnotation = (function ChoiceWidgetAnnotationClosure() { |
|
|
|
this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT); |
|
|
|
this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Util.inherit(ChoiceWidgetAnnotation, WidgetAnnotation, { |
|
|
|
getOperatorList(evaluator, task, renderForms) { |
|
|
|
getOperatorList: |
|
|
|
let operatorList = new OperatorList(); |
|
|
|
function ChoiceWidgetAnnotation_getOperatorList(evaluator, task, |
|
|
|
|
|
|
|
renderForms) { |
|
|
|
|
|
|
|
var operatorList = new OperatorList(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Do not render form elements on the canvas when interactive forms are
|
|
|
|
// Do not render form elements on the canvas when interactive forms are
|
|
|
|
// enabled. The display layer is responsible for rendering them instead.
|
|
|
|
// enabled. The display layer is responsible for rendering them instead.
|
|
|
@ -866,17 +826,14 @@ var ChoiceWidgetAnnotation = (function ChoiceWidgetAnnotationClosure() { |
|
|
|
|
|
|
|
|
|
|
|
return Annotation.prototype.getOperatorList.call(this, evaluator, task, |
|
|
|
return Annotation.prototype.getOperatorList.call(this, evaluator, task, |
|
|
|
renderForms); |
|
|
|
renderForms); |
|
|
|
}, |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ChoiceWidgetAnnotation; |
|
|
|
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var TextAnnotation = (function TextAnnotationClosure() { |
|
|
|
class TextAnnotation extends Annotation { |
|
|
|
var DEFAULT_ICON_SIZE = 22; // px
|
|
|
|
constructor(parameters) { |
|
|
|
|
|
|
|
const DEFAULT_ICON_SIZE = 22; // px
|
|
|
|
|
|
|
|
|
|
|
|
function TextAnnotation(parameters) { |
|
|
|
super(parameters); |
|
|
|
Annotation.call(this, parameters); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.data.annotationType = AnnotationType.TEXT; |
|
|
|
this.data.annotationType = AnnotationType.TEXT; |
|
|
|
|
|
|
|
|
|
|
@ -890,45 +847,36 @@ var TextAnnotation = (function TextAnnotationClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
this._preparePopup(parameters.dict); |
|
|
|
this._preparePopup(parameters.dict); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Util.inherit(TextAnnotation, Annotation, {}); |
|
|
|
class LinkAnnotation extends Annotation { |
|
|
|
|
|
|
|
constructor(params) { |
|
|
|
return TextAnnotation; |
|
|
|
super(params); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var LinkAnnotation = (function LinkAnnotationClosure() { |
|
|
|
|
|
|
|
function LinkAnnotation(params) { |
|
|
|
|
|
|
|
Annotation.call(this, params); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var data = this.data; |
|
|
|
this.data.annotationType = AnnotationType.LINK; |
|
|
|
data.annotationType = AnnotationType.LINK; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Catalog.parseDestDictionary({ |
|
|
|
Catalog.parseDestDictionary({ |
|
|
|
destDict: params.dict, |
|
|
|
destDict: params.dict, |
|
|
|
resultObj: data, |
|
|
|
resultObj: this.data, |
|
|
|
docBaseUrl: params.pdfManager.docBaseUrl, |
|
|
|
docBaseUrl: params.pdfManager.docBaseUrl, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Util.inherit(LinkAnnotation, Annotation, {}); |
|
|
|
class PopupAnnotation extends Annotation { |
|
|
|
|
|
|
|
constructor(parameters) { |
|
|
|
return LinkAnnotation; |
|
|
|
super(parameters); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var PopupAnnotation = (function PopupAnnotationClosure() { |
|
|
|
|
|
|
|
function PopupAnnotation(parameters) { |
|
|
|
|
|
|
|
Annotation.call(this, parameters); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.data.annotationType = AnnotationType.POPUP; |
|
|
|
this.data.annotationType = AnnotationType.POPUP; |
|
|
|
|
|
|
|
|
|
|
|
var dict = parameters.dict; |
|
|
|
let dict = parameters.dict; |
|
|
|
var parentItem = dict.get('Parent'); |
|
|
|
let parentItem = dict.get('Parent'); |
|
|
|
if (!parentItem) { |
|
|
|
if (!parentItem) { |
|
|
|
warn('Popup annotation has a missing or invalid parent annotation.'); |
|
|
|
warn('Popup annotation has a missing or invalid parent annotation.'); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var parentSubtype = parentItem.get('Subtype'); |
|
|
|
let parentSubtype = parentItem.get('Subtype'); |
|
|
|
this.data.parentType = isName(parentSubtype) ? parentSubtype.name : null; |
|
|
|
this.data.parentType = isName(parentSubtype) ? parentSubtype.name : null; |
|
|
|
this.data.parentId = dict.getRaw('Parent').toString(); |
|
|
|
this.data.parentId = dict.getRaw('Parent').toString(); |
|
|
|
this.data.title = stringToPDFString(parentItem.get('T') || ''); |
|
|
|
this.data.title = stringToPDFString(parentItem.get('T') || ''); |
|
|
@ -946,101 +894,73 @@ var PopupAnnotation = (function PopupAnnotationClosure() { |
|
|
|
// that is most likely a bug. Fallback to inherit the flags from the parent
|
|
|
|
// that is most likely a bug. Fallback to inherit the flags from the parent
|
|
|
|
// annotation (this is consistent with the behaviour in Adobe Reader).
|
|
|
|
// annotation (this is consistent with the behaviour in Adobe Reader).
|
|
|
|
if (!this.viewable) { |
|
|
|
if (!this.viewable) { |
|
|
|
var parentFlags = parentItem.get('F'); |
|
|
|
let parentFlags = parentItem.get('F'); |
|
|
|
if (this._isViewable(parentFlags)) { |
|
|
|
if (this._isViewable(parentFlags)) { |
|
|
|
this.setFlags(parentFlags); |
|
|
|
this.setFlags(parentFlags); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Util.inherit(PopupAnnotation, Annotation, {}); |
|
|
|
class LineAnnotation extends Annotation { |
|
|
|
|
|
|
|
constructor(parameters) { |
|
|
|
return PopupAnnotation; |
|
|
|
super(parameters); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var LineAnnotation = (function LineAnnotationClosure() { |
|
|
|
|
|
|
|
function LineAnnotation(parameters) { |
|
|
|
|
|
|
|
Annotation.call(this, parameters); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.data.annotationType = AnnotationType.LINE; |
|
|
|
this.data.annotationType = AnnotationType.LINE; |
|
|
|
|
|
|
|
|
|
|
|
var dict = parameters.dict; |
|
|
|
let dict = parameters.dict; |
|
|
|
this.data.lineCoordinates = Util.normalizeRect(dict.getArray('L')); |
|
|
|
this.data.lineCoordinates = Util.normalizeRect(dict.getArray('L')); |
|
|
|
this._preparePopup(dict); |
|
|
|
this._preparePopup(dict); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Util.inherit(LineAnnotation, Annotation, {}); |
|
|
|
class HighlightAnnotation extends Annotation { |
|
|
|
|
|
|
|
constructor(parameters) { |
|
|
|
return LineAnnotation; |
|
|
|
super(parameters); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var HighlightAnnotation = (function HighlightAnnotationClosure() { |
|
|
|
|
|
|
|
function HighlightAnnotation(parameters) { |
|
|
|
|
|
|
|
Annotation.call(this, parameters); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.data.annotationType = AnnotationType.HIGHLIGHT; |
|
|
|
this.data.annotationType = AnnotationType.HIGHLIGHT; |
|
|
|
this._preparePopup(parameters.dict); |
|
|
|
this._preparePopup(parameters.dict); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Util.inherit(HighlightAnnotation, Annotation, {}); |
|
|
|
class UnderlineAnnotation extends Annotation { |
|
|
|
|
|
|
|
constructor(parameters) { |
|
|
|
return HighlightAnnotation; |
|
|
|
super(parameters); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var UnderlineAnnotation = (function UnderlineAnnotationClosure() { |
|
|
|
|
|
|
|
function UnderlineAnnotation(parameters) { |
|
|
|
|
|
|
|
Annotation.call(this, parameters); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.data.annotationType = AnnotationType.UNDERLINE; |
|
|
|
this.data.annotationType = AnnotationType.UNDERLINE; |
|
|
|
this._preparePopup(parameters.dict); |
|
|
|
this._preparePopup(parameters.dict); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Util.inherit(UnderlineAnnotation, Annotation, {}); |
|
|
|
class SquigglyAnnotation extends Annotation { |
|
|
|
|
|
|
|
constructor(parameters) { |
|
|
|
return UnderlineAnnotation; |
|
|
|
super(parameters); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var SquigglyAnnotation = (function SquigglyAnnotationClosure() { |
|
|
|
|
|
|
|
function SquigglyAnnotation(parameters) { |
|
|
|
|
|
|
|
Annotation.call(this, parameters); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.data.annotationType = AnnotationType.SQUIGGLY; |
|
|
|
this.data.annotationType = AnnotationType.SQUIGGLY; |
|
|
|
this._preparePopup(parameters.dict); |
|
|
|
this._preparePopup(parameters.dict); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Util.inherit(SquigglyAnnotation, Annotation, {}); |
|
|
|
class StrikeOutAnnotation extends Annotation { |
|
|
|
|
|
|
|
constructor(parameters) { |
|
|
|
return SquigglyAnnotation; |
|
|
|
super(parameters); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() { |
|
|
|
|
|
|
|
function StrikeOutAnnotation(parameters) { |
|
|
|
|
|
|
|
Annotation.call(this, parameters); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.data.annotationType = AnnotationType.STRIKEOUT; |
|
|
|
this.data.annotationType = AnnotationType.STRIKEOUT; |
|
|
|
this._preparePopup(parameters.dict); |
|
|
|
this._preparePopup(parameters.dict); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Util.inherit(StrikeOutAnnotation, Annotation, {}); |
|
|
|
class FileAttachmentAnnotation extends Annotation { |
|
|
|
|
|
|
|
constructor(parameters) { |
|
|
|
|
|
|
|
super(parameters); |
|
|
|
|
|
|
|
|
|
|
|
return StrikeOutAnnotation; |
|
|
|
let file = new FileSpec(parameters.dict.get('FS'), parameters.xref); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var FileAttachmentAnnotation = (function FileAttachmentAnnotationClosure() { |
|
|
|
|
|
|
|
function FileAttachmentAnnotation(parameters) { |
|
|
|
|
|
|
|
Annotation.call(this, parameters); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var file = new FileSpec(parameters.dict.get('FS'), parameters.xref); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.data.annotationType = AnnotationType.FILEATTACHMENT; |
|
|
|
this.data.annotationType = AnnotationType.FILEATTACHMENT; |
|
|
|
this.data.file = file.serializable; |
|
|
|
this.data.file = file.serializable; |
|
|
|
this._preparePopup(parameters.dict); |
|
|
|
this._preparePopup(parameters.dict); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
Util.inherit(FileAttachmentAnnotation, Annotation, {}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return FileAttachmentAnnotation; |
|
|
|
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export { |
|
|
|
export { |
|
|
|
Annotation, |
|
|
|
Annotation, |
|
|
|