annotation_layer_builder.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = undefined;
  20. var _pdfjs = require('pdfjs-web/pdfjs');
  21. var _ui_utils = require('pdfjs-web/ui_utils');
  22. var _pdf_link_service = require('pdfjs-web/pdf_link_service');
  23. var AnnotationLayerBuilder = function AnnotationLayerBuilderClosure() {
  24. function AnnotationLayerBuilder(options) {
  25. this.pageDiv = options.pageDiv;
  26. this.pdfPage = options.pdfPage;
  27. this.renderInteractiveForms = options.renderInteractiveForms;
  28. this.linkService = options.linkService;
  29. this.downloadManager = options.downloadManager;
  30. this.div = null;
  31. }
  32. AnnotationLayerBuilder.prototype = {
  33. render: function AnnotationLayerBuilder_render(viewport, intent) {
  34. var self = this;
  35. var parameters = { intent: intent === undefined ? 'display' : intent };
  36. this.pdfPage.getAnnotations(parameters).then(function (annotations) {
  37. viewport = viewport.clone({ dontFlip: true });
  38. parameters = {
  39. viewport: viewport,
  40. div: self.div,
  41. annotations: annotations,
  42. page: self.pdfPage,
  43. renderInteractiveForms: self.renderInteractiveForms,
  44. linkService: self.linkService,
  45. downloadManager: self.downloadManager
  46. };
  47. if (self.div) {
  48. _pdfjs.AnnotationLayer.update(parameters);
  49. } else {
  50. if (annotations.length === 0) {
  51. return;
  52. }
  53. self.div = document.createElement('div');
  54. self.div.className = 'annotationLayer';
  55. self.pageDiv.appendChild(self.div);
  56. parameters.div = self.div;
  57. _pdfjs.AnnotationLayer.render(parameters);
  58. if (typeof _ui_utils.mozL10n !== 'undefined') {
  59. _ui_utils.mozL10n.translate(self.div);
  60. }
  61. }
  62. });
  63. },
  64. hide: function AnnotationLayerBuilder_hide() {
  65. if (!this.div) {
  66. return;
  67. }
  68. this.div.setAttribute('hidden', 'true');
  69. }
  70. };
  71. return AnnotationLayerBuilder;
  72. }();
  73. function DefaultAnnotationLayerFactory() {}
  74. DefaultAnnotationLayerFactory.prototype = {
  75. createAnnotationLayerBuilder: function (pageDiv, pdfPage, renderInteractiveForms) {
  76. return new AnnotationLayerBuilder({
  77. pageDiv: pageDiv,
  78. pdfPage: pdfPage,
  79. renderInteractiveForms: renderInteractiveForms,
  80. linkService: new _pdf_link_service.SimpleLinkService()
  81. });
  82. }
  83. };
  84. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  85. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;