|
|
|
@ -26,15 +26,11 @@ import { SimpleLinkService } from './pdf_link_service';
@@ -26,15 +26,11 @@ import { SimpleLinkService } from './pdf_link_service';
|
|
|
|
|
* @property {DownloadManager} downloadManager |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @class |
|
|
|
|
*/ |
|
|
|
|
var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() { |
|
|
|
|
class AnnotationLayerBuilder { |
|
|
|
|
/** |
|
|
|
|
* @param {AnnotationLayerBuilderOptions} options |
|
|
|
|
* @constructs AnnotationLayerBuilder |
|
|
|
|
*/ |
|
|
|
|
function AnnotationLayerBuilder(options) { |
|
|
|
|
constructor(options) { |
|
|
|
|
this.pageDiv = options.pageDiv; |
|
|
|
|
this.pdfPage = options.pdfPage; |
|
|
|
|
this.renderInteractiveForms = options.renderInteractiveForms; |
|
|
|
@ -44,88 +40,74 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
@@ -44,88 +40,74 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
|
|
|
|
|
this.div = null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
AnnotationLayerBuilder.prototype = |
|
|
|
|
/** @lends AnnotationLayerBuilder.prototype */ { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param {PageViewport} viewport |
|
|
|
|
* @param {string} intent (default value is 'display') |
|
|
|
|
*/ |
|
|
|
|
render: function AnnotationLayerBuilder_render(viewport, intent) { |
|
|
|
|
var self = this; |
|
|
|
|
/** |
|
|
|
|
* @param {PageViewport} viewport |
|
|
|
|
* @param {string} intent (default value is 'display') |
|
|
|
|
*/ |
|
|
|
|
render(viewport, intent = 'display') { |
|
|
|
|
this.pdfPage.getAnnotations({ intent }).then((annotations) => { |
|
|
|
|
var parameters = { |
|
|
|
|
intent: (intent === undefined ? 'display' : intent), |
|
|
|
|
viewport: viewport.clone({ dontFlip: true }), |
|
|
|
|
div: this.div, |
|
|
|
|
annotations, |
|
|
|
|
page: this.pdfPage, |
|
|
|
|
renderInteractiveForms: this.renderInteractiveForms, |
|
|
|
|
linkService: this.linkService, |
|
|
|
|
downloadManager: this.downloadManager, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.pdfPage.getAnnotations(parameters).then(function (annotations) { |
|
|
|
|
viewport = viewport.clone({ dontFlip: true }); |
|
|
|
|
parameters = { |
|
|
|
|
viewport: viewport, |
|
|
|
|
div: self.div, |
|
|
|
|
annotations: annotations, |
|
|
|
|
page: self.pdfPage, |
|
|
|
|
renderInteractiveForms: self.renderInteractiveForms, |
|
|
|
|
linkService: self.linkService, |
|
|
|
|
downloadManager: self.downloadManager, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (self.div) { |
|
|
|
|
// If an annotationLayer already exists, refresh its children's
|
|
|
|
|
// transformation matrices.
|
|
|
|
|
AnnotationLayer.update(parameters); |
|
|
|
|
} else { |
|
|
|
|
// Create an annotation layer div and render the annotations
|
|
|
|
|
// if there is at least one annotation.
|
|
|
|
|
if (annotations.length === 0) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (this.div) { |
|
|
|
|
// If an annotationLayer already exists, refresh its children's
|
|
|
|
|
// transformation matrices.
|
|
|
|
|
AnnotationLayer.update(parameters); |
|
|
|
|
} else { |
|
|
|
|
// Create an annotation layer div and render the annotations
|
|
|
|
|
// if there is at least one annotation.
|
|
|
|
|
if (annotations.length === 0) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self.div = document.createElement('div'); |
|
|
|
|
self.div.className = 'annotationLayer'; |
|
|
|
|
self.pageDiv.appendChild(self.div); |
|
|
|
|
parameters.div = self.div; |
|
|
|
|
this.div = document.createElement('div'); |
|
|
|
|
this.div.className = 'annotationLayer'; |
|
|
|
|
this.pageDiv.appendChild(this.div); |
|
|
|
|
parameters.div = this.div; |
|
|
|
|
|
|
|
|
|
AnnotationLayer.render(parameters); |
|
|
|
|
if (typeof mozL10n !== 'undefined') { |
|
|
|
|
mozL10n.translate(self.div); |
|
|
|
|
} |
|
|
|
|
AnnotationLayer.render(parameters); |
|
|
|
|
if (typeof mozL10n !== 'undefined') { |
|
|
|
|
mozL10n.translate(this.div); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
hide: function AnnotationLayerBuilder_hide() { |
|
|
|
|
if (!this.div) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.div.setAttribute('hidden', 'true'); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return AnnotationLayerBuilder; |
|
|
|
|
})(); |
|
|
|
|
hide() { |
|
|
|
|
if (!this.div) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.div.setAttribute('hidden', 'true'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @constructor |
|
|
|
|
* @implements IPDFAnnotationLayerFactory |
|
|
|
|
*/ |
|
|
|
|
function DefaultAnnotationLayerFactory() {} |
|
|
|
|
DefaultAnnotationLayerFactory.prototype = { |
|
|
|
|
class DefaultAnnotationLayerFactory { |
|
|
|
|
/** |
|
|
|
|
* @param {HTMLDivElement} pageDiv |
|
|
|
|
* @param {PDFPage} pdfPage |
|
|
|
|
* @param {boolean} renderInteractiveForms |
|
|
|
|
* @returns {AnnotationLayerBuilder} |
|
|
|
|
*/ |
|
|
|
|
createAnnotationLayerBuilder: function (pageDiv, pdfPage, |
|
|
|
|
renderInteractiveForms) { |
|
|
|
|
createAnnotationLayerBuilder(pageDiv, pdfPage, |
|
|
|
|
renderInteractiveForms = false) { |
|
|
|
|
return new AnnotationLayerBuilder({ |
|
|
|
|
pageDiv: pageDiv, |
|
|
|
|
pdfPage: pdfPage, |
|
|
|
|
renderInteractiveForms: renderInteractiveForms, |
|
|
|
|
pageDiv, |
|
|
|
|
pdfPage, |
|
|
|
|
renderInteractiveForms, |
|
|
|
|
linkService: new SimpleLinkService(), |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export { |
|
|
|
|
AnnotationLayerBuilder, |
|
|
|
|