annotation.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. Object.defineProperty(exports, "__esModule", {
  17. value: true
  18. });
  19. exports.AnnotationFactory = exports.AnnotationBorderStyle = exports.Annotation = undefined;
  20. var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
  21. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  22. var _util = require('../shared/util');
  23. var _obj = require('./obj');
  24. var _primitives = require('./primitives');
  25. var _colorspace = require('./colorspace');
  26. var _evaluator = require('./evaluator');
  27. var _stream = require('./stream');
  28. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  29. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  30. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  31. var AnnotationFactory = function () {
  32. function AnnotationFactory() {
  33. _classCallCheck(this, AnnotationFactory);
  34. }
  35. _createClass(AnnotationFactory, null, [{
  36. key: 'create',
  37. value: function create(xref, ref, pdfManager, idFactory) {
  38. var dict = xref.fetchIfRef(ref);
  39. if (!(0, _primitives.isDict)(dict)) {
  40. return;
  41. }
  42. var id = (0, _primitives.isRef)(ref) ? ref.toString() : 'annot_' + idFactory.createObjId();
  43. var subtype = dict.get('Subtype');
  44. subtype = (0, _primitives.isName)(subtype) ? subtype.name : null;
  45. var parameters = {
  46. xref: xref,
  47. dict: dict,
  48. ref: (0, _primitives.isRef)(ref) ? ref : null,
  49. subtype: subtype,
  50. id: id,
  51. pdfManager: pdfManager
  52. };
  53. switch (subtype) {
  54. case 'Link':
  55. return new LinkAnnotation(parameters);
  56. case 'Text':
  57. return new TextAnnotation(parameters);
  58. case 'Widget':
  59. var fieldType = _util.Util.getInheritableProperty(dict, 'FT');
  60. fieldType = (0, _primitives.isName)(fieldType) ? fieldType.name : null;
  61. switch (fieldType) {
  62. case 'Tx':
  63. return new TextWidgetAnnotation(parameters);
  64. case 'Btn':
  65. return new ButtonWidgetAnnotation(parameters);
  66. case 'Ch':
  67. return new ChoiceWidgetAnnotation(parameters);
  68. }
  69. (0, _util.warn)('Unimplemented widget field type "' + fieldType + '", ' + 'falling back to base field type.');
  70. return new WidgetAnnotation(parameters);
  71. case 'Popup':
  72. return new PopupAnnotation(parameters);
  73. case 'Line':
  74. return new LineAnnotation(parameters);
  75. case 'Square':
  76. return new SquareAnnotation(parameters);
  77. case 'Circle':
  78. return new CircleAnnotation(parameters);
  79. case 'PolyLine':
  80. return new PolylineAnnotation(parameters);
  81. case 'Polygon':
  82. return new PolygonAnnotation(parameters);
  83. case 'Highlight':
  84. return new HighlightAnnotation(parameters);
  85. case 'Underline':
  86. return new UnderlineAnnotation(parameters);
  87. case 'Squiggly':
  88. return new SquigglyAnnotation(parameters);
  89. case 'StrikeOut':
  90. return new StrikeOutAnnotation(parameters);
  91. case 'Stamp':
  92. return new StampAnnotation(parameters);
  93. case 'FileAttachment':
  94. return new FileAttachmentAnnotation(parameters);
  95. default:
  96. if (!subtype) {
  97. (0, _util.warn)('Annotation is missing the required /Subtype.');
  98. } else {
  99. (0, _util.warn)('Unimplemented annotation type "' + subtype + '", ' + 'falling back to base annotation.');
  100. }
  101. return new Annotation(parameters);
  102. }
  103. }
  104. }]);
  105. return AnnotationFactory;
  106. }();
  107. function getTransformMatrix(rect, bbox, matrix) {
  108. var bounds = _util.Util.getAxialAlignedBoundingBox(bbox, matrix);
  109. var minX = bounds[0];
  110. var minY = bounds[1];
  111. var maxX = bounds[2];
  112. var maxY = bounds[3];
  113. if (minX === maxX || minY === maxY) {
  114. return [1, 0, 0, 1, rect[0], rect[1]];
  115. }
  116. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  117. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  118. return [xRatio, 0, 0, yRatio, rect[0] - minX * xRatio, rect[1] - minY * yRatio];
  119. }
  120. var Annotation = function () {
  121. function Annotation(params) {
  122. _classCallCheck(this, Annotation);
  123. var dict = params.dict;
  124. this.setFlags(dict.get('F'));
  125. this.setRectangle(dict.getArray('Rect'));
  126. this.setColor(dict.getArray('C'));
  127. this.setBorderStyle(dict);
  128. this.setAppearance(dict);
  129. this.data = {
  130. annotationFlags: this.flags,
  131. borderStyle: this.borderStyle,
  132. color: this.color,
  133. hasAppearance: !!this.appearance,
  134. id: params.id,
  135. rect: this.rectangle,
  136. subtype: params.subtype
  137. };
  138. }
  139. _createClass(Annotation, [{
  140. key: '_hasFlag',
  141. value: function _hasFlag(flags, flag) {
  142. return !!(flags & flag);
  143. }
  144. }, {
  145. key: '_isViewable',
  146. value: function _isViewable(flags) {
  147. return !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN) && !this._hasFlag(flags, _util.AnnotationFlag.NOVIEW);
  148. }
  149. }, {
  150. key: '_isPrintable',
  151. value: function _isPrintable(flags) {
  152. return this._hasFlag(flags, _util.AnnotationFlag.PRINT) && !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN);
  153. }
  154. }, {
  155. key: 'setFlags',
  156. value: function setFlags(flags) {
  157. this.flags = Number.isInteger(flags) && flags > 0 ? flags : 0;
  158. }
  159. }, {
  160. key: 'hasFlag',
  161. value: function hasFlag(flag) {
  162. return this._hasFlag(this.flags, flag);
  163. }
  164. }, {
  165. key: 'setRectangle',
  166. value: function setRectangle(rectangle) {
  167. if (Array.isArray(rectangle) && rectangle.length === 4) {
  168. this.rectangle = _util.Util.normalizeRect(rectangle);
  169. } else {
  170. this.rectangle = [0, 0, 0, 0];
  171. }
  172. }
  173. }, {
  174. key: 'setColor',
  175. value: function setColor(color) {
  176. var rgbColor = new Uint8Array(3);
  177. if (!Array.isArray(color)) {
  178. this.color = rgbColor;
  179. return;
  180. }
  181. switch (color.length) {
  182. case 0:
  183. this.color = null;
  184. break;
  185. case 1:
  186. _colorspace.ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  187. this.color = rgbColor;
  188. break;
  189. case 3:
  190. _colorspace.ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  191. this.color = rgbColor;
  192. break;
  193. case 4:
  194. _colorspace.ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  195. this.color = rgbColor;
  196. break;
  197. default:
  198. this.color = rgbColor;
  199. break;
  200. }
  201. }
  202. }, {
  203. key: 'setBorderStyle',
  204. value: function setBorderStyle(borderStyle) {
  205. this.borderStyle = new AnnotationBorderStyle();
  206. if (!(0, _primitives.isDict)(borderStyle)) {
  207. return;
  208. }
  209. if (borderStyle.has('BS')) {
  210. var dict = borderStyle.get('BS');
  211. var dictType = dict.get('Type');
  212. if (!dictType || (0, _primitives.isName)(dictType, 'Border')) {
  213. this.borderStyle.setWidth(dict.get('W'));
  214. this.borderStyle.setStyle(dict.get('S'));
  215. this.borderStyle.setDashArray(dict.getArray('D'));
  216. }
  217. } else if (borderStyle.has('Border')) {
  218. var array = borderStyle.getArray('Border');
  219. if (Array.isArray(array) && array.length >= 3) {
  220. this.borderStyle.setHorizontalCornerRadius(array[0]);
  221. this.borderStyle.setVerticalCornerRadius(array[1]);
  222. this.borderStyle.setWidth(array[2]);
  223. if (array.length === 4) {
  224. this.borderStyle.setDashArray(array[3]);
  225. }
  226. }
  227. } else {
  228. this.borderStyle.setWidth(0);
  229. }
  230. }
  231. }, {
  232. key: 'setAppearance',
  233. value: function setAppearance(dict) {
  234. this.appearance = null;
  235. var appearanceStates = dict.get('AP');
  236. if (!(0, _primitives.isDict)(appearanceStates)) {
  237. return;
  238. }
  239. var normalAppearanceState = appearanceStates.get('N');
  240. if ((0, _primitives.isStream)(normalAppearanceState)) {
  241. this.appearance = normalAppearanceState;
  242. return;
  243. }
  244. if (!(0, _primitives.isDict)(normalAppearanceState)) {
  245. return;
  246. }
  247. var as = dict.get('AS');
  248. if (!(0, _primitives.isName)(as) || !normalAppearanceState.has(as.name)) {
  249. return;
  250. }
  251. this.appearance = normalAppearanceState.get(as.name);
  252. }
  253. }, {
  254. key: '_preparePopup',
  255. value: function _preparePopup(dict) {
  256. if (!dict.has('C')) {
  257. this.data.color = null;
  258. }
  259. this.data.hasPopup = dict.has('Popup');
  260. this.data.title = (0, _util.stringToPDFString)(dict.get('T') || '');
  261. this.data.contents = (0, _util.stringToPDFString)(dict.get('Contents') || '');
  262. }
  263. }, {
  264. key: 'loadResources',
  265. value: function loadResources(keys) {
  266. return this.appearance.dict.getAsync('Resources').then(function (resources) {
  267. if (!resources) {
  268. return;
  269. }
  270. var objectLoader = new _obj.ObjectLoader(resources, keys, resources.xref);
  271. return objectLoader.load().then(function () {
  272. return resources;
  273. });
  274. });
  275. }
  276. }, {
  277. key: 'getOperatorList',
  278. value: function getOperatorList(evaluator, task, renderForms) {
  279. var _this = this;
  280. if (!this.appearance) {
  281. return Promise.resolve(new _evaluator.OperatorList());
  282. }
  283. var data = this.data;
  284. var appearanceDict = this.appearance.dict;
  285. var resourcesPromise = this.loadResources(['ExtGState', 'ColorSpace', 'Pattern', 'Shading', 'XObject', 'Font']);
  286. var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
  287. var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0, 0];
  288. var transform = getTransformMatrix(data.rect, bbox, matrix);
  289. return resourcesPromise.then(function (resources) {
  290. var opList = new _evaluator.OperatorList();
  291. opList.addOp(_util.OPS.beginAnnotation, [data.rect, transform, matrix]);
  292. return evaluator.getOperatorList({
  293. stream: _this.appearance,
  294. task: task,
  295. resources: resources,
  296. operatorList: opList
  297. }).then(function () {
  298. opList.addOp(_util.OPS.endAnnotation, []);
  299. _this.appearance.reset();
  300. return opList;
  301. });
  302. });
  303. }
  304. }, {
  305. key: 'viewable',
  306. get: function get() {
  307. if (this.flags === 0) {
  308. return true;
  309. }
  310. return this._isViewable(this.flags);
  311. }
  312. }, {
  313. key: 'printable',
  314. get: function get() {
  315. if (this.flags === 0) {
  316. return false;
  317. }
  318. return this._isPrintable(this.flags);
  319. }
  320. }]);
  321. return Annotation;
  322. }();
  323. var AnnotationBorderStyle = function () {
  324. function AnnotationBorderStyle() {
  325. _classCallCheck(this, AnnotationBorderStyle);
  326. this.width = 1;
  327. this.style = _util.AnnotationBorderStyleType.SOLID;
  328. this.dashArray = [3];
  329. this.horizontalCornerRadius = 0;
  330. this.verticalCornerRadius = 0;
  331. }
  332. _createClass(AnnotationBorderStyle, [{
  333. key: 'setWidth',
  334. value: function setWidth(width) {
  335. if (Number.isInteger(width)) {
  336. this.width = width;
  337. }
  338. }
  339. }, {
  340. key: 'setStyle',
  341. value: function setStyle(style) {
  342. if (!style) {
  343. return;
  344. }
  345. switch (style.name) {
  346. case 'S':
  347. this.style = _util.AnnotationBorderStyleType.SOLID;
  348. break;
  349. case 'D':
  350. this.style = _util.AnnotationBorderStyleType.DASHED;
  351. break;
  352. case 'B':
  353. this.style = _util.AnnotationBorderStyleType.BEVELED;
  354. break;
  355. case 'I':
  356. this.style = _util.AnnotationBorderStyleType.INSET;
  357. break;
  358. case 'U':
  359. this.style = _util.AnnotationBorderStyleType.UNDERLINE;
  360. break;
  361. default:
  362. break;
  363. }
  364. }
  365. }, {
  366. key: 'setDashArray',
  367. value: function setDashArray(dashArray) {
  368. if (Array.isArray(dashArray) && dashArray.length > 0) {
  369. var isValid = true;
  370. var allZeros = true;
  371. for (var i = 0, len = dashArray.length; i < len; i++) {
  372. var element = dashArray[i];
  373. var validNumber = +element >= 0;
  374. if (!validNumber) {
  375. isValid = false;
  376. break;
  377. } else if (element > 0) {
  378. allZeros = false;
  379. }
  380. }
  381. if (isValid && !allZeros) {
  382. this.dashArray = dashArray;
  383. } else {
  384. this.width = 0;
  385. }
  386. } else if (dashArray) {
  387. this.width = 0;
  388. }
  389. }
  390. }, {
  391. key: 'setHorizontalCornerRadius',
  392. value: function setHorizontalCornerRadius(radius) {
  393. if (Number.isInteger(radius)) {
  394. this.horizontalCornerRadius = radius;
  395. }
  396. }
  397. }, {
  398. key: 'setVerticalCornerRadius',
  399. value: function setVerticalCornerRadius(radius) {
  400. if (Number.isInteger(radius)) {
  401. this.verticalCornerRadius = radius;
  402. }
  403. }
  404. }]);
  405. return AnnotationBorderStyle;
  406. }();
  407. var WidgetAnnotation = function (_Annotation) {
  408. _inherits(WidgetAnnotation, _Annotation);
  409. function WidgetAnnotation(params) {
  410. _classCallCheck(this, WidgetAnnotation);
  411. var _this2 = _possibleConstructorReturn(this, (WidgetAnnotation.__proto__ || Object.getPrototypeOf(WidgetAnnotation)).call(this, params));
  412. var dict = params.dict;
  413. var data = _this2.data;
  414. data.annotationType = _util.AnnotationType.WIDGET;
  415. data.fieldName = _this2._constructFieldName(dict);
  416. data.fieldValue = _util.Util.getInheritableProperty(dict, 'V', true);
  417. data.alternativeText = (0, _util.stringToPDFString)(dict.get('TU') || '');
  418. data.defaultAppearance = _util.Util.getInheritableProperty(dict, 'DA') || '';
  419. var fieldType = _util.Util.getInheritableProperty(dict, 'FT');
  420. data.fieldType = (0, _primitives.isName)(fieldType) ? fieldType.name : null;
  421. _this2.fieldResources = _util.Util.getInheritableProperty(dict, 'DR') || _primitives.Dict.empty;
  422. data.fieldFlags = _util.Util.getInheritableProperty(dict, 'Ff');
  423. if (!Number.isInteger(data.fieldFlags) || data.fieldFlags < 0) {
  424. data.fieldFlags = 0;
  425. }
  426. data.readOnly = _this2.hasFieldFlag(_util.AnnotationFieldFlag.READONLY);
  427. if (data.fieldType === 'Sig') {
  428. _this2.setFlags(_util.AnnotationFlag.HIDDEN);
  429. }
  430. return _this2;
  431. }
  432. _createClass(WidgetAnnotation, [{
  433. key: '_constructFieldName',
  434. value: function _constructFieldName(dict) {
  435. if (!dict.has('T') && !dict.has('Parent')) {
  436. (0, _util.warn)('Unknown field name, falling back to empty field name.');
  437. return '';
  438. }
  439. if (!dict.has('Parent')) {
  440. return (0, _util.stringToPDFString)(dict.get('T'));
  441. }
  442. var fieldName = [];
  443. if (dict.has('T')) {
  444. fieldName.unshift((0, _util.stringToPDFString)(dict.get('T')));
  445. }
  446. var loopDict = dict;
  447. while (loopDict.has('Parent')) {
  448. loopDict = loopDict.get('Parent');
  449. if (!(0, _primitives.isDict)(loopDict)) {
  450. break;
  451. }
  452. if (loopDict.has('T')) {
  453. fieldName.unshift((0, _util.stringToPDFString)(loopDict.get('T')));
  454. }
  455. }
  456. return fieldName.join('.');
  457. }
  458. }, {
  459. key: 'hasFieldFlag',
  460. value: function hasFieldFlag(flag) {
  461. return !!(this.data.fieldFlags & flag);
  462. }
  463. }, {
  464. key: 'getOperatorList',
  465. value: function getOperatorList(evaluator, task, renderForms) {
  466. if (renderForms) {
  467. return Promise.resolve(new _evaluator.OperatorList());
  468. }
  469. return _get(WidgetAnnotation.prototype.__proto__ || Object.getPrototypeOf(WidgetAnnotation.prototype), 'getOperatorList', this).call(this, evaluator, task, renderForms);
  470. }
  471. }]);
  472. return WidgetAnnotation;
  473. }(Annotation);
  474. var TextWidgetAnnotation = function (_WidgetAnnotation) {
  475. _inherits(TextWidgetAnnotation, _WidgetAnnotation);
  476. function TextWidgetAnnotation(params) {
  477. _classCallCheck(this, TextWidgetAnnotation);
  478. var _this3 = _possibleConstructorReturn(this, (TextWidgetAnnotation.__proto__ || Object.getPrototypeOf(TextWidgetAnnotation)).call(this, params));
  479. _this3.data.fieldValue = (0, _util.stringToPDFString)(_this3.data.fieldValue || '');
  480. var alignment = _util.Util.getInheritableProperty(params.dict, 'Q');
  481. if (!Number.isInteger(alignment) || alignment < 0 || alignment > 2) {
  482. alignment = null;
  483. }
  484. _this3.data.textAlignment = alignment;
  485. var maximumLength = _util.Util.getInheritableProperty(params.dict, 'MaxLen');
  486. if (!Number.isInteger(maximumLength) || maximumLength < 0) {
  487. maximumLength = null;
  488. }
  489. _this3.data.maxLen = maximumLength;
  490. _this3.data.multiLine = _this3.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE);
  491. _this3.data.comb = _this3.hasFieldFlag(_util.AnnotationFieldFlag.COMB) && !_this3.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE) && !_this3.hasFieldFlag(_util.AnnotationFieldFlag.PASSWORD) && !_this3.hasFieldFlag(_util.AnnotationFieldFlag.FILESELECT) && _this3.data.maxLen !== null;
  492. return _this3;
  493. }
  494. _createClass(TextWidgetAnnotation, [{
  495. key: 'getOperatorList',
  496. value: function getOperatorList(evaluator, task, renderForms) {
  497. if (renderForms || this.appearance) {
  498. return _get(TextWidgetAnnotation.prototype.__proto__ || Object.getPrototypeOf(TextWidgetAnnotation.prototype), 'getOperatorList', this).call(this, evaluator, task, renderForms);
  499. }
  500. var operatorList = new _evaluator.OperatorList();
  501. if (!this.data.defaultAppearance) {
  502. return Promise.resolve(operatorList);
  503. }
  504. var stream = new _stream.Stream((0, _util.stringToBytes)(this.data.defaultAppearance));
  505. return evaluator.getOperatorList({
  506. stream: stream,
  507. task: task,
  508. resources: this.fieldResources,
  509. operatorList: operatorList
  510. }).then(function () {
  511. return operatorList;
  512. });
  513. }
  514. }]);
  515. return TextWidgetAnnotation;
  516. }(WidgetAnnotation);
  517. var ButtonWidgetAnnotation = function (_WidgetAnnotation2) {
  518. _inherits(ButtonWidgetAnnotation, _WidgetAnnotation2);
  519. function ButtonWidgetAnnotation(params) {
  520. _classCallCheck(this, ButtonWidgetAnnotation);
  521. var _this4 = _possibleConstructorReturn(this, (ButtonWidgetAnnotation.__proto__ || Object.getPrototypeOf(ButtonWidgetAnnotation)).call(this, params));
  522. _this4.data.checkBox = !_this4.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !_this4.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
  523. if (_this4.data.checkBox) {
  524. if (!(0, _primitives.isName)(_this4.data.fieldValue)) {
  525. return _possibleConstructorReturn(_this4);
  526. }
  527. _this4.data.fieldValue = _this4.data.fieldValue.name;
  528. }
  529. _this4.data.radioButton = _this4.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !_this4.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
  530. if (_this4.data.radioButton) {
  531. _this4.data.fieldValue = _this4.data.buttonValue = null;
  532. var fieldParent = params.dict.get('Parent');
  533. if ((0, _primitives.isDict)(fieldParent) && fieldParent.has('V')) {
  534. var fieldParentValue = fieldParent.get('V');
  535. if ((0, _primitives.isName)(fieldParentValue)) {
  536. _this4.data.fieldValue = fieldParentValue.name;
  537. }
  538. }
  539. var appearanceStates = params.dict.get('AP');
  540. if (!(0, _primitives.isDict)(appearanceStates)) {
  541. return _possibleConstructorReturn(_this4);
  542. }
  543. var normalAppearanceState = appearanceStates.get('N');
  544. if (!(0, _primitives.isDict)(normalAppearanceState)) {
  545. return _possibleConstructorReturn(_this4);
  546. }
  547. var keys = normalAppearanceState.getKeys();
  548. for (var i = 0, ii = keys.length; i < ii; i++) {
  549. if (keys[i] !== 'Off') {
  550. _this4.data.buttonValue = keys[i];
  551. break;
  552. }
  553. }
  554. }
  555. return _this4;
  556. }
  557. return ButtonWidgetAnnotation;
  558. }(WidgetAnnotation);
  559. var ChoiceWidgetAnnotation = function (_WidgetAnnotation3) {
  560. _inherits(ChoiceWidgetAnnotation, _WidgetAnnotation3);
  561. function ChoiceWidgetAnnotation(params) {
  562. _classCallCheck(this, ChoiceWidgetAnnotation);
  563. var _this5 = _possibleConstructorReturn(this, (ChoiceWidgetAnnotation.__proto__ || Object.getPrototypeOf(ChoiceWidgetAnnotation)).call(this, params));
  564. _this5.data.options = [];
  565. var options = _util.Util.getInheritableProperty(params.dict, 'Opt');
  566. if (Array.isArray(options)) {
  567. var xref = params.xref;
  568. for (var i = 0, ii = options.length; i < ii; i++) {
  569. var option = xref.fetchIfRef(options[i]);
  570. var isOptionArray = Array.isArray(option);
  571. _this5.data.options[i] = {
  572. exportValue: isOptionArray ? xref.fetchIfRef(option[0]) : option,
  573. displayValue: isOptionArray ? xref.fetchIfRef(option[1]) : option
  574. };
  575. }
  576. }
  577. if (!Array.isArray(_this5.data.fieldValue)) {
  578. _this5.data.fieldValue = [_this5.data.fieldValue];
  579. }
  580. _this5.data.combo = _this5.hasFieldFlag(_util.AnnotationFieldFlag.COMBO);
  581. _this5.data.multiSelect = _this5.hasFieldFlag(_util.AnnotationFieldFlag.MULTISELECT);
  582. return _this5;
  583. }
  584. return ChoiceWidgetAnnotation;
  585. }(WidgetAnnotation);
  586. var TextAnnotation = function (_Annotation2) {
  587. _inherits(TextAnnotation, _Annotation2);
  588. function TextAnnotation(parameters) {
  589. _classCallCheck(this, TextAnnotation);
  590. var DEFAULT_ICON_SIZE = 22;
  591. var _this6 = _possibleConstructorReturn(this, (TextAnnotation.__proto__ || Object.getPrototypeOf(TextAnnotation)).call(this, parameters));
  592. _this6.data.annotationType = _util.AnnotationType.TEXT;
  593. if (_this6.data.hasAppearance) {
  594. _this6.data.name = 'NoIcon';
  595. } else {
  596. _this6.data.rect[1] = _this6.data.rect[3] - DEFAULT_ICON_SIZE;
  597. _this6.data.rect[2] = _this6.data.rect[0] + DEFAULT_ICON_SIZE;
  598. _this6.data.name = parameters.dict.has('Name') ? parameters.dict.get('Name').name : 'Note';
  599. }
  600. _this6._preparePopup(parameters.dict);
  601. return _this6;
  602. }
  603. return TextAnnotation;
  604. }(Annotation);
  605. var LinkAnnotation = function (_Annotation3) {
  606. _inherits(LinkAnnotation, _Annotation3);
  607. function LinkAnnotation(params) {
  608. _classCallCheck(this, LinkAnnotation);
  609. var _this7 = _possibleConstructorReturn(this, (LinkAnnotation.__proto__ || Object.getPrototypeOf(LinkAnnotation)).call(this, params));
  610. _this7.data.annotationType = _util.AnnotationType.LINK;
  611. _obj.Catalog.parseDestDictionary({
  612. destDict: params.dict,
  613. resultObj: _this7.data,
  614. docBaseUrl: params.pdfManager.docBaseUrl
  615. });
  616. return _this7;
  617. }
  618. return LinkAnnotation;
  619. }(Annotation);
  620. var PopupAnnotation = function (_Annotation4) {
  621. _inherits(PopupAnnotation, _Annotation4);
  622. function PopupAnnotation(parameters) {
  623. _classCallCheck(this, PopupAnnotation);
  624. var _this8 = _possibleConstructorReturn(this, (PopupAnnotation.__proto__ || Object.getPrototypeOf(PopupAnnotation)).call(this, parameters));
  625. _this8.data.annotationType = _util.AnnotationType.POPUP;
  626. var dict = parameters.dict;
  627. var parentItem = dict.get('Parent');
  628. if (!parentItem) {
  629. (0, _util.warn)('Popup annotation has a missing or invalid parent annotation.');
  630. return _possibleConstructorReturn(_this8);
  631. }
  632. var parentSubtype = parentItem.get('Subtype');
  633. _this8.data.parentType = (0, _primitives.isName)(parentSubtype) ? parentSubtype.name : null;
  634. _this8.data.parentId = dict.getRaw('Parent').toString();
  635. _this8.data.title = (0, _util.stringToPDFString)(parentItem.get('T') || '');
  636. _this8.data.contents = (0, _util.stringToPDFString)(parentItem.get('Contents') || '');
  637. if (!parentItem.has('C')) {
  638. _this8.data.color = null;
  639. } else {
  640. _this8.setColor(parentItem.getArray('C'));
  641. _this8.data.color = _this8.color;
  642. }
  643. if (!_this8.viewable) {
  644. var parentFlags = parentItem.get('F');
  645. if (_this8._isViewable(parentFlags)) {
  646. _this8.setFlags(parentFlags);
  647. }
  648. }
  649. return _this8;
  650. }
  651. return PopupAnnotation;
  652. }(Annotation);
  653. var LineAnnotation = function (_Annotation5) {
  654. _inherits(LineAnnotation, _Annotation5);
  655. function LineAnnotation(parameters) {
  656. _classCallCheck(this, LineAnnotation);
  657. var _this9 = _possibleConstructorReturn(this, (LineAnnotation.__proto__ || Object.getPrototypeOf(LineAnnotation)).call(this, parameters));
  658. _this9.data.annotationType = _util.AnnotationType.LINE;
  659. var dict = parameters.dict;
  660. _this9.data.lineCoordinates = _util.Util.normalizeRect(dict.getArray('L'));
  661. _this9._preparePopup(dict);
  662. return _this9;
  663. }
  664. return LineAnnotation;
  665. }(Annotation);
  666. var SquareAnnotation = function (_Annotation6) {
  667. _inherits(SquareAnnotation, _Annotation6);
  668. function SquareAnnotation(parameters) {
  669. _classCallCheck(this, SquareAnnotation);
  670. var _this10 = _possibleConstructorReturn(this, (SquareAnnotation.__proto__ || Object.getPrototypeOf(SquareAnnotation)).call(this, parameters));
  671. _this10.data.annotationType = _util.AnnotationType.SQUARE;
  672. _this10._preparePopup(parameters.dict);
  673. return _this10;
  674. }
  675. return SquareAnnotation;
  676. }(Annotation);
  677. var CircleAnnotation = function (_Annotation7) {
  678. _inherits(CircleAnnotation, _Annotation7);
  679. function CircleAnnotation(parameters) {
  680. _classCallCheck(this, CircleAnnotation);
  681. var _this11 = _possibleConstructorReturn(this, (CircleAnnotation.__proto__ || Object.getPrototypeOf(CircleAnnotation)).call(this, parameters));
  682. _this11.data.annotationType = _util.AnnotationType.CIRCLE;
  683. _this11._preparePopup(parameters.dict);
  684. return _this11;
  685. }
  686. return CircleAnnotation;
  687. }(Annotation);
  688. var PolylineAnnotation = function (_Annotation8) {
  689. _inherits(PolylineAnnotation, _Annotation8);
  690. function PolylineAnnotation(parameters) {
  691. _classCallCheck(this, PolylineAnnotation);
  692. var _this12 = _possibleConstructorReturn(this, (PolylineAnnotation.__proto__ || Object.getPrototypeOf(PolylineAnnotation)).call(this, parameters));
  693. _this12.data.annotationType = _util.AnnotationType.POLYLINE;
  694. var dict = parameters.dict;
  695. var rawVertices = dict.getArray('Vertices');
  696. _this12.data.vertices = [];
  697. for (var i = 0, ii = rawVertices.length; i < ii; i += 2) {
  698. _this12.data.vertices.push({
  699. x: rawVertices[i],
  700. y: rawVertices[i + 1]
  701. });
  702. }
  703. _this12._preparePopup(dict);
  704. return _this12;
  705. }
  706. return PolylineAnnotation;
  707. }(Annotation);
  708. var PolygonAnnotation = function (_PolylineAnnotation) {
  709. _inherits(PolygonAnnotation, _PolylineAnnotation);
  710. function PolygonAnnotation(parameters) {
  711. _classCallCheck(this, PolygonAnnotation);
  712. var _this13 = _possibleConstructorReturn(this, (PolygonAnnotation.__proto__ || Object.getPrototypeOf(PolygonAnnotation)).call(this, parameters));
  713. _this13.data.annotationType = _util.AnnotationType.POLYGON;
  714. return _this13;
  715. }
  716. return PolygonAnnotation;
  717. }(PolylineAnnotation);
  718. var HighlightAnnotation = function (_Annotation9) {
  719. _inherits(HighlightAnnotation, _Annotation9);
  720. function HighlightAnnotation(parameters) {
  721. _classCallCheck(this, HighlightAnnotation);
  722. var _this14 = _possibleConstructorReturn(this, (HighlightAnnotation.__proto__ || Object.getPrototypeOf(HighlightAnnotation)).call(this, parameters));
  723. _this14.data.annotationType = _util.AnnotationType.HIGHLIGHT;
  724. _this14._preparePopup(parameters.dict);
  725. return _this14;
  726. }
  727. return HighlightAnnotation;
  728. }(Annotation);
  729. var UnderlineAnnotation = function (_Annotation10) {
  730. _inherits(UnderlineAnnotation, _Annotation10);
  731. function UnderlineAnnotation(parameters) {
  732. _classCallCheck(this, UnderlineAnnotation);
  733. var _this15 = _possibleConstructorReturn(this, (UnderlineAnnotation.__proto__ || Object.getPrototypeOf(UnderlineAnnotation)).call(this, parameters));
  734. _this15.data.annotationType = _util.AnnotationType.UNDERLINE;
  735. _this15._preparePopup(parameters.dict);
  736. return _this15;
  737. }
  738. return UnderlineAnnotation;
  739. }(Annotation);
  740. var SquigglyAnnotation = function (_Annotation11) {
  741. _inherits(SquigglyAnnotation, _Annotation11);
  742. function SquigglyAnnotation(parameters) {
  743. _classCallCheck(this, SquigglyAnnotation);
  744. var _this16 = _possibleConstructorReturn(this, (SquigglyAnnotation.__proto__ || Object.getPrototypeOf(SquigglyAnnotation)).call(this, parameters));
  745. _this16.data.annotationType = _util.AnnotationType.SQUIGGLY;
  746. _this16._preparePopup(parameters.dict);
  747. return _this16;
  748. }
  749. return SquigglyAnnotation;
  750. }(Annotation);
  751. var StrikeOutAnnotation = function (_Annotation12) {
  752. _inherits(StrikeOutAnnotation, _Annotation12);
  753. function StrikeOutAnnotation(parameters) {
  754. _classCallCheck(this, StrikeOutAnnotation);
  755. var _this17 = _possibleConstructorReturn(this, (StrikeOutAnnotation.__proto__ || Object.getPrototypeOf(StrikeOutAnnotation)).call(this, parameters));
  756. _this17.data.annotationType = _util.AnnotationType.STRIKEOUT;
  757. _this17._preparePopup(parameters.dict);
  758. return _this17;
  759. }
  760. return StrikeOutAnnotation;
  761. }(Annotation);
  762. var StampAnnotation = function (_Annotation13) {
  763. _inherits(StampAnnotation, _Annotation13);
  764. function StampAnnotation(parameters) {
  765. _classCallCheck(this, StampAnnotation);
  766. var _this18 = _possibleConstructorReturn(this, (StampAnnotation.__proto__ || Object.getPrototypeOf(StampAnnotation)).call(this, parameters));
  767. _this18.data.annotationType = _util.AnnotationType.STAMP;
  768. _this18._preparePopup(parameters.dict);
  769. return _this18;
  770. }
  771. return StampAnnotation;
  772. }(Annotation);
  773. var FileAttachmentAnnotation = function (_Annotation14) {
  774. _inherits(FileAttachmentAnnotation, _Annotation14);
  775. function FileAttachmentAnnotation(parameters) {
  776. _classCallCheck(this, FileAttachmentAnnotation);
  777. var _this19 = _possibleConstructorReturn(this, (FileAttachmentAnnotation.__proto__ || Object.getPrototypeOf(FileAttachmentAnnotation)).call(this, parameters));
  778. var file = new _obj.FileSpec(parameters.dict.get('FS'), parameters.xref);
  779. _this19.data.annotationType = _util.AnnotationType.FILEATTACHMENT;
  780. _this19.data.file = file.serializable;
  781. _this19._preparePopup(parameters.dict);
  782. return _this19;
  783. }
  784. return FileAttachmentAnnotation;
  785. }(Annotation);
  786. exports.Annotation = Annotation;
  787. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  788. exports.AnnotationFactory = AnnotationFactory;