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');
|
fonts = document.createElement('div');
|
||||||
panel.appendChild(fonts);
|
panel.appendChild(fonts);
|
||||||
},
|
},
|
||||||
|
cleanup: function cleanup() {
|
||||||
|
fonts.textContent = '';
|
||||||
|
},
|
||||||
enabled: false,
|
enabled: false,
|
||||||
get active() {
|
get active() {
|
||||||
return active;
|
return active;
|
||||||
@ -181,6 +184,11 @@ var StepperManager = (function StepperManagerClosure() {
|
|||||||
breakPoints = JSON.parse(sessionStorage.getItem('pdfjsBreakPoints'));
|
breakPoints = JSON.parse(sessionStorage.getItem('pdfjsBreakPoints'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
cleanup: function cleanup() {
|
||||||
|
stepperChooser.textContent = '';
|
||||||
|
stepperDiv.textContent = '';
|
||||||
|
steppers = [];
|
||||||
|
},
|
||||||
enabled: false,
|
enabled: false,
|
||||||
active: false,
|
active: false,
|
||||||
// Stepper specific functions.
|
// Stepper specific functions.
|
||||||
@ -204,7 +212,7 @@ var StepperManager = (function StepperManagerClosure() {
|
|||||||
},
|
},
|
||||||
selectStepper: function selectStepper(pageIndex, selectPanel) {
|
selectStepper: function selectStepper(pageIndex, selectPanel) {
|
||||||
if (selectPanel) {
|
if (selectPanel) {
|
||||||
this.manager.selectPanel(1);
|
this.manager.selectPanel(this);
|
||||||
}
|
}
|
||||||
for (var i = 0; i < steppers.length; ++i) {
|
for (var i = 0; i < steppers.length; ++i) {
|
||||||
var stepper = steppers[i];
|
var stepper = steppers[i];
|
||||||
@ -259,6 +267,33 @@ var Stepper = (function StepperClosure() {
|
|||||||
'nextLineSetSpacingShowText': 2
|
'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) {
|
function Stepper(panel, pageIndex, initialBreakPoints) {
|
||||||
this.panel = panel;
|
this.panel = panel;
|
||||||
this.breakPoint = 0;
|
this.breakPoint = 0;
|
||||||
@ -291,30 +326,40 @@ var Stepper = (function StepperClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateOperatorList: function updateOperatorList(operatorList) {
|
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;
|
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');
|
var line = c('tr');
|
||||||
line.className = 'line';
|
line.className = 'line';
|
||||||
line.dataset.idx = i;
|
line.dataset.idx = i;
|
||||||
this.table.appendChild(line);
|
chunk.appendChild(line);
|
||||||
var checked = this.breakPoints.indexOf(i) != -1;
|
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 breakCell = c('td');
|
||||||
var cbox = c('input');
|
var cbox = c('input');
|
||||||
cbox.type = 'checkbox';
|
cbox.type = 'checkbox';
|
||||||
cbox.className = 'points';
|
cbox.className = 'points';
|
||||||
cbox.checked = checked;
|
cbox.checked = checked;
|
||||||
cbox.onclick = (function(x) {
|
cbox.dataset.idx = i;
|
||||||
return function() {
|
cbox.onclick = cboxOnClick;
|
||||||
if (this.checked) {
|
|
||||||
self.breakPoints.push(x);
|
|
||||||
} else {
|
|
||||||
self.breakPoints.splice(self.breakPoints.indexOf(x), 1);
|
|
||||||
}
|
|
||||||
StepperManager.saveBreakPoints(self.pageIndex, self.breakPoints);
|
|
||||||
};
|
|
||||||
})(i);
|
|
||||||
|
|
||||||
breakCell.appendChild(cbox);
|
breakCell.appendChild(cbox);
|
||||||
line.appendChild(breakCell);
|
line.appendChild(breakCell);
|
||||||
@ -341,8 +386,16 @@ var Stepper = (function StepperClosure() {
|
|||||||
decArgs[glyphIndex] = newArg;
|
decArgs[glyphIndex] = newArg;
|
||||||
}
|
}
|
||||||
line.appendChild(c('td', fn));
|
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() {
|
getNextBreakPoint: function getNextBreakPoint() {
|
||||||
this.breakPoints.sort(function(a, b) { return a - b; });
|
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) {
|
for (var i = 0, ii = stats.length; i < ii; ++i) {
|
||||||
this.panel.appendChild(stats[i].div);
|
this.panel.appendChild(stats[i].div);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
cleanup: function () {
|
||||||
|
stats = [];
|
||||||
|
clear(this.panel);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
@ -539,7 +596,17 @@ var PDFBug = (function PDFBugClosure() {
|
|||||||
}
|
}
|
||||||
this.selectPanel(0);
|
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) {
|
selectPanel: function selectPanel(index) {
|
||||||
|
if (typeof index !== 'number') {
|
||||||
|
index = this.tools.indexOf(index);
|
||||||
|
}
|
||||||
if (index === activePanel) {
|
if (index === activePanel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -546,9 +546,43 @@ var PDFView = {
|
|||||||
//#endif
|
//#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)
|
// TODO(mack): This function signature should really be pdfViewOpen(url, args)
|
||||||
open: function pdfViewOpen(url, scale, password,
|
open: function pdfViewOpen(url, scale, password,
|
||||||
pdfDataRangeTransport, args) {
|
pdfDataRangeTransport, args) {
|
||||||
|
if (this.pdfDocument) {
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
|
|
||||||
var parameters = {password: password};
|
var parameters = {password: password};
|
||||||
if (typeof url === 'string') { // URL
|
if (typeof url === 'string') { // URL
|
||||||
this.setTitleUsingUrl(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;
|
var self = this;
|
||||||
self.loading = true;
|
self.loading = true;
|
||||||
var passwordNeeded = function passwordNeeded(updatePassword, reason) {
|
var passwordNeeded = function passwordNeeded(updatePassword, reason) {
|
||||||
@ -858,31 +887,12 @@ var PDFView = {
|
|||||||
|
|
||||||
this.pdfDocument = pdfDocument;
|
this.pdfDocument = pdfDocument;
|
||||||
|
|
||||||
var errorWrapper = document.getElementById('errorWrapper');
|
|
||||||
errorWrapper.setAttribute('hidden', 'true');
|
|
||||||
|
|
||||||
pdfDocument.getDownloadInfo().then(function() {
|
pdfDocument.getDownloadInfo().then(function() {
|
||||||
PDFView.loadingBar.hide();
|
PDFView.loadingBar.hide();
|
||||||
var outerContainer = document.getElementById('outerContainer');
|
var outerContainer = document.getElementById('outerContainer');
|
||||||
outerContainer.classList.remove('loadingInProgress');
|
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 pagesCount = pdfDocument.numPages;
|
||||||
|
|
||||||
var id = pdfDocument.fingerprint;
|
var id = pdfDocument.fingerprint;
|
||||||
@ -907,6 +917,8 @@ var PDFView = {
|
|||||||
this.pagesPromise = pagesPromise;
|
this.pagesPromise = pagesPromise;
|
||||||
|
|
||||||
var firstPagePromise = pdfDocument.getPage(1);
|
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
|
// Fetch a single page so we can get a viewport that will be the default
|
||||||
// viewport for all pages
|
// viewport for all pages
|
||||||
|
Loading…
x
Reference in New Issue
Block a user