2
0

annotation.js 30 KB

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