2
0

annotation.js 24 KB

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