You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.2 KiB
112 lines
3.2 KiB
11 years ago
|
/* 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.
|
||
|
*/
|
||
10 years ago
|
/*globals PDFJS, mozL10n, SimpleLinkService */
|
||
11 years ago
|
|
||
|
'use strict';
|
||
|
|
||
|
/**
|
||
9 years ago
|
* @typedef {Object} AnnotationLayerBuilderOptions
|
||
11 years ago
|
* @property {HTMLDivElement} pageDiv
|
||
|
* @property {PDFPage} pdfPage
|
||
|
* @property {IPDFLinkService} linkService
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @class
|
||
|
*/
|
||
9 years ago
|
var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
|
||
11 years ago
|
/**
|
||
9 years ago
|
* @param {AnnotationLayerBuilderOptions} options
|
||
|
* @constructs AnnotationLayerBuilder
|
||
11 years ago
|
*/
|
||
9 years ago
|
function AnnotationLayerBuilder(options) {
|
||
11 years ago
|
this.pageDiv = options.pageDiv;
|
||
|
this.pdfPage = options.pdfPage;
|
||
|
this.linkService = options.linkService;
|
||
|
|
||
|
this.div = null;
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
AnnotationLayerBuilder.prototype =
|
||
|
/** @lends AnnotationLayerBuilder.prototype */ {
|
||
11 years ago
|
|
||
|
/**
|
||
|
* @param {PageViewport} viewport
|
||
10 years ago
|
* @param {string} intent (default value is 'display')
|
||
11 years ago
|
*/
|
||
9 years ago
|
render: function AnnotationLayerBuilder_render(viewport, intent) {
|
||
11 years ago
|
var self = this;
|
||
10 years ago
|
var parameters = {
|
||
10 years ago
|
intent: (intent === undefined ? 'display' : intent),
|
||
|
};
|
||
11 years ago
|
|
||
10 years ago
|
this.pdfPage.getAnnotations(parameters).then(function (annotations) {
|
||
11 years ago
|
viewport = viewport.clone({ dontFlip: true });
|
||
|
|
||
|
if (self.div) {
|
||
|
// If an annotationLayer already exists, refresh its children's
|
||
10 years ago
|
// transformation matrices.
|
||
9 years ago
|
PDFJS.AnnotationLayer.update(viewport, self.div, annotations);
|
||
11 years ago
|
} else {
|
||
9 years ago
|
// Create an annotation layer div and render the annotations
|
||
|
// if there is at least one annotation.
|
||
10 years ago
|
if (annotations.length === 0) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
self.div = document.createElement('div');
|
||
|
self.div.className = 'annotationLayer';
|
||
|
self.pageDiv.appendChild(self.div);
|
||
|
|
||
9 years ago
|
PDFJS.AnnotationLayer.render(viewport, self.div, annotations,
|
||
|
self.pdfPage, self.linkService);
|
||
|
if (typeof mozL10n !== 'undefined') {
|
||
|
mozL10n.translate(self.div);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
});
|
||
|
},
|
||
|
|
||
9 years ago
|
hide: function AnnotationLayerBuilder_hide() {
|
||
11 years ago
|
if (!this.div) {
|
||
|
return;
|
||
|
}
|
||
|
this.div.setAttribute('hidden', 'true');
|
||
|
}
|
||
|
};
|
||
10 years ago
|
|
||
9 years ago
|
return AnnotationLayerBuilder;
|
||
11 years ago
|
})();
|
||
10 years ago
|
|
||
|
/**
|
||
|
* @constructor
|
||
9 years ago
|
* @implements IPDFAnnotationLayerFactory
|
||
10 years ago
|
*/
|
||
9 years ago
|
function DefaultAnnotationLayerFactory() {}
|
||
|
DefaultAnnotationLayerFactory.prototype = {
|
||
10 years ago
|
/**
|
||
|
* @param {HTMLDivElement} pageDiv
|
||
|
* @param {PDFPage} pdfPage
|
||
9 years ago
|
* @returns {AnnotationLayerBuilder}
|
||
10 years ago
|
*/
|
||
9 years ago
|
createAnnotationLayerBuilder: function (pageDiv, pdfPage) {
|
||
|
return new AnnotationLayerBuilder({
|
||
10 years ago
|
pageDiv: pageDiv,
|
||
10 years ago
|
pdfPage: pdfPage,
|
||
|
linkService: new SimpleLinkService(),
|
||
10 years ago
|
});
|
||
|
}
|
||
|
};
|