2015-03-07 19:41:19 +00:00
|
|
|
/* Copyright 2012 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2019-01-23 08:49:30 +00:00
|
|
|
/* eslint-disable no-var */
|
2015-03-07 19:41:19 +00:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var FontInspector = (function FontInspectorClosure() {
|
2019-01-23 08:49:30 +00:00
|
|
|
var fonts, createObjectURL;
|
2015-03-07 19:41:19 +00:00
|
|
|
var active = false;
|
|
|
|
var fontAttribute = 'data-font-name';
|
|
|
|
function removeSelection() {
|
2019-01-23 08:49:30 +00:00
|
|
|
let divs = document.querySelectorAll(`span[${fontAttribute}]`);
|
|
|
|
for (let div of divs) {
|
2015-03-07 19:41:19 +00:00
|
|
|
div.className = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function resetSelection() {
|
2019-01-23 08:49:30 +00:00
|
|
|
let divs = document.querySelectorAll(`span[${fontAttribute}]`);
|
|
|
|
for (let div of divs) {
|
2015-03-07 19:41:19 +00:00
|
|
|
div.className = 'debuggerHideText';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function selectFont(fontName, show) {
|
2019-01-23 08:49:30 +00:00
|
|
|
let divs = document.querySelectorAll(`span[${fontAttribute}=${fontName}]`);
|
|
|
|
for (let div of divs) {
|
2015-03-07 19:41:19 +00:00
|
|
|
div.className = show ? 'debuggerShowText' : 'debuggerHideText';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function textLayerClick(e) {
|
2016-01-03 13:38:30 +00:00
|
|
|
if (!e.target.dataset.fontName ||
|
2019-01-23 08:49:30 +00:00
|
|
|
e.target.tagName.toUpperCase() !== 'SPAN') {
|
2015-03-07 19:41:19 +00:00
|
|
|
return;
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
2015-03-07 19:41:19 +00:00
|
|
|
var fontName = e.target.dataset.fontName;
|
|
|
|
var selects = document.getElementsByTagName('input');
|
|
|
|
for (var i = 0; i < selects.length; ++i) {
|
|
|
|
var select = selects[i];
|
2016-01-03 13:38:30 +00:00
|
|
|
if (select.dataset.fontName !== fontName) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-03-07 19:41:19 +00:00
|
|
|
select.checked = !select.checked;
|
|
|
|
selectFont(fontName, select.checked);
|
|
|
|
select.scrollIntoView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
// Properties/functions needed by PDFBug.
|
|
|
|
id: 'FontInspector',
|
|
|
|
name: 'Font Inspector',
|
|
|
|
panel: null,
|
|
|
|
manager: null,
|
2019-01-23 08:49:30 +00:00
|
|
|
init: function init(pdfjsLib) {
|
2015-03-07 19:41:19 +00:00
|
|
|
var panel = this.panel;
|
|
|
|
panel.setAttribute('style', 'padding: 5px;');
|
|
|
|
var tmp = document.createElement('button');
|
|
|
|
tmp.addEventListener('click', resetSelection);
|
|
|
|
tmp.textContent = 'Refresh';
|
|
|
|
panel.appendChild(tmp);
|
|
|
|
|
|
|
|
fonts = document.createElement('div');
|
|
|
|
panel.appendChild(fonts);
|
2019-01-23 08:49:30 +00:00
|
|
|
|
|
|
|
createObjectURL = pdfjsLib.createObjectURL;
|
2015-03-07 19:41:19 +00:00
|
|
|
},
|
2016-01-03 13:38:30 +00:00
|
|
|
cleanup: function cleanup() {
|
|
|
|
fonts.textContent = '';
|
|
|
|
},
|
2015-03-07 19:41:19 +00:00
|
|
|
enabled: false,
|
|
|
|
get active() {
|
|
|
|
return active;
|
|
|
|
},
|
|
|
|
set active(value) {
|
|
|
|
active = value;
|
|
|
|
if (active) {
|
|
|
|
document.body.addEventListener('click', textLayerClick, true);
|
|
|
|
resetSelection();
|
|
|
|
} else {
|
|
|
|
document.body.removeEventListener('click', textLayerClick, true);
|
|
|
|
removeSelection();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// FontInspector specific functions.
|
|
|
|
fontAdded: function fontAdded(fontObj, url) {
|
|
|
|
function properties(obj, list) {
|
|
|
|
var moreInfo = document.createElement('table');
|
|
|
|
for (var i = 0; i < list.length; i++) {
|
|
|
|
var tr = document.createElement('tr');
|
|
|
|
var td1 = document.createElement('td');
|
|
|
|
td1.textContent = list[i];
|
|
|
|
tr.appendChild(td1);
|
|
|
|
var td2 = document.createElement('td');
|
|
|
|
td2.textContent = obj[list[i]].toString();
|
|
|
|
tr.appendChild(td2);
|
|
|
|
moreInfo.appendChild(tr);
|
|
|
|
}
|
|
|
|
return moreInfo;
|
|
|
|
}
|
|
|
|
var moreInfo = properties(fontObj, ['name', 'type']);
|
|
|
|
var fontName = fontObj.loadedName;
|
|
|
|
var font = document.createElement('div');
|
|
|
|
var name = document.createElement('span');
|
|
|
|
name.textContent = fontName;
|
|
|
|
var download = document.createElement('a');
|
2016-01-03 13:38:30 +00:00
|
|
|
if (url) {
|
|
|
|
url = /url\(['"]?([^\)"']+)/.exec(url);
|
|
|
|
download.href = url[1];
|
|
|
|
} else if (fontObj.data) {
|
2019-01-23 08:49:30 +00:00
|
|
|
download.href = createObjectURL(fontObj.data, fontObj.mimeType);
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
2015-03-07 19:41:19 +00:00
|
|
|
download.textContent = 'Download';
|
|
|
|
var logIt = document.createElement('a');
|
|
|
|
logIt.href = '';
|
|
|
|
logIt.textContent = 'Log';
|
|
|
|
logIt.addEventListener('click', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
console.log(fontObj);
|
|
|
|
});
|
|
|
|
var select = document.createElement('input');
|
|
|
|
select.setAttribute('type', 'checkbox');
|
|
|
|
select.dataset.fontName = fontName;
|
|
|
|
select.addEventListener('click', (function(select, fontName) {
|
|
|
|
return (function() {
|
|
|
|
selectFont(fontName, select.checked);
|
|
|
|
});
|
|
|
|
})(select, fontName));
|
|
|
|
font.appendChild(select);
|
|
|
|
font.appendChild(name);
|
|
|
|
font.appendChild(document.createTextNode(' '));
|
|
|
|
font.appendChild(download);
|
|
|
|
font.appendChild(document.createTextNode(' '));
|
|
|
|
font.appendChild(logIt);
|
|
|
|
font.appendChild(moreInfo);
|
|
|
|
fonts.appendChild(font);
|
|
|
|
// Somewhat of a hack, should probably add a hook for when the text layer
|
|
|
|
// is done rendering.
|
2019-01-23 08:49:30 +00:00
|
|
|
setTimeout(() => {
|
2016-01-03 13:38:30 +00:00
|
|
|
if (this.active) {
|
2015-03-07 19:41:19 +00:00
|
|
|
resetSelection();
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
2019-01-23 08:49:30 +00:00
|
|
|
}, 2000);
|
|
|
|
},
|
2015-03-07 19:41:19 +00:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2019-01-23 08:49:30 +00:00
|
|
|
var opMap;
|
|
|
|
|
2015-03-07 19:41:19 +00:00
|
|
|
// Manages all the page steppers.
|
|
|
|
var StepperManager = (function StepperManagerClosure() {
|
|
|
|
var steppers = [];
|
|
|
|
var stepperDiv = null;
|
|
|
|
var stepperControls = null;
|
|
|
|
var stepperChooser = null;
|
2019-01-23 08:49:30 +00:00
|
|
|
var breakPoints = Object.create(null);
|
2015-03-07 19:41:19 +00:00
|
|
|
return {
|
|
|
|
// Properties/functions needed by PDFBug.
|
|
|
|
id: 'Stepper',
|
|
|
|
name: 'Stepper',
|
|
|
|
panel: null,
|
|
|
|
manager: null,
|
2019-01-23 08:49:30 +00:00
|
|
|
init: function init(pdfjsLib) {
|
2015-03-07 19:41:19 +00:00
|
|
|
var self = this;
|
|
|
|
this.panel.setAttribute('style', 'padding: 5px;');
|
|
|
|
stepperControls = document.createElement('div');
|
|
|
|
stepperChooser = document.createElement('select');
|
|
|
|
stepperChooser.addEventListener('change', function(event) {
|
|
|
|
self.selectStepper(this.value);
|
|
|
|
});
|
|
|
|
stepperControls.appendChild(stepperChooser);
|
|
|
|
stepperDiv = document.createElement('div');
|
|
|
|
this.panel.appendChild(stepperControls);
|
|
|
|
this.panel.appendChild(stepperDiv);
|
2016-01-03 13:38:30 +00:00
|
|
|
if (sessionStorage.getItem('pdfjsBreakPoints')) {
|
2015-03-07 19:41:19 +00:00
|
|
|
breakPoints = JSON.parse(sessionStorage.getItem('pdfjsBreakPoints'));
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
2019-01-23 08:49:30 +00:00
|
|
|
|
|
|
|
opMap = Object.create(null);
|
|
|
|
for (var key in pdfjsLib.OPS) {
|
|
|
|
opMap[pdfjsLib.OPS[key]] = key;
|
|
|
|
}
|
2016-01-03 13:38:30 +00:00
|
|
|
},
|
|
|
|
cleanup: function cleanup() {
|
|
|
|
stepperChooser.textContent = '';
|
|
|
|
stepperDiv.textContent = '';
|
|
|
|
steppers = [];
|
2015-03-07 19:41:19 +00:00
|
|
|
},
|
|
|
|
enabled: false,
|
|
|
|
active: false,
|
|
|
|
// Stepper specific functions.
|
|
|
|
create: function create(pageIndex) {
|
|
|
|
var debug = document.createElement('div');
|
|
|
|
debug.id = 'stepper' + pageIndex;
|
|
|
|
debug.setAttribute('hidden', true);
|
|
|
|
debug.className = 'stepper';
|
|
|
|
stepperDiv.appendChild(debug);
|
|
|
|
var b = document.createElement('option');
|
|
|
|
b.textContent = 'Page ' + (pageIndex + 1);
|
|
|
|
b.value = pageIndex;
|
|
|
|
stepperChooser.appendChild(b);
|
|
|
|
var initBreakPoints = breakPoints[pageIndex] || [];
|
|
|
|
var stepper = new Stepper(debug, pageIndex, initBreakPoints);
|
|
|
|
steppers.push(stepper);
|
2016-01-03 13:38:30 +00:00
|
|
|
if (steppers.length === 1) {
|
2015-03-07 19:41:19 +00:00
|
|
|
this.selectStepper(pageIndex, false);
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
2015-03-07 19:41:19 +00:00
|
|
|
return stepper;
|
|
|
|
},
|
|
|
|
selectStepper: function selectStepper(pageIndex, selectPanel) {
|
2016-01-03 13:38:30 +00:00
|
|
|
var i;
|
|
|
|
pageIndex = pageIndex | 0;
|
|
|
|
if (selectPanel) {
|
|
|
|
this.manager.selectPanel(this);
|
|
|
|
}
|
|
|
|
for (i = 0; i < steppers.length; ++i) {
|
2015-03-07 19:41:19 +00:00
|
|
|
var stepper = steppers[i];
|
2016-01-03 13:38:30 +00:00
|
|
|
if (stepper.pageIndex === pageIndex) {
|
2015-03-07 19:41:19 +00:00
|
|
|
stepper.panel.removeAttribute('hidden');
|
2016-01-03 13:38:30 +00:00
|
|
|
} else {
|
2015-03-07 19:41:19 +00:00
|
|
|
stepper.panel.setAttribute('hidden', true);
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
2015-03-07 19:41:19 +00:00
|
|
|
}
|
|
|
|
var options = stepperChooser.options;
|
2016-01-03 13:38:30 +00:00
|
|
|
for (i = 0; i < options.length; ++i) {
|
2015-03-07 19:41:19 +00:00
|
|
|
var option = options[i];
|
2016-01-03 13:38:30 +00:00
|
|
|
option.selected = (option.value | 0) === pageIndex;
|
2015-03-07 19:41:19 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
saveBreakPoints: function saveBreakPoints(pageIndex, bps) {
|
|
|
|
breakPoints[pageIndex] = bps;
|
|
|
|
sessionStorage.setItem('pdfjsBreakPoints', JSON.stringify(breakPoints));
|
2019-01-23 08:49:30 +00:00
|
|
|
},
|
2015-03-07 19:41:19 +00:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
// The stepper for each page's IRQueue.
|
|
|
|
var Stepper = (function StepperClosure() {
|
|
|
|
// Shorter way to create element and optionally set textContent.
|
|
|
|
function c(tag, textContent) {
|
|
|
|
var d = document.createElement(tag);
|
2016-01-03 13:38:30 +00:00
|
|
|
if (textContent) {
|
2015-03-07 19:41:19 +00:00
|
|
|
d.textContent = textContent;
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
2015-03-07 19:41:19 +00:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2016-01-03 13:38:30 +00:00
|
|
|
function simplifyArgs(args) {
|
|
|
|
if (typeof args === 'string') {
|
|
|
|
var MAX_STRING_LENGTH = 75;
|
|
|
|
return args.length <= MAX_STRING_LENGTH ? args :
|
2019-01-23 08:49:30 +00:00
|
|
|
args.substring(0, MAX_STRING_LENGTH) + '...';
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
|
|
|
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('...');
|
2015-03-07 19:41:19 +00:00
|
|
|
}
|
2016-01-03 13:38:30 +00:00
|
|
|
return simpleArgs;
|
|
|
|
}
|
|
|
|
var simpleObj = {};
|
|
|
|
for (var key in args) {
|
|
|
|
simpleObj[key] = simplifyArgs(args[key]);
|
2015-03-07 19:41:19 +00:00
|
|
|
}
|
2016-01-03 13:38:30 +00:00
|
|
|
return simpleObj;
|
2015-03-07 19:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function Stepper(panel, pageIndex, initialBreakPoints) {
|
|
|
|
this.panel = panel;
|
|
|
|
this.breakPoint = 0;
|
|
|
|
this.nextBreakPoint = null;
|
|
|
|
this.pageIndex = pageIndex;
|
|
|
|
this.breakPoints = initialBreakPoints;
|
|
|
|
this.currentIdx = -1;
|
|
|
|
this.operatorListIdx = 0;
|
|
|
|
}
|
|
|
|
Stepper.prototype = {
|
2019-01-23 08:49:30 +00:00
|
|
|
init: function init(operatorList) {
|
2015-03-07 19:41:19 +00:00
|
|
|
var panel = this.panel;
|
|
|
|
var content = c('div', 'c=continue, s=step');
|
|
|
|
var table = c('table');
|
|
|
|
content.appendChild(table);
|
|
|
|
table.cellSpacing = 0;
|
|
|
|
var headerRow = c('tr');
|
|
|
|
table.appendChild(headerRow);
|
|
|
|
headerRow.appendChild(c('th', 'Break'));
|
|
|
|
headerRow.appendChild(c('th', 'Idx'));
|
|
|
|
headerRow.appendChild(c('th', 'fn'));
|
|
|
|
headerRow.appendChild(c('th', 'args'));
|
|
|
|
panel.appendChild(content);
|
|
|
|
this.table = table;
|
2019-01-23 08:49:30 +00:00
|
|
|
this.updateOperatorList(operatorList);
|
2015-03-07 19:41:19 +00:00
|
|
|
},
|
|
|
|
updateOperatorList: function updateOperatorList(operatorList) {
|
|
|
|
var self = this;
|
2016-01-03 13:38:30 +00:00
|
|
|
|
|
|
|
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 chunk = document.createDocumentFragment();
|
|
|
|
var operatorsToDisplay = Math.min(MAX_OPERATORS_COUNT,
|
|
|
|
operatorList.fnArray.length);
|
|
|
|
for (var i = this.operatorListIdx; i < operatorsToDisplay; i++) {
|
2015-03-07 19:41:19 +00:00
|
|
|
var line = c('tr');
|
|
|
|
line.className = 'line';
|
|
|
|
line.dataset.idx = i;
|
2016-01-03 13:38:30 +00:00
|
|
|
chunk.appendChild(line);
|
2019-01-23 08:49:30 +00:00
|
|
|
var checked = this.breakPoints.includes(i);
|
2016-01-03 13:38:30 +00:00
|
|
|
var args = operatorList.argsArray[i] || [];
|
2015-03-07 19:41:19 +00:00
|
|
|
|
|
|
|
var breakCell = c('td');
|
|
|
|
var cbox = c('input');
|
|
|
|
cbox.type = 'checkbox';
|
|
|
|
cbox.className = 'points';
|
|
|
|
cbox.checked = checked;
|
2016-01-03 13:38:30 +00:00
|
|
|
cbox.dataset.idx = i;
|
|
|
|
cbox.onclick = cboxOnClick;
|
2015-03-07 19:41:19 +00:00
|
|
|
|
|
|
|
breakCell.appendChild(cbox);
|
|
|
|
line.appendChild(breakCell);
|
|
|
|
line.appendChild(c('td', i.toString()));
|
|
|
|
var fn = opMap[operatorList.fnArray[i]];
|
|
|
|
var decArgs = args;
|
2016-01-03 13:38:30 +00:00
|
|
|
if (fn === 'showText') {
|
|
|
|
var glyphs = args[0];
|
|
|
|
var newArgs = [];
|
|
|
|
var str = [];
|
|
|
|
for (var j = 0; j < glyphs.length; j++) {
|
|
|
|
var glyph = glyphs[j];
|
|
|
|
if (typeof glyph === 'object' && glyph !== null) {
|
|
|
|
str.push(glyph.fontChar);
|
|
|
|
} else {
|
|
|
|
if (str.length > 0) {
|
|
|
|
newArgs.push(str.join(''));
|
|
|
|
str = [];
|
2015-03-07 19:41:19 +00:00
|
|
|
}
|
2016-01-03 13:38:30 +00:00
|
|
|
newArgs.push(glyph); // null or number
|
2015-03-07 19:41:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-03 13:38:30 +00:00
|
|
|
if (str.length > 0) {
|
|
|
|
newArgs.push(str.join(''));
|
|
|
|
}
|
|
|
|
decArgs = [newArgs];
|
2015-03-07 19:41:19 +00:00
|
|
|
}
|
|
|
|
line.appendChild(c('td', fn));
|
2016-01-03 13:38:30 +00:00
|
|
|
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);
|
2015-03-07 19:41:19 +00:00
|
|
|
}
|
2016-01-03 13:38:30 +00:00
|
|
|
this.operatorListIdx = operatorList.fnArray.length;
|
|
|
|
this.table.appendChild(chunk);
|
2015-03-07 19:41:19 +00:00
|
|
|
},
|
|
|
|
getNextBreakPoint: function getNextBreakPoint() {
|
2019-01-23 08:49:30 +00:00
|
|
|
this.breakPoints.sort(function(a, b) {
|
|
|
|
return a - b;
|
|
|
|
});
|
2015-03-07 19:41:19 +00:00
|
|
|
for (var i = 0; i < this.breakPoints.length; i++) {
|
2016-01-03 13:38:30 +00:00
|
|
|
if (this.breakPoints[i] > this.currentIdx) {
|
2015-03-07 19:41:19 +00:00
|
|
|
return this.breakPoints[i];
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
2015-03-07 19:41:19 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
breakIt: function breakIt(idx, callback) {
|
|
|
|
StepperManager.selectStepper(this.pageIndex, true);
|
|
|
|
var self = this;
|
|
|
|
var dom = document;
|
|
|
|
self.currentIdx = idx;
|
|
|
|
var listener = function(e) {
|
|
|
|
switch (e.keyCode) {
|
|
|
|
case 83: // step
|
2019-01-23 08:49:30 +00:00
|
|
|
dom.removeEventListener('keydown', listener);
|
2015-03-07 19:41:19 +00:00
|
|
|
self.nextBreakPoint = self.currentIdx + 1;
|
|
|
|
self.goTo(-1);
|
|
|
|
callback();
|
|
|
|
break;
|
|
|
|
case 67: // continue
|
2019-01-23 08:49:30 +00:00
|
|
|
dom.removeEventListener('keydown', listener);
|
2015-03-07 19:41:19 +00:00
|
|
|
var breakPoint = self.getNextBreakPoint();
|
|
|
|
self.nextBreakPoint = breakPoint;
|
|
|
|
self.goTo(-1);
|
|
|
|
callback();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2019-01-23 08:49:30 +00:00
|
|
|
dom.addEventListener('keydown', listener);
|
2015-03-07 19:41:19 +00:00
|
|
|
self.goTo(idx);
|
|
|
|
},
|
|
|
|
goTo: function goTo(idx) {
|
|
|
|
var allRows = this.panel.getElementsByClassName('line');
|
|
|
|
for (var x = 0, xx = allRows.length; x < xx; ++x) {
|
|
|
|
var row = allRows[x];
|
2016-01-03 13:38:30 +00:00
|
|
|
if ((row.dataset.idx | 0) === idx) {
|
2015-03-07 19:41:19 +00:00
|
|
|
row.style.backgroundColor = 'rgb(251,250,207)';
|
|
|
|
row.scrollIntoView();
|
|
|
|
} else {
|
|
|
|
row.style.backgroundColor = null;
|
|
|
|
}
|
|
|
|
}
|
2019-01-23 08:49:30 +00:00
|
|
|
},
|
2015-03-07 19:41:19 +00:00
|
|
|
};
|
|
|
|
return Stepper;
|
|
|
|
})();
|
|
|
|
|
|
|
|
var Stats = (function Stats() {
|
|
|
|
var stats = [];
|
|
|
|
function clear(node) {
|
2016-01-03 13:38:30 +00:00
|
|
|
while (node.hasChildNodes()) {
|
2015-03-07 19:41:19 +00:00
|
|
|
node.removeChild(node.lastChild);
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
2015-03-07 19:41:19 +00:00
|
|
|
}
|
|
|
|
function getStatIndex(pageNumber) {
|
2016-01-03 13:38:30 +00:00
|
|
|
for (var i = 0, ii = stats.length; i < ii; ++i) {
|
|
|
|
if (stats[i].pageNumber === pageNumber) {
|
2015-03-07 19:41:19 +00:00
|
|
|
return i;
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-07 19:41:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
// Properties/functions needed by PDFBug.
|
|
|
|
id: 'Stats',
|
|
|
|
name: 'Stats',
|
|
|
|
panel: null,
|
|
|
|
manager: null,
|
2019-01-23 08:49:30 +00:00
|
|
|
init(pdfjsLib) {
|
2015-03-07 19:41:19 +00:00
|
|
|
this.panel.setAttribute('style', 'padding: 5px;');
|
|
|
|
},
|
|
|
|
enabled: false,
|
|
|
|
active: false,
|
|
|
|
// Stats specific functions.
|
2019-01-23 08:49:30 +00:00
|
|
|
add(pageNumber, stat) {
|
2016-01-03 13:38:30 +00:00
|
|
|
if (!stat) {
|
2015-03-07 19:41:19 +00:00
|
|
|
return;
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
2015-03-07 19:41:19 +00:00
|
|
|
var statsIndex = getStatIndex(pageNumber);
|
|
|
|
if (statsIndex !== false) {
|
|
|
|
var b = stats[statsIndex];
|
|
|
|
this.panel.removeChild(b.div);
|
|
|
|
stats.splice(statsIndex, 1);
|
|
|
|
}
|
|
|
|
var wrapper = document.createElement('div');
|
|
|
|
wrapper.className = 'stats';
|
|
|
|
var title = document.createElement('div');
|
|
|
|
title.className = 'title';
|
|
|
|
title.textContent = 'Page: ' + pageNumber;
|
|
|
|
var statsDiv = document.createElement('div');
|
|
|
|
statsDiv.textContent = stat.toString();
|
|
|
|
wrapper.appendChild(title);
|
|
|
|
wrapper.appendChild(statsDiv);
|
2019-01-23 08:49:30 +00:00
|
|
|
stats.push({ pageNumber, div: wrapper, });
|
|
|
|
stats.sort(function(a, b) {
|
|
|
|
return a.pageNumber - b.pageNumber;
|
|
|
|
});
|
2015-03-07 19:41:19 +00:00
|
|
|
clear(this.panel);
|
2016-01-03 13:38:30 +00:00
|
|
|
for (var i = 0, ii = stats.length; i < ii; ++i) {
|
2015-03-07 19:41:19 +00:00
|
|
|
this.panel.appendChild(stats[i].div);
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
|
|
|
},
|
2019-01-23 08:49:30 +00:00
|
|
|
cleanup() {
|
2016-01-03 13:38:30 +00:00
|
|
|
stats = [];
|
|
|
|
clear(this.panel);
|
2019-01-23 08:49:30 +00:00
|
|
|
},
|
2015-03-07 19:41:19 +00:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Manages all the debugging tools.
|
2019-01-23 08:49:30 +00:00
|
|
|
window.PDFBug = (function PDFBugClosure() {
|
2015-03-07 19:41:19 +00:00
|
|
|
var panelWidth = 300;
|
|
|
|
var buttons = [];
|
|
|
|
var activePanel = null;
|
|
|
|
|
|
|
|
return {
|
|
|
|
tools: [
|
|
|
|
FontInspector,
|
|
|
|
StepperManager,
|
|
|
|
Stats
|
|
|
|
],
|
2019-01-23 08:49:30 +00:00
|
|
|
enable(ids) {
|
2015-03-07 19:41:19 +00:00
|
|
|
var all = false, tools = this.tools;
|
2016-01-03 13:38:30 +00:00
|
|
|
if (ids.length === 1 && ids[0] === 'all') {
|
2015-03-07 19:41:19 +00:00
|
|
|
all = true;
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
2015-03-07 19:41:19 +00:00
|
|
|
for (var i = 0; i < tools.length; ++i) {
|
|
|
|
var tool = tools[i];
|
2019-01-23 08:49:30 +00:00
|
|
|
if (all || ids.includes(tool.id)) {
|
2015-03-07 19:41:19 +00:00
|
|
|
tool.enabled = true;
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
2015-03-07 19:41:19 +00:00
|
|
|
}
|
|
|
|
if (!all) {
|
|
|
|
// Sort the tools by the order they are enabled.
|
|
|
|
tools.sort(function(a, b) {
|
|
|
|
var indexA = ids.indexOf(a.id);
|
|
|
|
indexA = indexA < 0 ? tools.length : indexA;
|
|
|
|
var indexB = ids.indexOf(b.id);
|
|
|
|
indexB = indexB < 0 ? tools.length : indexB;
|
|
|
|
return indexA - indexB;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2019-01-23 08:49:30 +00:00
|
|
|
init(pdfjsLib, container) {
|
2015-03-07 19:41:19 +00:00
|
|
|
/*
|
|
|
|
* Basic Layout:
|
|
|
|
* PDFBug
|
|
|
|
* Controls
|
|
|
|
* Panels
|
|
|
|
* Panel
|
|
|
|
* Panel
|
|
|
|
* ...
|
|
|
|
*/
|
|
|
|
var ui = document.createElement('div');
|
|
|
|
ui.id = 'PDFBug';
|
|
|
|
|
|
|
|
var controls = document.createElement('div');
|
|
|
|
controls.setAttribute('class', 'controls');
|
|
|
|
ui.appendChild(controls);
|
|
|
|
|
|
|
|
var panels = document.createElement('div');
|
|
|
|
panels.setAttribute('class', 'panels');
|
|
|
|
ui.appendChild(panels);
|
|
|
|
|
|
|
|
container.appendChild(ui);
|
|
|
|
container.style.right = panelWidth + 'px';
|
|
|
|
|
|
|
|
// Initialize all the debugging tools.
|
|
|
|
var tools = this.tools;
|
|
|
|
var self = this;
|
|
|
|
for (var i = 0; i < tools.length; ++i) {
|
|
|
|
var tool = tools[i];
|
|
|
|
var panel = document.createElement('div');
|
|
|
|
var panelButton = document.createElement('button');
|
|
|
|
panelButton.textContent = tool.name;
|
|
|
|
panelButton.addEventListener('click', (function(selected) {
|
|
|
|
return function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
self.selectPanel(selected);
|
|
|
|
};
|
|
|
|
})(i));
|
|
|
|
controls.appendChild(panelButton);
|
|
|
|
panels.appendChild(panel);
|
|
|
|
tool.panel = panel;
|
|
|
|
tool.manager = this;
|
2016-01-03 13:38:30 +00:00
|
|
|
if (tool.enabled) {
|
2019-01-23 08:49:30 +00:00
|
|
|
tool.init(pdfjsLib);
|
2016-01-03 13:38:30 +00:00
|
|
|
} else {
|
2015-03-07 19:41:19 +00:00
|
|
|
panel.textContent = tool.name + ' is disabled. To enable add ' +
|
|
|
|
' "' + tool.id + '" to the pdfBug parameter ' +
|
2019-01-23 08:49:30 +00:00
|
|
|
'and refresh (separate multiple by commas).';
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
2015-03-07 19:41:19 +00:00
|
|
|
buttons.push(panelButton);
|
|
|
|
}
|
|
|
|
this.selectPanel(0);
|
|
|
|
},
|
2019-01-23 08:49:30 +00:00
|
|
|
cleanup() {
|
2016-01-03 13:38:30 +00:00
|
|
|
for (var i = 0, ii = this.tools.length; i < ii; i++) {
|
|
|
|
if (this.tools[i].enabled) {
|
|
|
|
this.tools[i].cleanup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2019-01-23 08:49:30 +00:00
|
|
|
selectPanel(index) {
|
2016-01-03 13:38:30 +00:00
|
|
|
if (typeof index !== 'number') {
|
|
|
|
index = this.tools.indexOf(index);
|
|
|
|
}
|
|
|
|
if (index === activePanel) {
|
2015-03-07 19:41:19 +00:00
|
|
|
return;
|
2016-01-03 13:38:30 +00:00
|
|
|
}
|
2015-03-07 19:41:19 +00:00
|
|
|
activePanel = index;
|
|
|
|
var tools = this.tools;
|
|
|
|
for (var j = 0; j < tools.length; ++j) {
|
2016-01-03 13:38:30 +00:00
|
|
|
if (j === index) {
|
2015-03-07 19:41:19 +00:00
|
|
|
buttons[j].setAttribute('class', 'active');
|
|
|
|
tools[j].active = true;
|
|
|
|
tools[j].panel.removeAttribute('hidden');
|
|
|
|
} else {
|
|
|
|
buttons[j].setAttribute('class', '');
|
|
|
|
tools[j].active = false;
|
|
|
|
tools[j].panel.setAttribute('hidden', 'true');
|
|
|
|
}
|
|
|
|
}
|
2019-01-23 08:49:30 +00:00
|
|
|
},
|
2015-03-07 19:41:19 +00:00
|
|
|
};
|
|
|
|
})();
|