annotation_layer.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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. var sharedUtil = require('../shared/util.js');
  17. var displayDOMUtils = require('./dom_utils.js');
  18. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  19. var AnnotationType = sharedUtil.AnnotationType;
  20. var stringToPDFString = sharedUtil.stringToPDFString;
  21. var Util = sharedUtil.Util;
  22. var addLinkAttributes = displayDOMUtils.addLinkAttributes;
  23. var LinkTarget = displayDOMUtils.LinkTarget;
  24. var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  25. var warn = sharedUtil.warn;
  26. var CustomStyle = displayDOMUtils.CustomStyle;
  27. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  28. function AnnotationElementFactory() {}
  29. AnnotationElementFactory.prototype = {
  30. create: function AnnotationElementFactory_create(parameters) {
  31. var subtype = parameters.data.annotationType;
  32. switch (subtype) {
  33. case AnnotationType.LINK:
  34. return new LinkAnnotationElement(parameters);
  35. case AnnotationType.TEXT:
  36. return new TextAnnotationElement(parameters);
  37. case AnnotationType.WIDGET:
  38. var fieldType = parameters.data.fieldType;
  39. switch (fieldType) {
  40. case 'Tx':
  41. return new TextWidgetAnnotationElement(parameters);
  42. case 'Btn':
  43. if (parameters.data.radioButton) {
  44. return new RadioButtonWidgetAnnotationElement(parameters);
  45. } else if (parameters.data.checkBox) {
  46. return new CheckboxWidgetAnnotationElement(parameters);
  47. }
  48. warn('Unimplemented button widget annotation: pushbutton');
  49. break;
  50. case 'Ch':
  51. return new ChoiceWidgetAnnotationElement(parameters);
  52. }
  53. return new WidgetAnnotationElement(parameters);
  54. case AnnotationType.POPUP:
  55. return new PopupAnnotationElement(parameters);
  56. case AnnotationType.HIGHLIGHT:
  57. return new HighlightAnnotationElement(parameters);
  58. case AnnotationType.UNDERLINE:
  59. return new UnderlineAnnotationElement(parameters);
  60. case AnnotationType.SQUIGGLY:
  61. return new SquigglyAnnotationElement(parameters);
  62. case AnnotationType.STRIKEOUT:
  63. return new StrikeOutAnnotationElement(parameters);
  64. case AnnotationType.FILEATTACHMENT:
  65. return new FileAttachmentAnnotationElement(parameters);
  66. default:
  67. return new AnnotationElement(parameters);
  68. }
  69. }
  70. };
  71. var AnnotationElement = function AnnotationElementClosure() {
  72. function AnnotationElement(parameters, isRenderable) {
  73. this.isRenderable = isRenderable || false;
  74. this.data = parameters.data;
  75. this.layer = parameters.layer;
  76. this.page = parameters.page;
  77. this.viewport = parameters.viewport;
  78. this.linkService = parameters.linkService;
  79. this.downloadManager = parameters.downloadManager;
  80. this.imageResourcesPath = parameters.imageResourcesPath;
  81. this.renderInteractiveForms = parameters.renderInteractiveForms;
  82. if (isRenderable) {
  83. this.container = this._createContainer();
  84. }
  85. }
  86. AnnotationElement.prototype = {
  87. _createContainer: function AnnotationElement_createContainer() {
  88. var data = this.data,
  89. page = this.page,
  90. viewport = this.viewport;
  91. var container = document.createElement('section');
  92. var width = data.rect[2] - data.rect[0];
  93. var height = data.rect[3] - data.rect[1];
  94. container.setAttribute('data-annotation-id', data.id);
  95. var rect = Util.normalizeRect([data.rect[0], page.view[3] - data.rect[1] + page.view[1], data.rect[2], page.view[3] - data.rect[3] + page.view[1]]);
  96. CustomStyle.setProp('transform', container, 'matrix(' + viewport.transform.join(',') + ')');
  97. CustomStyle.setProp('transformOrigin', container, -rect[0] + 'px ' + -rect[1] + 'px');
  98. if (data.borderStyle.width > 0) {
  99. container.style.borderWidth = data.borderStyle.width + 'px';
  100. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  101. width = width - 2 * data.borderStyle.width;
  102. height = height - 2 * data.borderStyle.width;
  103. }
  104. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  105. var verticalRadius = data.borderStyle.verticalCornerRadius;
  106. if (horizontalRadius > 0 || verticalRadius > 0) {
  107. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  108. CustomStyle.setProp('borderRadius', container, radius);
  109. }
  110. switch (data.borderStyle.style) {
  111. case AnnotationBorderStyleType.SOLID:
  112. container.style.borderStyle = 'solid';
  113. break;
  114. case AnnotationBorderStyleType.DASHED:
  115. container.style.borderStyle = 'dashed';
  116. break;
  117. case AnnotationBorderStyleType.BEVELED:
  118. warn('Unimplemented border style: beveled');
  119. break;
  120. case AnnotationBorderStyleType.INSET:
  121. warn('Unimplemented border style: inset');
  122. break;
  123. case AnnotationBorderStyleType.UNDERLINE:
  124. container.style.borderBottomStyle = 'solid';
  125. break;
  126. default:
  127. break;
  128. }
  129. if (data.color) {
  130. container.style.borderColor = Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  131. } else {
  132. container.style.borderWidth = 0;
  133. }
  134. }
  135. container.style.left = rect[0] + 'px';
  136. container.style.top = rect[1] + 'px';
  137. container.style.width = width + 'px';
  138. container.style.height = height + 'px';
  139. return container;
  140. },
  141. _createPopup: function AnnotationElement_createPopup(container, trigger, data) {
  142. if (!trigger) {
  143. trigger = document.createElement('div');
  144. trigger.style.height = container.style.height;
  145. trigger.style.width = container.style.width;
  146. container.appendChild(trigger);
  147. }
  148. var popupElement = new PopupElement({
  149. container: container,
  150. trigger: trigger,
  151. color: data.color,
  152. title: data.title,
  153. contents: data.contents,
  154. hideWrapper: true
  155. });
  156. var popup = popupElement.render();
  157. popup.style.left = container.style.width;
  158. container.appendChild(popup);
  159. },
  160. render: function AnnotationElement_render() {
  161. throw new Error('Abstract method AnnotationElement.render called');
  162. }
  163. };
  164. return AnnotationElement;
  165. }();
  166. var LinkAnnotationElement = function LinkAnnotationElementClosure() {
  167. function LinkAnnotationElement(parameters) {
  168. AnnotationElement.call(this, parameters, true);
  169. }
  170. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  171. render: function LinkAnnotationElement_render() {
  172. this.container.className = 'linkAnnotation';
  173. var link = document.createElement('a');
  174. addLinkAttributes(link, {
  175. url: this.data.url,
  176. target: this.data.newWindow ? LinkTarget.BLANK : undefined
  177. });
  178. if (!this.data.url) {
  179. if (this.data.action) {
  180. this._bindNamedAction(link, this.data.action);
  181. } else {
  182. this._bindLink(link, this.data.dest);
  183. }
  184. }
  185. this.container.appendChild(link);
  186. return this.container;
  187. },
  188. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  189. var self = this;
  190. link.href = this.linkService.getDestinationHash(destination);
  191. link.onclick = function () {
  192. if (destination) {
  193. self.linkService.navigateTo(destination);
  194. }
  195. return false;
  196. };
  197. if (destination) {
  198. link.className = 'internalLink';
  199. }
  200. },
  201. _bindNamedAction: function LinkAnnotationElement_bindNamedAction(link, action) {
  202. var self = this;
  203. link.href = this.linkService.getAnchorUrl('');
  204. link.onclick = function () {
  205. self.linkService.executeNamedAction(action);
  206. return false;
  207. };
  208. link.className = 'internalLink';
  209. }
  210. });
  211. return LinkAnnotationElement;
  212. }();
  213. var TextAnnotationElement = function TextAnnotationElementClosure() {
  214. function TextAnnotationElement(parameters) {
  215. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  216. AnnotationElement.call(this, parameters, isRenderable);
  217. }
  218. Util.inherit(TextAnnotationElement, AnnotationElement, {
  219. render: function TextAnnotationElement_render() {
  220. this.container.className = 'textAnnotation';
  221. var image = document.createElement('img');
  222. image.style.height = this.container.style.height;
  223. image.style.width = this.container.style.width;
  224. image.src = this.imageResourcesPath + 'annotation-' + this.data.name.toLowerCase() + '.svg';
  225. image.alt = '[{{type}} Annotation]';
  226. image.dataset.l10nId = 'text_annotation_type';
  227. image.dataset.l10nArgs = JSON.stringify({ type: this.data.name });
  228. if (!this.data.hasPopup) {
  229. this._createPopup(this.container, image, this.data);
  230. }
  231. this.container.appendChild(image);
  232. return this.container;
  233. }
  234. });
  235. return TextAnnotationElement;
  236. }();
  237. var WidgetAnnotationElement = function WidgetAnnotationElementClosure() {
  238. function WidgetAnnotationElement(parameters, isRenderable) {
  239. AnnotationElement.call(this, parameters, isRenderable);
  240. }
  241. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  242. render: function WidgetAnnotationElement_render() {
  243. return this.container;
  244. }
  245. });
  246. return WidgetAnnotationElement;
  247. }();
  248. var TextWidgetAnnotationElement = function TextWidgetAnnotationElementClosure() {
  249. var TEXT_ALIGNMENT = ['left', 'center', 'right'];
  250. function TextWidgetAnnotationElement(parameters) {
  251. var isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  252. WidgetAnnotationElement.call(this, parameters, isRenderable);
  253. }
  254. Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, {
  255. render: function TextWidgetAnnotationElement_render() {
  256. this.container.className = 'textWidgetAnnotation';
  257. var element = null;
  258. if (this.renderInteractiveForms) {
  259. if (this.data.multiLine) {
  260. element = document.createElement('textarea');
  261. element.textContent = this.data.fieldValue;
  262. } else {
  263. element = document.createElement('input');
  264. element.type = 'text';
  265. element.setAttribute('value', this.data.fieldValue);
  266. }
  267. element.disabled = this.data.readOnly;
  268. if (this.data.maxLen !== null) {
  269. element.maxLength = this.data.maxLen;
  270. }
  271. if (this.data.comb) {
  272. var fieldWidth = this.data.rect[2] - this.data.rect[0];
  273. var combWidth = fieldWidth / this.data.maxLen;
  274. element.classList.add('comb');
  275. element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)';
  276. }
  277. } else {
  278. element = document.createElement('div');
  279. element.textContent = this.data.fieldValue;
  280. element.style.verticalAlign = 'middle';
  281. element.style.display = 'table-cell';
  282. var font = null;
  283. if (this.data.fontRefName) {
  284. font = this.page.commonObjs.getData(this.data.fontRefName);
  285. }
  286. this._setTextStyle(element, font);
  287. }
  288. if (this.data.textAlignment !== null) {
  289. element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  290. }
  291. this.container.appendChild(element);
  292. return this.container;
  293. },
  294. _setTextStyle: function TextWidgetAnnotationElement_setTextStyle(element, font) {
  295. var style = element.style;
  296. style.fontSize = this.data.fontSize + 'px';
  297. style.direction = this.data.fontDirection < 0 ? 'rtl' : 'ltr';
  298. if (!font) {
  299. return;
  300. }
  301. style.fontWeight = font.black ? font.bold ? '900' : 'bold' : font.bold ? 'bold' : 'normal';
  302. style.fontStyle = font.italic ? 'italic' : 'normal';
  303. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  304. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  305. style.fontFamily = fontFamily + fallbackName;
  306. }
  307. });
  308. return TextWidgetAnnotationElement;
  309. }();
  310. var CheckboxWidgetAnnotationElement = function CheckboxWidgetAnnotationElementClosure() {
  311. function CheckboxWidgetAnnotationElement(parameters) {
  312. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  313. }
  314. Util.inherit(CheckboxWidgetAnnotationElement, WidgetAnnotationElement, {
  315. render: function CheckboxWidgetAnnotationElement_render() {
  316. this.container.className = 'buttonWidgetAnnotation checkBox';
  317. var element = document.createElement('input');
  318. element.disabled = this.data.readOnly;
  319. element.type = 'checkbox';
  320. if (this.data.fieldValue && this.data.fieldValue !== 'Off') {
  321. element.setAttribute('checked', true);
  322. }
  323. this.container.appendChild(element);
  324. return this.container;
  325. }
  326. });
  327. return CheckboxWidgetAnnotationElement;
  328. }();
  329. var RadioButtonWidgetAnnotationElement = function RadioButtonWidgetAnnotationElementClosure() {
  330. function RadioButtonWidgetAnnotationElement(parameters) {
  331. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  332. }
  333. Util.inherit(RadioButtonWidgetAnnotationElement, WidgetAnnotationElement, {
  334. render: function RadioButtonWidgetAnnotationElement_render() {
  335. this.container.className = 'buttonWidgetAnnotation radioButton';
  336. var element = document.createElement('input');
  337. element.disabled = this.data.readOnly;
  338. element.type = 'radio';
  339. element.name = this.data.fieldName;
  340. if (this.data.fieldValue === this.data.buttonValue) {
  341. element.setAttribute('checked', true);
  342. }
  343. this.container.appendChild(element);
  344. return this.container;
  345. }
  346. });
  347. return RadioButtonWidgetAnnotationElement;
  348. }();
  349. var ChoiceWidgetAnnotationElement = function ChoiceWidgetAnnotationElementClosure() {
  350. function ChoiceWidgetAnnotationElement(parameters) {
  351. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  352. }
  353. Util.inherit(ChoiceWidgetAnnotationElement, WidgetAnnotationElement, {
  354. render: function ChoiceWidgetAnnotationElement_render() {
  355. this.container.className = 'choiceWidgetAnnotation';
  356. var selectElement = document.createElement('select');
  357. selectElement.disabled = this.data.readOnly;
  358. if (!this.data.combo) {
  359. selectElement.size = this.data.options.length;
  360. if (this.data.multiSelect) {
  361. selectElement.multiple = true;
  362. }
  363. }
  364. for (var i = 0, ii = this.data.options.length; i < ii; i++) {
  365. var option = this.data.options[i];
  366. var optionElement = document.createElement('option');
  367. optionElement.textContent = option.displayValue;
  368. optionElement.value = option.exportValue;
  369. if (this.data.fieldValue.indexOf(option.displayValue) >= 0) {
  370. optionElement.setAttribute('selected', true);
  371. }
  372. selectElement.appendChild(optionElement);
  373. }
  374. this.container.appendChild(selectElement);
  375. return this.container;
  376. }
  377. });
  378. return ChoiceWidgetAnnotationElement;
  379. }();
  380. var PopupAnnotationElement = function PopupAnnotationElementClosure() {
  381. function PopupAnnotationElement(parameters) {
  382. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  383. AnnotationElement.call(this, parameters, isRenderable);
  384. }
  385. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  386. render: function PopupAnnotationElement_render() {
  387. this.container.className = 'popupAnnotation';
  388. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  389. var parentElement = this.layer.querySelector(selector);
  390. if (!parentElement) {
  391. return this.container;
  392. }
  393. var popup = new PopupElement({
  394. container: this.container,
  395. trigger: parentElement,
  396. color: this.data.color,
  397. title: this.data.title,
  398. contents: this.data.contents
  399. });
  400. var parentLeft = parseFloat(parentElement.style.left);
  401. var parentWidth = parseFloat(parentElement.style.width);
  402. CustomStyle.setProp('transformOrigin', this.container, -(parentLeft + parentWidth) + 'px -' + parentElement.style.top);
  403. this.container.style.left = parentLeft + parentWidth + 'px';
  404. this.container.appendChild(popup.render());
  405. return this.container;
  406. }
  407. });
  408. return PopupAnnotationElement;
  409. }();
  410. var PopupElement = function PopupElementClosure() {
  411. var BACKGROUND_ENLIGHT = 0.7;
  412. function PopupElement(parameters) {
  413. this.container = parameters.container;
  414. this.trigger = parameters.trigger;
  415. this.color = parameters.color;
  416. this.title = parameters.title;
  417. this.contents = parameters.contents;
  418. this.hideWrapper = parameters.hideWrapper || false;
  419. this.pinned = false;
  420. }
  421. PopupElement.prototype = {
  422. render: function PopupElement_render() {
  423. var wrapper = document.createElement('div');
  424. wrapper.className = 'popupWrapper';
  425. this.hideElement = this.hideWrapper ? wrapper : this.container;
  426. this.hideElement.setAttribute('hidden', true);
  427. var popup = document.createElement('div');
  428. popup.className = 'popup';
  429. var color = this.color;
  430. if (color) {
  431. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  432. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  433. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  434. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  435. }
  436. var contents = this._formatContents(this.contents);
  437. var title = document.createElement('h1');
  438. title.textContent = this.title;
  439. this.trigger.addEventListener('click', this._toggle.bind(this));
  440. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  441. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  442. popup.addEventListener('click', this._hide.bind(this, true));
  443. popup.appendChild(title);
  444. popup.appendChild(contents);
  445. wrapper.appendChild(popup);
  446. return wrapper;
  447. },
  448. _formatContents: function PopupElement_formatContents(contents) {
  449. var p = document.createElement('p');
  450. var lines = contents.split(/(?:\r\n?|\n)/);
  451. for (var i = 0, ii = lines.length; i < ii; ++i) {
  452. var line = lines[i];
  453. p.appendChild(document.createTextNode(line));
  454. if (i < ii - 1) {
  455. p.appendChild(document.createElement('br'));
  456. }
  457. }
  458. return p;
  459. },
  460. _toggle: function PopupElement_toggle() {
  461. if (this.pinned) {
  462. this._hide(true);
  463. } else {
  464. this._show(true);
  465. }
  466. },
  467. _show: function PopupElement_show(pin) {
  468. if (pin) {
  469. this.pinned = true;
  470. }
  471. if (this.hideElement.hasAttribute('hidden')) {
  472. this.hideElement.removeAttribute('hidden');
  473. this.container.style.zIndex += 1;
  474. }
  475. },
  476. _hide: function PopupElement_hide(unpin) {
  477. if (unpin) {
  478. this.pinned = false;
  479. }
  480. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  481. this.hideElement.setAttribute('hidden', true);
  482. this.container.style.zIndex -= 1;
  483. }
  484. }
  485. };
  486. return PopupElement;
  487. }();
  488. var HighlightAnnotationElement = function HighlightAnnotationElementClosure() {
  489. function HighlightAnnotationElement(parameters) {
  490. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  491. AnnotationElement.call(this, parameters, isRenderable);
  492. }
  493. Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  494. render: function HighlightAnnotationElement_render() {
  495. this.container.className = 'highlightAnnotation';
  496. if (!this.data.hasPopup) {
  497. this._createPopup(this.container, null, this.data);
  498. }
  499. return this.container;
  500. }
  501. });
  502. return HighlightAnnotationElement;
  503. }();
  504. var UnderlineAnnotationElement = function UnderlineAnnotationElementClosure() {
  505. function UnderlineAnnotationElement(parameters) {
  506. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  507. AnnotationElement.call(this, parameters, isRenderable);
  508. }
  509. Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  510. render: function UnderlineAnnotationElement_render() {
  511. this.container.className = 'underlineAnnotation';
  512. if (!this.data.hasPopup) {
  513. this._createPopup(this.container, null, this.data);
  514. }
  515. return this.container;
  516. }
  517. });
  518. return UnderlineAnnotationElement;
  519. }();
  520. var SquigglyAnnotationElement = function SquigglyAnnotationElementClosure() {
  521. function SquigglyAnnotationElement(parameters) {
  522. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  523. AnnotationElement.call(this, parameters, isRenderable);
  524. }
  525. Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  526. render: function SquigglyAnnotationElement_render() {
  527. this.container.className = 'squigglyAnnotation';
  528. if (!this.data.hasPopup) {
  529. this._createPopup(this.container, null, this.data);
  530. }
  531. return this.container;
  532. }
  533. });
  534. return SquigglyAnnotationElement;
  535. }();
  536. var StrikeOutAnnotationElement = function StrikeOutAnnotationElementClosure() {
  537. function StrikeOutAnnotationElement(parameters) {
  538. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  539. AnnotationElement.call(this, parameters, isRenderable);
  540. }
  541. Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  542. render: function StrikeOutAnnotationElement_render() {
  543. this.container.className = 'strikeoutAnnotation';
  544. if (!this.data.hasPopup) {
  545. this._createPopup(this.container, null, this.data);
  546. }
  547. return this.container;
  548. }
  549. });
  550. return StrikeOutAnnotationElement;
  551. }();
  552. var FileAttachmentAnnotationElement = function FileAttachmentAnnotationElementClosure() {
  553. function FileAttachmentAnnotationElement(parameters) {
  554. AnnotationElement.call(this, parameters, true);
  555. var file = this.data.file;
  556. this.filename = getFilenameFromUrl(file.filename);
  557. this.content = file.content;
  558. this.linkService.onFileAttachmentAnnotation({
  559. id: stringToPDFString(file.filename),
  560. filename: file.filename,
  561. content: file.content
  562. });
  563. }
  564. Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, {
  565. render: function FileAttachmentAnnotationElement_render() {
  566. this.container.className = 'fileAttachmentAnnotation';
  567. var trigger = document.createElement('div');
  568. trigger.style.height = this.container.style.height;
  569. trigger.style.width = this.container.style.width;
  570. trigger.addEventListener('dblclick', this._download.bind(this));
  571. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  572. this._createPopup(this.container, trigger, this.data);
  573. }
  574. this.container.appendChild(trigger);
  575. return this.container;
  576. },
  577. _download: function FileAttachmentAnnotationElement_download() {
  578. if (!this.downloadManager) {
  579. warn('Download cannot be started due to unavailable download manager');
  580. return;
  581. }
  582. this.downloadManager.downloadData(this.content, this.filename, '');
  583. }
  584. });
  585. return FileAttachmentAnnotationElement;
  586. }();
  587. var AnnotationLayer = function AnnotationLayerClosure() {
  588. return {
  589. render: function AnnotationLayer_render(parameters) {
  590. var annotationElementFactory = new AnnotationElementFactory();
  591. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  592. var data = parameters.annotations[i];
  593. if (!data) {
  594. continue;
  595. }
  596. var element = annotationElementFactory.create({
  597. data: data,
  598. layer: parameters.div,
  599. page: parameters.page,
  600. viewport: parameters.viewport,
  601. linkService: parameters.linkService,
  602. downloadManager: parameters.downloadManager,
  603. imageResourcesPath: parameters.imageResourcesPath || getDefaultSetting('imageResourcesPath'),
  604. renderInteractiveForms: parameters.renderInteractiveForms || false
  605. });
  606. if (element.isRenderable) {
  607. parameters.div.appendChild(element.render());
  608. }
  609. }
  610. },
  611. update: function AnnotationLayer_update(parameters) {
  612. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  613. var data = parameters.annotations[i];
  614. var element = parameters.div.querySelector('[data-annotation-id="' + data.id + '"]');
  615. if (element) {
  616. CustomStyle.setProp('transform', element, 'matrix(' + parameters.viewport.transform.join(',') + ')');
  617. }
  618. }
  619. parameters.div.removeAttribute('hidden');
  620. }
  621. };
  622. }();
  623. exports.AnnotationLayer = AnnotationLayer;