|
|
|
@ -18,8 +18,7 @@
@@ -18,8 +18,7 @@
|
|
|
|
|
(function (root, factory) { |
|
|
|
|
if (typeof define === 'function' && define.amd) { |
|
|
|
|
define('pdfjs-web/text_layer_builder', ['exports', 'pdfjs-web/dom_events', |
|
|
|
|
'pdfjs-web/pdfjs'], |
|
|
|
|
factory); |
|
|
|
|
'pdfjs-web/pdfjs'], factory); |
|
|
|
|
} else if (typeof exports !== 'undefined') { |
|
|
|
|
factory(exports, require('./dom_events.js'), require('./pdfjs.js')); |
|
|
|
|
} else { |
|
|
|
@ -52,8 +51,8 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
@@ -52,8 +51,8 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|
|
|
|
function TextLayerBuilder(options) { |
|
|
|
|
this.textLayerDiv = options.textLayerDiv; |
|
|
|
|
this.eventBus = options.eventBus || domEvents.getGlobalEventBus(); |
|
|
|
|
this.textContent = null; |
|
|
|
|
this.renderingDone = false; |
|
|
|
|
this.divContentDone = false; |
|
|
|
|
this.pageIdx = options.pageIndex; |
|
|
|
|
this.pageNumber = this.pageIdx + 1; |
|
|
|
|
this.matches = []; |
|
|
|
@ -66,6 +65,9 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
@@ -66,6 +65,9 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TextLayerBuilder.prototype = { |
|
|
|
|
/** |
|
|
|
|
* @private |
|
|
|
|
*/ |
|
|
|
|
_finishRendering: function TextLayerBuilder_finishRendering() { |
|
|
|
|
this.renderingDone = true; |
|
|
|
|
|
|
|
|
@ -77,7 +79,8 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
@@ -77,7 +79,8 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|
|
|
|
|
|
|
|
|
this.eventBus.dispatch('textlayerrendered', { |
|
|
|
|
source: this, |
|
|
|
|
pageNumber: this.pageNumber |
|
|
|
|
pageNumber: this.pageNumber, |
|
|
|
|
numTextDivs: this.textDivs.length, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
@ -87,14 +90,10 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
@@ -87,14 +90,10 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|
|
|
|
* for specified amount of ms. |
|
|
|
|
*/ |
|
|
|
|
render: function TextLayerBuilder_render(timeout) { |
|
|
|
|
if (!this.divContentDone || this.renderingDone) { |
|
|
|
|
if (!this.textContent || this.renderingDone) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.textLayerRenderTask) { |
|
|
|
|
this.textLayerRenderTask.cancel(); |
|
|
|
|
this.textLayerRenderTask = null; |
|
|
|
|
} |
|
|
|
|
this.cancel(); |
|
|
|
|
|
|
|
|
|
this.textDivs = []; |
|
|
|
|
var textLayerFrag = document.createDocumentFragment(); |
|
|
|
@ -111,17 +110,23 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
@@ -111,17 +110,23 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|
|
|
|
this._finishRendering(); |
|
|
|
|
this.updateMatches(); |
|
|
|
|
}.bind(this), function (reason) { |
|
|
|
|
// canceled or failed to render text layer -- skipping errors
|
|
|
|
|
// cancelled or failed to render text layer -- skipping errors
|
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
setTextContent: function TextLayerBuilder_setTextContent(textContent) { |
|
|
|
|
/** |
|
|
|
|
* Cancels rendering of the text layer. |
|
|
|
|
*/ |
|
|
|
|
cancel: function TextLayerBuilder_cancel() { |
|
|
|
|
if (this.textLayerRenderTask) { |
|
|
|
|
this.textLayerRenderTask.cancel(); |
|
|
|
|
this.textLayerRenderTask = null; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
setTextContent: function TextLayerBuilder_setTextContent(textContent) { |
|
|
|
|
this.cancel(); |
|
|
|
|
this.textContent = textContent; |
|
|
|
|
this.divContentDone = true; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
convertMatches: function TextLayerBuilder_convertMatches(matches, |
|
|
|
@ -324,6 +329,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
@@ -324,6 +329,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|
|
|
|
var div = this.textLayerDiv; |
|
|
|
|
var self = this; |
|
|
|
|
var expandDivsTimer = null; |
|
|
|
|
|
|
|
|
|
div.addEventListener('mousedown', function (e) { |
|
|
|
|
if (self.enhanceTextSelection && self.textLayerRenderTask) { |
|
|
|
|
self.textLayerRenderTask.expandTextDivs(true); |
|
|
|
@ -357,11 +363,14 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
@@ -357,11 +363,14 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|
|
|
|
//#endif
|
|
|
|
|
end.classList.add('active'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
div.addEventListener('mouseup', function (e) { |
|
|
|
|
if (self.enhanceTextSelection && self.textLayerRenderTask) { |
|
|
|
|
//#if !(MOZCENTRAL || FIREFOX)
|
|
|
|
|
expandDivsTimer = setTimeout(function() { |
|
|
|
|
self.textLayerRenderTask.expandTextDivs(false); |
|
|
|
|
if (self.textLayerRenderTask) { |
|
|
|
|
self.textLayerRenderTask.expandTextDivs(false); |
|
|
|
|
} |
|
|
|
|
expandDivsTimer = null; |
|
|
|
|
}, EXPAND_DIVS_TIMEOUT); |
|
|
|
|
//#else
|
|
|
|
|