annotation.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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 'Highlight':
  76. return new HighlightAnnotation(parameters);
  77. case 'Underline':
  78. return new UnderlineAnnotation(parameters);
  79. case 'Squiggly':
  80. return new SquigglyAnnotation(parameters);
  81. case 'StrikeOut':
  82. return new StrikeOutAnnotation(parameters);
  83. case 'FileAttachment':
  84. return new FileAttachmentAnnotation(parameters);
  85. default:
  86. if (!subtype) {
  87. (0, _util.warn)('Annotation is missing the required /Subtype.');
  88. } else {
  89. (0, _util.warn)('Unimplemented annotation type "' + subtype + '", ' + 'falling back to base annotation.');
  90. }
  91. return new Annotation(parameters);
  92. }
  93. }
  94. }]);
  95. return AnnotationFactory;
  96. }();
  97. function getTransformMatrix(rect, bbox, matrix) {
  98. var bounds = _util.Util.getAxialAlignedBoundingBox(bbox, matrix);
  99. var minX = bounds[0];
  100. var minY = bounds[1];
  101. var maxX = bounds[2];
  102. var maxY = bounds[3];
  103. if (minX === maxX || minY === maxY) {
  104. return [1, 0, 0, 1, rect[0], rect[1]];
  105. }
  106. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  107. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  108. return [xRatio, 0, 0, yRatio, rect[0] - minX * xRatio, rect[1] - minY * yRatio];
  109. }
  110. var Annotation = function () {
  111. function Annotation(params) {
  112. _classCallCheck(this, Annotation);
  113. var dict = params.dict;
  114. this.setFlags(dict.get('F'));
  115. this.setRectangle(dict.getArray('Rect'));
  116. this.setColor(dict.getArray('C'));
  117. this.setBorderStyle(dict);
  118. this.setAppearance(dict);
  119. this.data = {
  120. annotationFlags: this.flags,
  121. borderStyle: this.borderStyle,
  122. color: this.color,
  123. hasAppearance: !!this.appearance,
  124. id: params.id,
  125. rect: this.rectangle,
  126. subtype: params.subtype
  127. };
  128. }
  129. _createClass(Annotation, [{
  130. key: '_hasFlag',
  131. value: function _hasFlag(flags, flag) {
  132. return !!(flags & flag);
  133. }
  134. }, {
  135. key: '_isViewable',
  136. value: function _isViewable(flags) {
  137. return !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN) && !this._hasFlag(flags, _util.AnnotationFlag.NOVIEW);
  138. }
  139. }, {
  140. key: '_isPrintable',
  141. value: function _isPrintable(flags) {
  142. return this._hasFlag(flags, _util.AnnotationFlag.PRINT) && !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN);
  143. }
  144. }, {
  145. key: 'setFlags',
  146. value: function setFlags(flags) {
  147. this.flags = (0, _util.isInt)(flags) && flags > 0 ? flags : 0;
  148. }
  149. }, {
  150. key: 'hasFlag',
  151. value: function hasFlag(flag) {
  152. return this._hasFlag(this.flags, flag);
  153. }
  154. }, {
  155. key: 'setRectangle',
  156. value: function setRectangle(rectangle) {
  157. if ((0, _util.isArray)(rectangle) && rectangle.length === 4) {
  158. this.rectangle = _util.Util.normalizeRect(rectangle);
  159. } else {
  160. this.rectangle = [0, 0, 0, 0];
  161. }
  162. }
  163. }, {
  164. key: 'setColor',
  165. value: function setColor(color) {
  166. var rgbColor = new Uint8Array(3);
  167. if (!(0, _util.isArray)(color)) {
  168. this.color = rgbColor;
  169. return;
  170. }
  171. switch (color.length) {
  172. case 0:
  173. this.color = null;
  174. break;
  175. case 1:
  176. _colorspace.ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  177. this.color = rgbColor;
  178. break;
  179. case 3:
  180. _colorspace.ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  181. this.color = rgbColor;
  182. break;
  183. case 4:
  184. _colorspace.ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  185. this.color = rgbColor;
  186. break;
  187. default:
  188. this.color = rgbColor;
  189. break;
  190. }
  191. }
  192. }, {
  193. key: 'setBorderStyle',
  194. value: function setBorderStyle(borderStyle) {
  195. this.borderStyle = new AnnotationBorderStyle();
  196. if (!(0, _primitives.isDict)(borderStyle)) {
  197. return;
  198. }
  199. if (borderStyle.has('BS')) {
  200. var dict = borderStyle.get('BS');
  201. var dictType = dict.get('Type');
  202. if (!dictType || (0, _primitives.isName)(dictType, 'Border')) {
  203. this.borderStyle.setWidth(dict.get('W'));
  204. this.borderStyle.setStyle(dict.get('S'));
  205. this.borderStyle.setDashArray(dict.getArray('D'));
  206. }
  207. } else if (borderStyle.has('Border')) {
  208. var array = borderStyle.getArray('Border');
  209. if ((0, _util.isArray)(array) && array.length >= 3) {
  210. this.borderStyle.setHorizontalCornerRadius(array[0]);
  211. this.borderStyle.setVerticalCornerRadius(array[1]);
  212. this.borderStyle.setWidth(array[2]);
  213. if (array.length === 4) {
  214. this.borderStyle.setDashArray(array[3]);
  215. }
  216. }
  217. } else {
  218. this.borderStyle.setWidth(0);
  219. }
  220. }
  221. }, {
  222. key: 'setAppearance',
  223. value: function setAppearance(dict) {
  224. this.appearance = null;
  225. var appearanceStates = dict.get('AP');
  226. if (!(0, _primitives.isDict)(appearanceStates)) {
  227. return;
  228. }
  229. var normalAppearanceState = appearanceStates.get('N');
  230. if ((0, _primitives.isStream)(normalAppearanceState)) {
  231. this.appearance = normalAppearanceState;
  232. return;
  233. }
  234. if (!(0, _primitives.isDict)(normalAppearanceState)) {
  235. return;
  236. }
  237. var as = dict.get('AS');
  238. if (!(0, _primitives.isName)(as) || !normalAppearanceState.has(as.name)) {
  239. return;
  240. }
  241. this.appearance = normalAppearanceState.get(as.name);
  242. }
  243. }, {
  244. key: '_preparePopup',
  245. value: function _preparePopup(dict) {
  246. if (!dict.has('C')) {
  247. this.data.color = null;
  248. }
  249. this.data.hasPopup = dict.has('Popup');
  250. this.data.title = (0, _util.stringToPDFString)(dict.get('T') || '');
  251. this.data.contents = (0, _util.stringToPDFString)(dict.get('Contents') || '');
  252. }
  253. }, {
  254. key: 'loadResources',
  255. value: function loadResources(keys) {
  256. return this.appearance.dict.getAsync('Resources').then(function (resources) {
  257. if (!resources) {
  258. return;
  259. }
  260. var objectLoader = new _obj.ObjectLoader(resources, keys, resources.xref);
  261. return objectLoader.load().then(function () {
  262. return resources;
  263. });
  264. });
  265. }
  266. }, {
  267. key: 'getOperatorList',
  268. value: function getOperatorList(evaluator, task, renderForms) {
  269. var _this = this;
  270. if (!this.appearance) {
  271. return Promise.resolve(new _evaluator.OperatorList());
  272. }
  273. var data = this.data;
  274. var appearanceDict = this.appearance.dict;
  275. var resourcesPromise = this.loadResources(['ExtGState', 'ColorSpace', 'Pattern', 'Shading', 'XObject', 'Font']);
  276. var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
  277. var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0, 0];
  278. var transform = getTransformMatrix(data.rect, bbox, matrix);
  279. return resourcesPromise.then(function (resources) {
  280. var opList = new _evaluator.OperatorList();
  281. opList.addOp(_util.OPS.beginAnnotation, [data.rect, transform, matrix]);
  282. return evaluator.getOperatorList({
  283. stream: _this.appearance,
  284. task: task,
  285. resources: resources,
  286. operatorList: opList
  287. }).then(function () {
  288. opList.addOp(_util.OPS.endAnnotation, []);
  289. _this.appearance.reset();
  290. return opList;
  291. });
  292. });
  293. }
  294. }, {
  295. key: 'viewable',
  296. get: function get() {
  297. if (this.flags === 0) {
  298. return true;
  299. }
  300. return this._isViewable(this.flags);
  301. }
  302. }, {
  303. key: 'printable',
  304. get: function get() {
  305. if (this.flags === 0) {
  306. return false;
  307. }
  308. return this._isPrintable(this.flags);
  309. }
  310. }]);
  311. return Annotation;
  312. }();
  313. var AnnotationBorderStyle = function () {
  314. function AnnotationBorderStyle() {
  315. _classCallCheck(this, AnnotationBorderStyle);
  316. this.width = 1;
  317. this.style = _util.AnnotationBorderStyleType.SOLID;
  318. this.dashArray = [3];
  319. this.horizontalCornerRadius = 0;
  320. this.verticalCornerRadius = 0;
  321. }
  322. _createClass(AnnotationBorderStyle, [{
  323. key: 'setWidth',
  324. value: function setWidth(width) {
  325. if (width === (width | 0)) {
  326. this.width = width;
  327. }
  328. }
  329. }, {
  330. key: 'setStyle',
  331. value: function setStyle(style) {
  332. if (!style) {
  333. return;
  334. }
  335. switch (style.name) {
  336. case 'S':
  337. this.style = _util.AnnotationBorderStyleType.SOLID;
  338. break;
  339. case 'D':
  340. this.style = _util.AnnotationBorderStyleType.DASHED;
  341. break;
  342. case 'B':
  343. this.style = _util.AnnotationBorderStyleType.BEVELED;
  344. break;
  345. case 'I':
  346. this.style = _util.AnnotationBorderStyleType.INSET;
  347. break;
  348. case 'U':
  349. this.style = _util.AnnotationBorderStyleType.UNDERLINE;
  350. break;
  351. default:
  352. break;
  353. }
  354. }
  355. }, {
  356. key: 'setDashArray',
  357. value: function setDashArray(dashArray) {
  358. if ((0, _util.isArray)(dashArray) && dashArray.length > 0) {
  359. var isValid = true;
  360. var allZeros = true;
  361. for (var i = 0, len = dashArray.length; i < len; i++) {
  362. var element = dashArray[i];
  363. var validNumber = +element >= 0;
  364. if (!validNumber) {
  365. isValid = false;
  366. break;
  367. } else if (element > 0) {
  368. allZeros = false;
  369. }
  370. }
  371. if (isValid && !allZeros) {
  372. this.dashArray = dashArray;
  373. } else {
  374. this.width = 0;
  375. }
  376. } else if (dashArray) {
  377. this.width = 0;
  378. }
  379. }
  380. }, {
  381. key: 'setHorizontalCornerRadius',
  382. value: function setHorizontalCornerRadius(radius) {
  383. if (radius === (radius | 0)) {
  384. this.horizontalCornerRadius = radius;
  385. }
  386. }
  387. }, {
  388. key: 'setVerticalCornerRadius',
  389. value: function setVerticalCornerRadius(radius) {
  390. if (radius === (radius | 0)) {
  391. this.verticalCornerRadius = radius;
  392. }
  393. }
  394. }]);
  395. return AnnotationBorderStyle;
  396. }();
  397. var WidgetAnnotation = function (_Annotation) {
  398. _inherits(WidgetAnnotation, _Annotation);
  399. function WidgetAnnotation(params) {
  400. _classCallCheck(this, WidgetAnnotation);
  401. var _this2 = _possibleConstructorReturn(this, (WidgetAnnotation.__proto__ || Object.getPrototypeOf(WidgetAnnotation)).call(this, params));
  402. var dict = params.dict;
  403. var data = _this2.data;
  404. data.annotationType = _util.AnnotationType.WIDGET;
  405. data.fieldName = _this2._constructFieldName(dict);
  406. data.fieldValue = _util.Util.getInheritableProperty(dict, 'V', true);
  407. data.alternativeText = (0, _util.stringToPDFString)(dict.get('TU') || '');
  408. data.defaultAppearance = _util.Util.getInheritableProperty(dict, 'DA') || '';
  409. var fieldType = _util.Util.getInheritableProperty(dict, 'FT');
  410. data.fieldType = (0, _primitives.isName)(fieldType) ? fieldType.name : null;
  411. _this2.fieldResources = _util.Util.getInheritableProperty(dict, 'DR') || _primitives.Dict.empty;
  412. data.fieldFlags = _util.Util.getInheritableProperty(dict, 'Ff');
  413. if (!(0, _util.isInt)(data.fieldFlags) || data.fieldFlags < 0) {
  414. data.fieldFlags = 0;
  415. }
  416. data.readOnly = _this2.hasFieldFlag(_util.AnnotationFieldFlag.READONLY);
  417. if (data.fieldType === 'Sig') {
  418. _this2.setFlags(_util.AnnotationFlag.HIDDEN);
  419. }
  420. return _this2;
  421. }
  422. _createClass(WidgetAnnotation, [{
  423. key: '_constructFieldName',
  424. value: function _constructFieldName(dict) {
  425. if (!dict.has('T') && !dict.has('Parent')) {
  426. (0, _util.warn)('Unknown field name, falling back to empty field name.');
  427. return '';
  428. }
  429. if (!dict.has('Parent')) {
  430. return (0, _util.stringToPDFString)(dict.get('T'));
  431. }
  432. var fieldName = [];
  433. if (dict.has('T')) {
  434. fieldName.unshift((0, _util.stringToPDFString)(dict.get('T')));
  435. }
  436. var loopDict = dict;
  437. while (loopDict.has('Parent')) {
  438. loopDict = loopDict.get('Parent');
  439. if (!(0, _primitives.isDict)(loopDict)) {
  440. break;
  441. }
  442. if (loopDict.has('T')) {
  443. fieldName.unshift((0, _util.stringToPDFString)(loopDict.get('T')));
  444. }
  445. }
  446. return fieldName.join('.');
  447. }
  448. }, {
  449. key: 'hasFieldFlag',
  450. value: function hasFieldFlag(flag) {
  451. return !!(this.data.fieldFlags & flag);
  452. }
  453. }, {
  454. key: 'getOperatorList',
  455. value: function getOperatorList(evaluator, task, renderForms) {
  456. if (renderForms) {
  457. return Promise.resolve(new _evaluator.OperatorList());
  458. }
  459. return _get(WidgetAnnotation.prototype.__proto__ || Object.getPrototypeOf(WidgetAnnotation.prototype), 'getOperatorList', this).call(this, evaluator, task, renderForms);
  460. }
  461. }]);
  462. return WidgetAnnotation;
  463. }(Annotation);
  464. var TextWidgetAnnotation = function (_WidgetAnnotation) {
  465. _inherits(TextWidgetAnnotation, _WidgetAnnotation);
  466. function TextWidgetAnnotation(params) {
  467. _classCallCheck(this, TextWidgetAnnotation);
  468. var _this3 = _possibleConstructorReturn(this, (TextWidgetAnnotation.__proto__ || Object.getPrototypeOf(TextWidgetAnnotation)).call(this, params));
  469. _this3.data.fieldValue = (0, _util.stringToPDFString)(_this3.data.fieldValue || '');
  470. var alignment = _util.Util.getInheritableProperty(params.dict, 'Q');
  471. if (!(0, _util.isInt)(alignment) || alignment < 0 || alignment > 2) {
  472. alignment = null;
  473. }
  474. _this3.data.textAlignment = alignment;
  475. var maximumLength = _util.Util.getInheritableProperty(params.dict, 'MaxLen');
  476. if (!(0, _util.isInt)(maximumLength) || maximumLength < 0) {
  477. maximumLength = null;
  478. }
  479. _this3.data.maxLen = maximumLength;
  480. _this3.data.multiLine = _this3.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE);
  481. _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;
  482. return _this3;
  483. }
  484. _createClass(TextWidgetAnnotation, [{
  485. key: 'getOperatorList',
  486. value: function getOperatorList(evaluator, task, renderForms) {
  487. if (renderForms || this.appearance) {
  488. return _get(TextWidgetAnnotation.prototype.__proto__ || Object.getPrototypeOf(TextWidgetAnnotation.prototype), 'getOperatorList', this).call(this, evaluator, task, renderForms);
  489. }
  490. var operatorList = new _evaluator.OperatorList();
  491. if (!this.data.defaultAppearance) {
  492. return Promise.resolve(operatorList);
  493. }
  494. var stream = new _stream.Stream((0, _util.stringToBytes)(this.data.defaultAppearance));
  495. return evaluator.getOperatorList({
  496. stream: stream,
  497. task: task,
  498. resources: this.fieldResources,
  499. operatorList: operatorList
  500. }).then(function () {
  501. return operatorList;
  502. });
  503. }
  504. }]);
  505. return TextWidgetAnnotation;
  506. }(WidgetAnnotation);
  507. var ButtonWidgetAnnotation = function (_WidgetAnnotation2) {
  508. _inherits(ButtonWidgetAnnotation, _WidgetAnnotation2);
  509. function ButtonWidgetAnnotation(params) {
  510. _classCallCheck(this, ButtonWidgetAnnotation);
  511. var _this4 = _possibleConstructorReturn(this, (ButtonWidgetAnnotation.__proto__ || Object.getPrototypeOf(ButtonWidgetAnnotation)).call(this, params));
  512. _this4.data.checkBox = !_this4.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !_this4.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
  513. if (_this4.data.checkBox) {
  514. if (!(0, _primitives.isName)(_this4.data.fieldValue)) {
  515. return _possibleConstructorReturn(_this4);
  516. }
  517. _this4.data.fieldValue = _this4.data.fieldValue.name;
  518. }
  519. _this4.data.radioButton = _this4.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !_this4.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
  520. if (_this4.data.radioButton) {
  521. _this4.data.fieldValue = _this4.data.buttonValue = null;
  522. var fieldParent = params.dict.get('Parent');
  523. if ((0, _primitives.isDict)(fieldParent) && fieldParent.has('V')) {
  524. var fieldParentValue = fieldParent.get('V');
  525. if ((0, _primitives.isName)(fieldParentValue)) {
  526. _this4.data.fieldValue = fieldParentValue.name;
  527. }
  528. }
  529. var appearanceStates = params.dict.get('AP');
  530. if (!(0, _primitives.isDict)(appearanceStates)) {
  531. return _possibleConstructorReturn(_this4);
  532. }
  533. var normalAppearanceState = appearanceStates.get('N');
  534. if (!(0, _primitives.isDict)(normalAppearanceState)) {
  535. return _possibleConstructorReturn(_this4);
  536. }
  537. var keys = normalAppearanceState.getKeys();
  538. for (var i = 0, ii = keys.length; i < ii; i++) {
  539. if (keys[i] !== 'Off') {
  540. _this4.data.buttonValue = keys[i];
  541. break;
  542. }
  543. }
  544. }
  545. return _this4;
  546. }
  547. return ButtonWidgetAnnotation;
  548. }(WidgetAnnotation);
  549. var ChoiceWidgetAnnotation = function (_WidgetAnnotation3) {
  550. _inherits(ChoiceWidgetAnnotation, _WidgetAnnotation3);
  551. function ChoiceWidgetAnnotation(params) {
  552. _classCallCheck(this, ChoiceWidgetAnnotation);
  553. var _this5 = _possibleConstructorReturn(this, (ChoiceWidgetAnnotation.__proto__ || Object.getPrototypeOf(ChoiceWidgetAnnotation)).call(this, params));
  554. _this5.data.options = [];
  555. var options = _util.Util.getInheritableProperty(params.dict, 'Opt');
  556. if ((0, _util.isArray)(options)) {
  557. var xref = params.xref;
  558. for (var i = 0, ii = options.length; i < ii; i++) {
  559. var option = xref.fetchIfRef(options[i]);
  560. var isOptionArray = (0, _util.isArray)(option);
  561. _this5.data.options[i] = {
  562. exportValue: isOptionArray ? xref.fetchIfRef(option[0]) : option,
  563. displayValue: isOptionArray ? xref.fetchIfRef(option[1]) : option
  564. };
  565. }
  566. }
  567. if (!(0, _util.isArray)(_this5.data.fieldValue)) {
  568. _this5.data.fieldValue = [_this5.data.fieldValue];
  569. }
  570. _this5.data.combo = _this5.hasFieldFlag(_util.AnnotationFieldFlag.COMBO);
  571. _this5.data.multiSelect = _this5.hasFieldFlag(_util.AnnotationFieldFlag.MULTISELECT);
  572. return _this5;
  573. }
  574. return ChoiceWidgetAnnotation;
  575. }(WidgetAnnotation);
  576. var TextAnnotation = function (_Annotation2) {
  577. _inherits(TextAnnotation, _Annotation2);
  578. function TextAnnotation(parameters) {
  579. _classCallCheck(this, TextAnnotation);
  580. var DEFAULT_ICON_SIZE = 22;
  581. var _this6 = _possibleConstructorReturn(this, (TextAnnotation.__proto__ || Object.getPrototypeOf(TextAnnotation)).call(this, parameters));
  582. _this6.data.annotationType = _util.AnnotationType.TEXT;
  583. if (_this6.data.hasAppearance) {
  584. _this6.data.name = 'NoIcon';
  585. } else {
  586. _this6.data.rect[1] = _this6.data.rect[3] - DEFAULT_ICON_SIZE;
  587. _this6.data.rect[2] = _this6.data.rect[0] + DEFAULT_ICON_SIZE;
  588. _this6.data.name = parameters.dict.has('Name') ? parameters.dict.get('Name').name : 'Note';
  589. }
  590. _this6._preparePopup(parameters.dict);
  591. return _this6;
  592. }
  593. return TextAnnotation;
  594. }(Annotation);
  595. var LinkAnnotation = function (_Annotation3) {
  596. _inherits(LinkAnnotation, _Annotation3);
  597. function LinkAnnotation(params) {
  598. _classCallCheck(this, LinkAnnotation);
  599. var _this7 = _possibleConstructorReturn(this, (LinkAnnotation.__proto__ || Object.getPrototypeOf(LinkAnnotation)).call(this, params));
  600. _this7.data.annotationType = _util.AnnotationType.LINK;
  601. _obj.Catalog.parseDestDictionary({
  602. destDict: params.dict,
  603. resultObj: _this7.data,
  604. docBaseUrl: params.pdfManager.docBaseUrl
  605. });
  606. return _this7;
  607. }
  608. return LinkAnnotation;
  609. }(Annotation);
  610. var PopupAnnotation = function (_Annotation4) {
  611. _inherits(PopupAnnotation, _Annotation4);
  612. function PopupAnnotation(parameters) {
  613. _classCallCheck(this, PopupAnnotation);
  614. var _this8 = _possibleConstructorReturn(this, (PopupAnnotation.__proto__ || Object.getPrototypeOf(PopupAnnotation)).call(this, parameters));
  615. _this8.data.annotationType = _util.AnnotationType.POPUP;
  616. var dict = parameters.dict;
  617. var parentItem = dict.get('Parent');
  618. if (!parentItem) {
  619. (0, _util.warn)('Popup annotation has a missing or invalid parent annotation.');
  620. return _possibleConstructorReturn(_this8);
  621. }
  622. var parentSubtype = parentItem.get('Subtype');
  623. _this8.data.parentType = (0, _primitives.isName)(parentSubtype) ? parentSubtype.name : null;
  624. _this8.data.parentId = dict.getRaw('Parent').toString();
  625. _this8.data.title = (0, _util.stringToPDFString)(parentItem.get('T') || '');
  626. _this8.data.contents = (0, _util.stringToPDFString)(parentItem.get('Contents') || '');
  627. if (!parentItem.has('C')) {
  628. _this8.data.color = null;
  629. } else {
  630. _this8.setColor(parentItem.getArray('C'));
  631. _this8.data.color = _this8.color;
  632. }
  633. if (!_this8.viewable) {
  634. var parentFlags = parentItem.get('F');
  635. if (_this8._isViewable(parentFlags)) {
  636. _this8.setFlags(parentFlags);
  637. }
  638. }
  639. return _this8;
  640. }
  641. return PopupAnnotation;
  642. }(Annotation);
  643. var LineAnnotation = function (_Annotation5) {
  644. _inherits(LineAnnotation, _Annotation5);
  645. function LineAnnotation(parameters) {
  646. _classCallCheck(this, LineAnnotation);
  647. var _this9 = _possibleConstructorReturn(this, (LineAnnotation.__proto__ || Object.getPrototypeOf(LineAnnotation)).call(this, parameters));
  648. _this9.data.annotationType = _util.AnnotationType.LINE;
  649. var dict = parameters.dict;
  650. _this9.data.lineCoordinates = _util.Util.normalizeRect(dict.getArray('L'));
  651. _this9._preparePopup(dict);
  652. return _this9;
  653. }
  654. return LineAnnotation;
  655. }(Annotation);
  656. var HighlightAnnotation = function (_Annotation6) {
  657. _inherits(HighlightAnnotation, _Annotation6);
  658. function HighlightAnnotation(parameters) {
  659. _classCallCheck(this, HighlightAnnotation);
  660. var _this10 = _possibleConstructorReturn(this, (HighlightAnnotation.__proto__ || Object.getPrototypeOf(HighlightAnnotation)).call(this, parameters));
  661. _this10.data.annotationType = _util.AnnotationType.HIGHLIGHT;
  662. _this10._preparePopup(parameters.dict);
  663. return _this10;
  664. }
  665. return HighlightAnnotation;
  666. }(Annotation);
  667. var UnderlineAnnotation = function (_Annotation7) {
  668. _inherits(UnderlineAnnotation, _Annotation7);
  669. function UnderlineAnnotation(parameters) {
  670. _classCallCheck(this, UnderlineAnnotation);
  671. var _this11 = _possibleConstructorReturn(this, (UnderlineAnnotation.__proto__ || Object.getPrototypeOf(UnderlineAnnotation)).call(this, parameters));
  672. _this11.data.annotationType = _util.AnnotationType.UNDERLINE;
  673. _this11._preparePopup(parameters.dict);
  674. return _this11;
  675. }
  676. return UnderlineAnnotation;
  677. }(Annotation);
  678. var SquigglyAnnotation = function (_Annotation8) {
  679. _inherits(SquigglyAnnotation, _Annotation8);
  680. function SquigglyAnnotation(parameters) {
  681. _classCallCheck(this, SquigglyAnnotation);
  682. var _this12 = _possibleConstructorReturn(this, (SquigglyAnnotation.__proto__ || Object.getPrototypeOf(SquigglyAnnotation)).call(this, parameters));
  683. _this12.data.annotationType = _util.AnnotationType.SQUIGGLY;
  684. _this12._preparePopup(parameters.dict);
  685. return _this12;
  686. }
  687. return SquigglyAnnotation;
  688. }(Annotation);
  689. var StrikeOutAnnotation = function (_Annotation9) {
  690. _inherits(StrikeOutAnnotation, _Annotation9);
  691. function StrikeOutAnnotation(parameters) {
  692. _classCallCheck(this, StrikeOutAnnotation);
  693. var _this13 = _possibleConstructorReturn(this, (StrikeOutAnnotation.__proto__ || Object.getPrototypeOf(StrikeOutAnnotation)).call(this, parameters));
  694. _this13.data.annotationType = _util.AnnotationType.STRIKEOUT;
  695. _this13._preparePopup(parameters.dict);
  696. return _this13;
  697. }
  698. return StrikeOutAnnotation;
  699. }(Annotation);
  700. var FileAttachmentAnnotation = function (_Annotation10) {
  701. _inherits(FileAttachmentAnnotation, _Annotation10);
  702. function FileAttachmentAnnotation(parameters) {
  703. _classCallCheck(this, FileAttachmentAnnotation);
  704. var _this14 = _possibleConstructorReturn(this, (FileAttachmentAnnotation.__proto__ || Object.getPrototypeOf(FileAttachmentAnnotation)).call(this, parameters));
  705. var file = new _obj.FileSpec(parameters.dict.get('FS'), parameters.xref);
  706. _this14.data.annotationType = _util.AnnotationType.FILEATTACHMENT;
  707. _this14.data.file = file.serializable;
  708. _this14._preparePopup(parameters.dict);
  709. return _this14;
  710. }
  711. return FileAttachmentAnnotation;
  712. }(Annotation);
  713. exports.Annotation = Annotation;
  714. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  715. exports.AnnotationFactory = AnnotationFactory;