Merge pull request #4519 from yurydelendik/pdfbugclean
Cleaning up the viewer and pdfbug; fixes bugs in Stepper
This commit is contained in:
		
						commit
						a06fca142e
					
				| @ -79,6 +79,9 @@ var FontInspector = (function FontInspectorClosure() { | ||||
|       fonts = document.createElement('div'); | ||||
|       panel.appendChild(fonts); | ||||
|     }, | ||||
|     cleanup: function cleanup() { | ||||
|       fonts.textContent = ''; | ||||
|     }, | ||||
|     enabled: false, | ||||
|     get active() { | ||||
|       return active; | ||||
| @ -181,6 +184,11 @@ var StepperManager = (function StepperManagerClosure() { | ||||
|         breakPoints = JSON.parse(sessionStorage.getItem('pdfjsBreakPoints')); | ||||
|       } | ||||
|     }, | ||||
|     cleanup: function cleanup() { | ||||
|       stepperChooser.textContent = ''; | ||||
|       stepperDiv.textContent = ''; | ||||
|       steppers = []; | ||||
|     }, | ||||
|     enabled: false, | ||||
|     active: false, | ||||
|     // Stepper specific functions.
 | ||||
| @ -204,7 +212,7 @@ var StepperManager = (function StepperManagerClosure() { | ||||
|     }, | ||||
|     selectStepper: function selectStepper(pageIndex, selectPanel) { | ||||
|       if (selectPanel) { | ||||
|         this.manager.selectPanel(1); | ||||
|         this.manager.selectPanel(this); | ||||
|       } | ||||
|       for (var i = 0; i < steppers.length; ++i) { | ||||
|         var stepper = steppers[i]; | ||||
| @ -259,6 +267,33 @@ var Stepper = (function StepperClosure() { | ||||
|     'nextLineSetSpacingShowText': 2 | ||||
|   }; | ||||
| 
 | ||||
|   function simplifyArgs(args) { | ||||
|     if (typeof args === 'string') { | ||||
|       var MAX_STRING_LENGTH = 75; | ||||
|       return args.length <= MAX_STRING_LENGTH ? args : | ||||
|         args.substr(0, MAX_STRING_LENGTH) + '...'; | ||||
|     } | ||||
|     if (typeof args !== 'object' || args === null) { | ||||
|       return args; | ||||
|     } | ||||
|     if ('length' in args) { // array
 | ||||
|       var simpleArgs = [], i, ii; | ||||
|       var MAX_ITEMS = 10; | ||||
|       for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) { | ||||
|         simpleArgs.push(simplifyArgs(args[i])); | ||||
|       } | ||||
|       if (i < args.length) { | ||||
|         simpleArgs.push('...'); | ||||
|       } | ||||
|       return simpleArgs; | ||||
|     } | ||||
|     var simpleObj = {}; | ||||
|     for (var key in args) { | ||||
|       simpleObj[key] = simplifyArgs(args[key]); | ||||
|     } | ||||
|     return simpleObj; | ||||
|   } | ||||
| 
 | ||||
|   function Stepper(panel, pageIndex, initialBreakPoints) { | ||||
|     this.panel = panel; | ||||
|     this.breakPoint = 0; | ||||
| @ -291,30 +326,40 @@ var Stepper = (function StepperClosure() { | ||||
|       } | ||||
|     }, | ||||
|     updateOperatorList: function updateOperatorList(operatorList) { | ||||
|       function cboxOnClick() { | ||||
|         var x = +this.dataset.idx; | ||||
|         if (this.checked) { | ||||
|           self.breakPoints.push(x); | ||||
|         } else { | ||||
|           self.breakPoints.splice(self.breakPoints.indexOf(x), 1); | ||||
|         } | ||||
|         StepperManager.saveBreakPoints(self.pageIndex, self.breakPoints); | ||||
|       } | ||||
| 
 | ||||
|       var MAX_OPERATORS_COUNT = 15000; | ||||
|       if (this.operatorListIdx > MAX_OPERATORS_COUNT) { | ||||
|         return; | ||||
|       } | ||||
| 
 | ||||
|       var self = this; | ||||
|       for (var i = this.operatorListIdx; i < operatorList.fnArray.length; i++) { | ||||
|       var chunk = document.createDocumentFragment(); | ||||
|       var operatorsToDisplay = Math.min(MAX_OPERATORS_COUNT, | ||||
|         operatorList.fnArray.length); | ||||
|       for (var i = this.operatorListIdx; i < operatorsToDisplay; i++) { | ||||
|         var line = c('tr'); | ||||
|         line.className = 'line'; | ||||
|         line.dataset.idx = i; | ||||
|         this.table.appendChild(line); | ||||
|         chunk.appendChild(line); | ||||
|         var checked = this.breakPoints.indexOf(i) != -1; | ||||
|         var args = operatorList.argsArray[i] ? operatorList.argsArray[i] : []; | ||||
|         var args = operatorList.argsArray[i] || []; | ||||
| 
 | ||||
|         var breakCell = c('td'); | ||||
|         var cbox = c('input'); | ||||
|         cbox.type = 'checkbox'; | ||||
|         cbox.className = 'points'; | ||||
|         cbox.checked = checked; | ||||
|         cbox.onclick = (function(x) { | ||||
|           return function() { | ||||
|             if (this.checked) { | ||||
|               self.breakPoints.push(x); | ||||
|             } else { | ||||
|               self.breakPoints.splice(self.breakPoints.indexOf(x), 1); | ||||
|             } | ||||
|             StepperManager.saveBreakPoints(self.pageIndex, self.breakPoints); | ||||
|           }; | ||||
|         })(i); | ||||
|         cbox.dataset.idx = i; | ||||
|         cbox.onclick = cboxOnClick; | ||||
| 
 | ||||
|         breakCell.appendChild(cbox); | ||||
|         line.appendChild(breakCell); | ||||
| @ -341,8 +386,16 @@ var Stepper = (function StepperClosure() { | ||||
|           decArgs[glyphIndex] = newArg; | ||||
|         } | ||||
|         line.appendChild(c('td', fn)); | ||||
|         line.appendChild(c('td', JSON.stringify(decArgs))); | ||||
|         line.appendChild(c('td', JSON.stringify(simplifyArgs(decArgs)))); | ||||
|       } | ||||
|       if (operatorsToDisplay < operatorList.fnArray.length) { | ||||
|         line = c('tr'); | ||||
|         var lastCell = c('td', '...'); | ||||
|         lastCell.colspan = 4; | ||||
|         chunk.appendChild(lastCell); | ||||
|       } | ||||
|       this.operatorListIdx = operatorList.fnArray.length; | ||||
|       this.table.appendChild(chunk); | ||||
|     }, | ||||
|     getNextBreakPoint: function getNextBreakPoint() { | ||||
|       this.breakPoints.sort(function(a, b) { return a - b; }); | ||||
| @ -447,6 +500,10 @@ var Stats = (function Stats() { | ||||
|       for (var i = 0, ii = stats.length; i < ii; ++i) { | ||||
|         this.panel.appendChild(stats[i].div); | ||||
|       } | ||||
|     }, | ||||
|     cleanup: function () { | ||||
|       stats = []; | ||||
|       clear(this.panel); | ||||
|     } | ||||
|   }; | ||||
| })(); | ||||
| @ -539,7 +596,17 @@ var PDFBug = (function PDFBugClosure() { | ||||
|       } | ||||
|       this.selectPanel(0); | ||||
|     }, | ||||
|     cleanup: function cleanup() { | ||||
|       for (var i = 0, ii = this.tools.length; i < ii; i++) { | ||||
|         if (this.tools[i].enabled) { | ||||
|           this.tools[i].cleanup(); | ||||
|         } | ||||
|       } | ||||
|     }, | ||||
|     selectPanel: function selectPanel(index) { | ||||
|       if (typeof index !== 'number') { | ||||
|         index = this.tools.indexOf(index); | ||||
|       } | ||||
|       if (index === activePanel) { | ||||
|         return; | ||||
|       } | ||||
|  | ||||
| @ -546,9 +546,43 @@ var PDFView = { | ||||
| //#endif
 | ||||
|   }, | ||||
| 
 | ||||
|   close: function pdfViewClose() { | ||||
|     if (!this.pdfDocument) { | ||||
|       return; | ||||
|     } | ||||
| 
 | ||||
|     this.pdfDocument.destroy(); | ||||
|     this.pdfDocument = null; | ||||
| 
 | ||||
|     var errorWrapper = document.getElementById('errorWrapper'); | ||||
|     errorWrapper.setAttribute('hidden', 'true'); | ||||
| 
 | ||||
|     var thumbsView = document.getElementById('thumbnailView'); | ||||
|     while (thumbsView.hasChildNodes()) { | ||||
|       thumbsView.removeChild(thumbsView.lastChild); | ||||
|     } | ||||
| 
 | ||||
|     if ('_loadingInterval' in thumbsView) { | ||||
|       clearInterval(thumbsView._loadingInterval); | ||||
|     } | ||||
| 
 | ||||
|     var container = document.getElementById('viewer'); | ||||
|     while (container.hasChildNodes()) { | ||||
|       container.removeChild(container.lastChild); | ||||
|     } | ||||
| 
 | ||||
|     if (typeof PDFBug !== 'undefined') { | ||||
|       PDFBug.cleanup(); | ||||
|     } | ||||
|   }, | ||||
| 
 | ||||
|   // TODO(mack): This function signature should really be pdfViewOpen(url, args)
 | ||||
|   open: function pdfViewOpen(url, scale, password, | ||||
|                              pdfDataRangeTransport, args) { | ||||
|     if (this.pdfDocument) { | ||||
|       this.close(); | ||||
|     } | ||||
| 
 | ||||
|     var parameters = {password: password}; | ||||
|     if (typeof url === 'string') { // URL
 | ||||
|       this.setTitleUsingUrl(url); | ||||
| @ -562,11 +596,6 @@ var PDFView = { | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     // Terminate worker of the previous document if any.
 | ||||
|     if (this.pdfDocument) { | ||||
|       this.pdfDocument.destroy(); | ||||
|     } | ||||
|     this.pdfDocument = null; | ||||
|     var self = this; | ||||
|     self.loading = true; | ||||
|     var passwordNeeded = function passwordNeeded(updatePassword, reason) { | ||||
| @ -858,31 +887,12 @@ var PDFView = { | ||||
| 
 | ||||
|     this.pdfDocument = pdfDocument; | ||||
| 
 | ||||
|     var errorWrapper = document.getElementById('errorWrapper'); | ||||
|     errorWrapper.setAttribute('hidden', 'true'); | ||||
| 
 | ||||
|     pdfDocument.getDownloadInfo().then(function() { | ||||
|       PDFView.loadingBar.hide(); | ||||
|       var outerContainer = document.getElementById('outerContainer'); | ||||
|       outerContainer.classList.remove('loadingInProgress'); | ||||
|     }); | ||||
| 
 | ||||
|     var thumbsView = document.getElementById('thumbnailView'); | ||||
|     thumbsView.parentNode.scrollTop = 0; | ||||
| 
 | ||||
|     while (thumbsView.hasChildNodes()) { | ||||
|       thumbsView.removeChild(thumbsView.lastChild); | ||||
|     } | ||||
| 
 | ||||
|     if ('_loadingInterval' in thumbsView) { | ||||
|       clearInterval(thumbsView._loadingInterval); | ||||
|     } | ||||
| 
 | ||||
|     var container = document.getElementById('viewer'); | ||||
|     while (container.hasChildNodes()) { | ||||
|       container.removeChild(container.lastChild); | ||||
|     } | ||||
| 
 | ||||
|     var pagesCount = pdfDocument.numPages; | ||||
| 
 | ||||
|     var id = pdfDocument.fingerprint; | ||||
| @ -907,6 +917,8 @@ var PDFView = { | ||||
|     this.pagesPromise = pagesPromise; | ||||
| 
 | ||||
|     var firstPagePromise = pdfDocument.getPage(1); | ||||
|     var container = document.getElementById('viewer'); | ||||
|     var thumbsView = document.getElementById('thumbnailView'); | ||||
| 
 | ||||
|     // Fetch a single page so we can get a viewport that will be the default
 | ||||
|     // viewport for all pages
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user