Convert the text layer builder to a class
This commit is contained in:
		
							parent
							
								
									2a052c4aad
								
							
						
					
					
						commit
						a968da8887
					
				| @ -28,7 +28,8 @@ var RENDER_DELAY = 200; // ms | ||||
|  * contain text that matches the PDF text they are overlaying. This object | ||||
|  * also provides a way to highlight text that is being searched for. | ||||
|  */ | ||||
| var TextLayerBuilder = function textLayerBuilder(options) { | ||||
| var TextLayerBuilder = (function TextLayerBuilderClosure() { | ||||
|   function TextLayerBuilder(options) { | ||||
|     this.textLayerDiv = options.textLayerDiv; | ||||
|     this.layoutDone = false; | ||||
|     this.divContentDone = false; | ||||
| @ -42,8 +43,10 @@ var TextLayerBuilder = function textLayerBuilder(options) { | ||||
|     if (typeof PDFFindController === 'undefined') { | ||||
|       window.PDFFindController = null; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   this.renderLayer = function textLayerBuilder_renderLayer() { | ||||
|   TextLayerBuilder.prototype = { | ||||
|     renderLayer: function TextLayerBuilder_renderLayer() { | ||||
|       var textLayerFrag = document.createDocumentFragment(); | ||||
|       var textDivs = this.textDivs; | ||||
|       var textDivsLength = textDivs.length; | ||||
| @ -78,10 +81,10 @@ var TextLayerBuilder = function textLayerBuilder(options) { | ||||
|       this.textLayerDiv.appendChild(textLayerFrag); | ||||
|       this.renderingDone = true; | ||||
|       this.updateMatches(); | ||||
|   }; | ||||
|     }, | ||||
| 
 | ||||
|   this.setupRenderLayoutTimer = | ||||
|     function textLayerBuilder_setupRenderLayoutTimer() { | ||||
|     setupRenderLayoutTimer: | ||||
|         function TextLayerBuilder_setupRenderLayoutTimer() { | ||||
|       // Schedule renderLayout() if the user has been scrolling,
 | ||||
|       // otherwise run it right away.
 | ||||
|       var self = this; | ||||
| @ -98,9 +101,9 @@ var TextLayerBuilder = function textLayerBuilder(options) { | ||||
|           self.setupRenderLayoutTimer(); | ||||
|         }, RENDER_DELAY); | ||||
|       } | ||||
|   }; | ||||
|     }, | ||||
| 
 | ||||
|   this.appendText = function textLayerBuilder_appendText(geom, styles) { | ||||
|     appendText: function TextLayerBuilder_appendText(geom, styles) { | ||||
|       var style = styles[geom.fontName]; | ||||
|       var textDiv = document.createElement('div'); | ||||
|       this.textDivs.push(textDiv); | ||||
| @ -131,9 +134,9 @@ var TextLayerBuilder = function textLayerBuilder(options) { | ||||
|       } else { | ||||
|         textDiv.dataset.canvasWidth = geom.width * this.viewport.scale; | ||||
|       } | ||||
|   }; | ||||
|     }, | ||||
| 
 | ||||
|   this.setTextContent = function textLayerBuilder_setTextContent(textContent) { | ||||
|     setTextContent: function TextLayerBuilder_setTextContent(textContent) { | ||||
|       this.textContent = textContent; | ||||
| 
 | ||||
|       var textItems = textContent.items; | ||||
| @ -142,9 +145,9 @@ var TextLayerBuilder = function textLayerBuilder(options) { | ||||
|       } | ||||
|       this.divContentDone = true; | ||||
|       this.setupRenderLayoutTimer(); | ||||
|   }; | ||||
|     }, | ||||
| 
 | ||||
|   this.convertMatches = function textLayerBuilder_convertMatches(matches) { | ||||
|     convertMatches: function TextLayerBuilder_convertMatches(matches) { | ||||
|       var i = 0; | ||||
|       var iIndex = 0; | ||||
|       var bidiTexts = this.textContent.items; | ||||
| @ -192,9 +195,9 @@ var TextLayerBuilder = function textLayerBuilder(options) { | ||||
|       } | ||||
| 
 | ||||
|       return ret; | ||||
|   }; | ||||
|     }, | ||||
| 
 | ||||
|   this.renderMatches = function textLayerBuilder_renderMatches(matches) { | ||||
|     renderMatches: function TextLayerBuilder_renderMatches(matches) { | ||||
|       // Early exit if there is nothing to render.
 | ||||
|       if (matches.length === 0) { | ||||
|         return; | ||||
| @ -285,9 +288,9 @@ var TextLayerBuilder = function textLayerBuilder(options) { | ||||
|       if (prevEnd) { | ||||
|         appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset); | ||||
|       } | ||||
|   }; | ||||
|     }, | ||||
| 
 | ||||
|   this.updateMatches = function textLayerBuilder_updateMatches() { | ||||
|     updateMatches: function TextLayerBuilder_updateMatches() { | ||||
|       // Only show matches when all rendering is done.
 | ||||
|       if (!this.renderingDone) { | ||||
|         return; | ||||
| @ -320,6 +323,8 @@ var TextLayerBuilder = function textLayerBuilder(options) { | ||||
|       this.matches = this.convertMatches(PDFFindController === null ? | ||||
|         [] : (PDFFindController.pageMatches[this.pageIdx] || [])); | ||||
|       this.renderMatches(this.matches); | ||||
|     } | ||||
|   }; | ||||
| }; | ||||
|   return TextLayerBuilder; | ||||
| })(); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user