2014-12-01 05:42:47 -05:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
|
|
|
|
2016-10-14 07:00:47 -04:00
|
|
|
# uses the PDFJS text layer renderer to provide invisible overlayed
|
|
|
|
# text for searching
|
2014-12-01 05:42:47 -05:00
|
|
|
|
2016-10-14 07:00:47 -04:00
|
|
|
App.factory 'pdfTextLayer', [ () ->
|
2014-12-01 05:42:47 -05:00
|
|
|
|
|
|
|
class pdfTextLayer
|
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
@textLayerDiv = options.textLayerDiv
|
|
|
|
@divContentDone = false
|
|
|
|
@viewport = options.viewport
|
|
|
|
@textDivs = []
|
2016-10-14 07:00:47 -04:00
|
|
|
@renderer = options.renderer
|
|
|
|
@renderingDone = false
|
2014-12-01 05:42:47 -05:00
|
|
|
|
2016-10-14 07:00:47 -04:00
|
|
|
render: (timeout) ->
|
|
|
|
if @renderingDone or not @divContentDone
|
|
|
|
return
|
2014-12-01 05:42:47 -05:00
|
|
|
|
2016-10-14 07:00:47 -04:00
|
|
|
if @textLayerRenderTask?
|
|
|
|
@textLayerRenderTask.cancel()
|
|
|
|
@textLayerRenderTask = null
|
2014-12-01 05:42:47 -05:00
|
|
|
|
2016-10-14 07:00:47 -04:00
|
|
|
@textDivs = []
|
|
|
|
textLayerFrag = document.createDocumentFragment()
|
2014-12-01 05:42:47 -05:00
|
|
|
|
2016-10-14 07:00:47 -04:00
|
|
|
@textLayerRenderTask = @renderer {
|
|
|
|
textContent: this.textContent,
|
|
|
|
container: textLayerFrag,
|
|
|
|
viewport: this.viewport,
|
|
|
|
textDivs: this.textDivs,
|
|
|
|
timeout: timeout,
|
|
|
|
enhanceTextSelection: this.enhanceTextSelection,
|
|
|
|
}
|
2014-12-01 05:42:47 -05:00
|
|
|
|
2016-10-14 07:00:47 -04:00
|
|
|
textLayerSuccess = () =>
|
|
|
|
@textLayerDiv.appendChild(textLayerFrag)
|
|
|
|
@renderingDone = true
|
2014-12-05 09:33:06 -05:00
|
|
|
|
2016-10-14 07:00:47 -04:00
|
|
|
textLayerFailure = () ->
|
|
|
|
return # canceled or failed to render text layer -- skipping errors
|
2014-12-01 05:42:47 -05:00
|
|
|
|
2016-10-14 07:00:47 -04:00
|
|
|
@textLayerRenderTask.promise.then(textLayerSuccess, textLayerFailure)
|
2014-12-01 05:42:47 -05:00
|
|
|
|
|
|
|
setTextContent: (textContent) ->
|
2016-10-14 07:00:47 -04:00
|
|
|
if (@textLayerRenderTask)
|
|
|
|
@textLayerRenderTask.cancel();
|
|
|
|
@textLayerRenderTask = null;
|
2014-12-01 05:42:47 -05:00
|
|
|
|
2016-10-14 07:00:47 -04:00
|
|
|
@textContent = textContent;
|
|
|
|
@divContentDone = true;
|
2014-12-01 05:42:47 -05:00
|
|
|
|
|
|
|
]
|