2014-09-30 01:05:28 +09:00
|
|
|
/* Copyright 2014 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 02:34:27 +09:00
|
|
|
(function (root, factory) {
|
|
|
|
if (typeof define === 'function' && define.amd) {
|
|
|
|
define('pdfjs-web/annotation_layer_builder', ['exports',
|
2016-04-09 04:15:48 +09:00
|
|
|
'pdfjs-web/ui_utils', 'pdfjs-web/pdf_link_service',
|
|
|
|
'pdfjs-web/pdfjs'], factory);
|
2016-04-09 02:34:27 +09:00
|
|
|
} else if (typeof exports !== 'undefined') {
|
|
|
|
factory(exports, require('./ui_utils.js'),
|
2016-04-09 04:15:48 +09:00
|
|
|
require('./pdf_link_service.js'), require('./pdfjs.js'));
|
2016-04-09 02:34:27 +09:00
|
|
|
} else {
|
|
|
|
factory((root.pdfjsWebAnnotationLayerBuilder = {}), root.pdfjsWebUIUtils,
|
2016-04-09 04:15:48 +09:00
|
|
|
root.pdfjsWebPDFLinkService, root.pdfjsWebPDFJS);
|
2016-04-09 02:34:27 +09:00
|
|
|
}
|
2016-04-09 04:15:48 +09:00
|
|
|
}(this, function (exports, uiUtils, pdfLinkService, pdfjsLib) {
|
2016-04-09 02:34:27 +09:00
|
|
|
|
|
|
|
var mozL10n = uiUtils.mozL10n;
|
|
|
|
var SimpleLinkService = pdfLinkService.SimpleLinkService;
|
|
|
|
|
2014-09-30 01:05:28 +09:00
|
|
|
/**
|
2015-12-17 20:54:53 +09:00
|
|
|
* @typedef {Object} AnnotationLayerBuilderOptions
|
2014-09-30 01:05:28 +09:00
|
|
|
* @property {HTMLDivElement} pageDiv
|
|
|
|
* @property {PDFPage} pdfPage
|
2016-09-18 02:44:25 +09:00
|
|
|
* @property {boolean} renderInteractiveForms
|
2014-09-30 01:05:28 +09:00
|
|
|
* @property {IPDFLinkService} linkService
|
2016-02-15 04:44:00 +09:00
|
|
|
* @property {DownloadManager} downloadManager
|
2014-09-30 01:05:28 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
*/
|
2015-12-17 20:54:53 +09:00
|
|
|
var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
|
2014-09-30 01:05:28 +09:00
|
|
|
/**
|
2015-12-17 20:54:53 +09:00
|
|
|
* @param {AnnotationLayerBuilderOptions} options
|
|
|
|
* @constructs AnnotationLayerBuilder
|
2014-09-30 01:05:28 +09:00
|
|
|
*/
|
2015-12-17 20:54:53 +09:00
|
|
|
function AnnotationLayerBuilder(options) {
|
2014-09-30 01:05:28 +09:00
|
|
|
this.pageDiv = options.pageDiv;
|
|
|
|
this.pdfPage = options.pdfPage;
|
2016-09-18 02:44:25 +09:00
|
|
|
this.renderInteractiveForms = options.renderInteractiveForms;
|
2014-09-30 01:05:28 +09:00
|
|
|
this.linkService = options.linkService;
|
2016-02-15 04:44:00 +09:00
|
|
|
this.downloadManager = options.downloadManager;
|
2014-09-30 01:05:28 +09:00
|
|
|
|
|
|
|
this.div = null;
|
|
|
|
}
|
2015-12-03 08:20:18 +09:00
|
|
|
|
2015-12-17 20:54:53 +09:00
|
|
|
AnnotationLayerBuilder.prototype =
|
|
|
|
/** @lends AnnotationLayerBuilder.prototype */ {
|
2014-09-30 01:05:28 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {PageViewport} viewport
|
2015-11-22 21:56:52 +09:00
|
|
|
* @param {string} intent (default value is 'display')
|
2014-09-30 01:05:28 +09:00
|
|
|
*/
|
2015-12-17 20:54:53 +09:00
|
|
|
render: function AnnotationLayerBuilder_render(viewport, intent) {
|
2014-09-30 01:05:28 +09:00
|
|
|
var self = this;
|
2015-12-09 07:38:32 +09:00
|
|
|
var parameters = {
|
2015-11-22 21:56:52 +09:00
|
|
|
intent: (intent === undefined ? 'display' : intent),
|
|
|
|
};
|
2014-09-30 01:05:28 +09:00
|
|
|
|
2015-12-09 07:38:32 +09:00
|
|
|
this.pdfPage.getAnnotations(parameters).then(function (annotations) {
|
2014-09-30 01:05:28 +09:00
|
|
|
viewport = viewport.clone({ dontFlip: true });
|
2015-12-17 23:55:11 +09:00
|
|
|
parameters = {
|
|
|
|
viewport: viewport,
|
|
|
|
div: self.div,
|
|
|
|
annotations: annotations,
|
|
|
|
page: self.pdfPage,
|
2016-09-18 02:44:25 +09:00
|
|
|
renderInteractiveForms: self.renderInteractiveForms,
|
2016-02-15 04:44:00 +09:00
|
|
|
linkService: self.linkService,
|
2016-09-07 05:26:57 +09:00
|
|
|
downloadManager: self.downloadManager,
|
2015-12-17 23:55:11 +09:00
|
|
|
};
|
2014-09-30 01:05:28 +09:00
|
|
|
|
|
|
|
if (self.div) {
|
|
|
|
// If an annotationLayer already exists, refresh its children's
|
2015-12-09 07:38:32 +09:00
|
|
|
// transformation matrices.
|
2016-03-29 06:44:27 +09:00
|
|
|
pdfjsLib.AnnotationLayer.update(parameters);
|
2014-09-30 01:05:28 +09:00
|
|
|
} else {
|
2015-12-16 00:48:55 +09:00
|
|
|
// Create an annotation layer div and render the annotations
|
|
|
|
// if there is at least one annotation.
|
2015-12-09 07:38:32 +09:00
|
|
|
if (annotations.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.div = document.createElement('div');
|
|
|
|
self.div.className = 'annotationLayer';
|
|
|
|
self.pageDiv.appendChild(self.div);
|
2015-12-17 23:55:11 +09:00
|
|
|
parameters.div = self.div;
|
2015-12-09 07:38:32 +09:00
|
|
|
|
2016-03-29 06:44:27 +09:00
|
|
|
pdfjsLib.AnnotationLayer.render(parameters);
|
2015-12-16 00:48:55 +09:00
|
|
|
if (typeof mozL10n !== 'undefined') {
|
|
|
|
mozL10n.translate(self.div);
|
2014-09-30 01:05:28 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-12-17 20:54:53 +09:00
|
|
|
hide: function AnnotationLayerBuilder_hide() {
|
2014-09-30 01:05:28 +09:00
|
|
|
if (!this.div) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.div.setAttribute('hidden', 'true');
|
|
|
|
}
|
|
|
|
};
|
2015-12-03 08:20:18 +09:00
|
|
|
|
2015-12-17 20:54:53 +09:00
|
|
|
return AnnotationLayerBuilder;
|
2014-09-30 01:05:28 +09:00
|
|
|
})();
|
2014-12-18 05:47:14 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
2015-12-17 20:54:53 +09:00
|
|
|
* @implements IPDFAnnotationLayerFactory
|
2014-12-18 05:47:14 +09:00
|
|
|
*/
|
2015-12-17 20:54:53 +09:00
|
|
|
function DefaultAnnotationLayerFactory() {}
|
|
|
|
DefaultAnnotationLayerFactory.prototype = {
|
2014-12-18 05:47:14 +09:00
|
|
|
/**
|
|
|
|
* @param {HTMLDivElement} pageDiv
|
|
|
|
* @param {PDFPage} pdfPage
|
2016-09-18 02:44:25 +09:00
|
|
|
* @param {boolean} renderInteractiveForms
|
2015-12-17 20:54:53 +09:00
|
|
|
* @returns {AnnotationLayerBuilder}
|
2014-12-18 05:47:14 +09:00
|
|
|
*/
|
2016-09-18 02:44:25 +09:00
|
|
|
createAnnotationLayerBuilder: function (pageDiv, pdfPage,
|
|
|
|
renderInteractiveForms) {
|
2015-12-17 20:54:53 +09:00
|
|
|
return new AnnotationLayerBuilder({
|
2014-12-18 05:47:14 +09:00
|
|
|
pageDiv: pageDiv,
|
Simplify the SimpleLinkService and use it to pass in a linkService instance in DefaultAnnotationsLayerFactory
Considering that most methods of `SimpleLinkService` are complete stubs, or practically "useless" considering what they return, we can actually simplify it even more.
*Note:* This depends on the previous patch, that did a small amount of refactoring of `PDFViewer_scrollPageIntoView`, since `PDFViewer.linkService.page` is no longer accessed.
----------
Currently the `pageviewer` components example doesn't work correctly (an error is printed in the console), since no `linkService` is present when the `AnnotationsLayerBuilder` is created.
*Note:* Given that this uses the `SimpleLinkService`, clicking on e.g. internal links won't actually do anything. However, given that internal links (and similar features) are pretty much useless when only *one* page is loaded the `pageviewer` example, I don't think that really matters.
Also, using the complete `PDFLinkService` would require a `PDFViewer` instance. That would significantly complicate the example, thus making it both less clear and less self contained.
2015-06-12 05:20:04 +09:00
|
|
|
pdfPage: pdfPage,
|
2016-09-18 02:44:25 +09:00
|
|
|
renderInteractiveForms: renderInteractiveForms,
|
Simplify the SimpleLinkService and use it to pass in a linkService instance in DefaultAnnotationsLayerFactory
Considering that most methods of `SimpleLinkService` are complete stubs, or practically "useless" considering what they return, we can actually simplify it even more.
*Note:* This depends on the previous patch, that did a small amount of refactoring of `PDFViewer_scrollPageIntoView`, since `PDFViewer.linkService.page` is no longer accessed.
----------
Currently the `pageviewer` components example doesn't work correctly (an error is printed in the console), since no `linkService` is present when the `AnnotationsLayerBuilder` is created.
*Note:* Given that this uses the `SimpleLinkService`, clicking on e.g. internal links won't actually do anything. However, given that internal links (and similar features) are pretty much useless when only *one* page is loaded the `pageviewer` example, I don't think that really matters.
Also, using the complete `PDFLinkService` would require a `PDFViewer` instance. That would significantly complicate the example, thus making it both less clear and less self contained.
2015-06-12 05:20:04 +09:00
|
|
|
linkService: new SimpleLinkService(),
|
2014-12-18 05:47:14 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2016-04-09 02:34:27 +09:00
|
|
|
|
|
|
|
exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
|
2016-04-14 00:42:04 +09:00
|
|
|
exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
|
2016-04-09 02:34:27 +09:00
|
|
|
}));
|