2016-07-09 08:54:13 +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-04-13 13:02:01 +00:00
|
|
|
/* eslint-disable no-var */
|
2016-07-09 08:54:13 +00:00
|
|
|
|
2021-05-14 07:29:24 +00:00
|
|
|
"use strict";
|
2016-07-09 08:54:13 +00:00
|
|
|
|
|
|
|
var FontInspector = (function FontInspectorClosure() {
|
2021-05-14 07:29:24 +00:00
|
|
|
var fonts;
|
2016-07-09 08:54:13 +00:00
|
|
|
var active = false;
|
2021-05-14 07:29:24 +00:00
|
|
|
var fontAttribute = "data-font-name";
|
2016-07-09 08:54:13 +00:00
|
|
|
function removeSelection() {
|
2021-05-14 07:29:24 +00:00
|
|
|
const divs = document.querySelectorAll(`span[${fontAttribute}]`);
|
|
|
|
for (const div of divs) {
|
|
|
|
div.className = "";
|
2016-07-09 08:54:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function resetSelection() {
|
2021-05-14 07:29:24 +00:00
|
|
|
const divs = document.querySelectorAll(`span[${fontAttribute}]`);
|
|
|
|
for (const div of divs) {
|
|
|
|
div.className = "debuggerHideText";
|
2016-07-09 08:54:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function selectFont(fontName, show) {
|
2021-05-14 07:29:24 +00:00
|
|
|
const divs = document.querySelectorAll(
|
|
|
|
`span[${fontAttribute}=${fontName}]`
|
|
|
|
);
|
|
|
|
for (const div of divs) {
|
|
|
|
div.className = show ? "debuggerShowText" : "debuggerHideText";
|
2016-07-09 08:54:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function textLayerClick(e) {
|
2021-05-14 07:29:24 +00:00
|
|
|
if (
|
|
|
|
!e.target.dataset.fontName ||
|
|
|
|
e.target.tagName.toUpperCase() !== "SPAN"
|
|
|
|
) {
|
2016-07-09 08:54:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var fontName = e.target.dataset.fontName;
|
2021-05-14 07:29:24 +00:00
|
|
|
var selects = document.getElementsByTagName("input");
|
2016-07-09 08:54:13 +00:00
|
|
|
for (var i = 0; i < selects.length; ++i) {
|
|
|
|
var select = selects[i];
|
|
|
|
if (select.dataset.fontName !== fontName) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
select.checked = !select.checked;
|
|
|
|
selectFont(fontName, select.checked);
|
|
|
|
select.scrollIntoView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
// Properties/functions needed by PDFBug.
|
2021-05-14 07:29:24 +00:00
|
|
|
id: "FontInspector",
|
|
|
|
name: "Font Inspector",
|
2016-07-09 08:54:13 +00:00
|
|
|
panel: null,
|
|
|
|
manager: null,
|
|
|
|
init: function init(pdfjsLib) {
|
|
|
|
var panel = this.panel;
|
2021-05-14 07:29:24 +00:00
|
|
|
var tmp = document.createElement("button");
|
|
|
|
tmp.addEventListener("click", resetSelection);
|
|
|
|
tmp.textContent = "Refresh";
|
2016-07-09 08:54:13 +00:00
|
|
|
panel.appendChild(tmp);
|
|
|
|
|
2021-05-14 07:29:24 +00:00
|
|
|
fonts = document.createElement("div");
|
2016-07-09 08:54:13 +00:00
|
|
|
panel.appendChild(fonts);
|
|
|
|
},
|
|
|
|
cleanup: function cleanup() {
|
2021-05-14 07:29:24 +00:00
|
|
|
fonts.textContent = "";
|
2016-07-09 08:54:13 +00:00
|
|
|
},
|
|
|
|
enabled: false,
|
|
|
|
get active() {
|
|
|
|
return active;
|
|
|
|
},
|
|
|
|
set active(value) {
|
|
|
|
active = value;
|
|
|
|
if (active) {
|
2021-05-14 07:29:24 +00:00
|
|
|
document.body.addEventListener("click", textLayerClick, true);
|
2016-07-09 08:54:13 +00:00
|
|
|
resetSelection();
|
|
|
|
} else {
|
2021-05-14 07:29:24 +00:00
|
|
|
document.body.removeEventListener("click", textLayerClick, true);
|
2016-07-09 08:54:13 +00:00
|
|
|
removeSelection();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// FontInspector specific functions.
|
|
|
|
fontAdded: function fontAdded(fontObj, url) {
|
|
|
|
function properties(obj, list) {
|
2021-05-14 07:29:24 +00:00
|
|
|
var moreInfo = document.createElement("table");
|
2016-07-09 08:54:13 +00:00
|
|
|
for (var i = 0; i < list.length; i++) {
|
2021-05-14 07:29:24 +00:00
|
|
|
var tr = document.createElement("tr");
|
|
|
|
var td1 = document.createElement("td");
|
2016-07-09 08:54:13 +00:00
|
|
|
td1.textContent = list[i];
|
|
|
|
tr.appendChild(td1);
|
2021-05-14 07:29:24 +00:00
|
|
|
var td2 = document.createElement("td");
|
2016-07-09 08:54:13 +00:00
|
|
|
td2.textContent = obj[list[i]].toString();
|
|
|
|
tr.appendChild(td2);
|
|
|
|
moreInfo.appendChild(tr);
|
|
|
|
}
|
|
|
|
return moreInfo;
|
|
|
|
}
|
2021-05-14 07:29:24 +00:00
|
|
|
var moreInfo = properties(fontObj, ["name", "type"]);
|
|
|
|
const fontName = fontObj.loadedName;
|
|
|
|
var font = document.createElement("div");
|
|
|
|
var name = document.createElement("span");
|
2016-07-09 08:54:13 +00:00
|
|
|
name.textContent = fontName;
|
2021-05-14 07:29:24 +00:00
|
|
|
var download = document.createElement("a");
|
2016-07-09 08:54:13 +00:00
|
|
|
if (url) {
|
2021-05-14 07:29:24 +00:00
|
|
|
url = /url\(['"]?([^)"']+)/.exec(url);
|
2016-07-09 08:54:13 +00:00
|
|
|
download.href = url[1];
|
|
|
|
} else if (fontObj.data) {
|
2021-05-14 07:29:24 +00:00
|
|
|
download.href = URL.createObjectURL(
|
|
|
|
new Blob([fontObj.data], { type: fontObj.mimeType })
|
|
|
|
);
|
2016-07-09 08:54:13 +00:00
|
|
|
}
|
2021-05-14 07:29:24 +00:00
|
|
|
download.textContent = "Download";
|
|
|
|
var logIt = document.createElement("a");
|
|
|
|
logIt.href = "";
|
|
|
|
logIt.textContent = "Log";
|
|
|
|
logIt.addEventListener("click", function (event) {
|
2016-07-09 08:54:13 +00:00
|
|
|
event.preventDefault();
|
|
|
|
console.log(fontObj);
|
|
|
|
});
|
2021-05-14 07:29:24 +00:00
|
|
|
const select = document.createElement("input");
|
|
|
|
select.setAttribute("type", "checkbox");
|
2016-07-09 08:54:13 +00:00
|
|
|
select.dataset.fontName = fontName;
|
2021-05-14 07:29:24 +00:00
|
|
|
select.addEventListener("click", function () {
|
|
|
|
selectFont(fontName, select.checked);
|
|
|
|
});
|
2016-07-09 08:54:13 +00:00
|
|
|
font.appendChild(select);
|
|
|
|
font.appendChild(name);
|
2021-05-14 07:29:24 +00:00
|
|
|
font.appendChild(document.createTextNode(" "));
|
2016-07-09 08:54:13 +00:00
|
|
|
font.appendChild(download);
|
2021-05-14 07:29:24 +00:00
|
|
|
font.appendChild(document.createTextNode(" "));
|
2016-07-09 08:54:13 +00:00
|
|
|
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-04-13 13:02:01 +00:00
|
|
|
setTimeout(() => {
|
2016-07-09 08:54:13 +00:00
|
|
|
if (this.active) {
|
|
|
|
resetSelection();
|
|
|
|
}
|
2019-04-13 13:02:01 +00:00
|
|
|
}, 2000);
|
|
|
|
},
|
2016-07-09 08:54:13 +00:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2017-05-13 12:01:52 +00:00
|
|
|
var opMap;
|
|
|
|
|
2016-07-09 08:54:13 +00:00
|
|
|
// Manages all the page steppers.
|
|
|
|
var StepperManager = (function StepperManagerClosure() {
|
|
|
|
var steppers = [];
|
|
|
|
var stepperDiv = null;
|
|
|
|
var stepperControls = null;
|
|
|
|
var stepperChooser = null;
|
|
|
|
var breakPoints = Object.create(null);
|
|
|
|
return {
|
|
|
|
// Properties/functions needed by PDFBug.
|
2021-05-14 07:29:24 +00:00
|
|
|
id: "Stepper",
|
|
|
|
name: "Stepper",
|
2016-07-09 08:54:13 +00:00
|
|
|
panel: null,
|
|
|
|
manager: null,
|
2017-05-13 12:01:52 +00:00
|
|
|
init: function init(pdfjsLib) {
|
2016-07-09 08:54:13 +00:00
|
|
|
var self = this;
|
2021-05-14 07:29:24 +00:00
|
|
|
stepperControls = document.createElement("div");
|
|
|
|
stepperChooser = document.createElement("select");
|
|
|
|
stepperChooser.addEventListener("change", function (event) {
|
2016-07-09 08:54:13 +00:00
|
|
|
self.selectStepper(this.value);
|
|
|
|
});
|
|
|
|
stepperControls.appendChild(stepperChooser);
|
2021-05-14 07:29:24 +00:00
|
|
|
stepperDiv = document.createElement("div");
|
2016-07-09 08:54:13 +00:00
|
|
|
this.panel.appendChild(stepperControls);
|
|
|
|
this.panel.appendChild(stepperDiv);
|
2021-05-14 07:29:24 +00:00
|
|
|
if (sessionStorage.getItem("pdfjsBreakPoints")) {
|
|
|
|
breakPoints = JSON.parse(sessionStorage.getItem("pdfjsBreakPoints"));
|
2016-07-09 08:54:13 +00:00
|
|
|
}
|
2017-05-13 12:01:52 +00:00
|
|
|
|
|
|
|
opMap = Object.create(null);
|
|
|
|
for (var key in pdfjsLib.OPS) {
|
|
|
|
opMap[pdfjsLib.OPS[key]] = key;
|
|
|
|
}
|
2016-07-09 08:54:13 +00:00
|
|
|
},
|
|
|
|
cleanup: function cleanup() {
|
2021-05-14 07:29:24 +00:00
|
|
|
stepperChooser.textContent = "";
|
|
|
|
stepperDiv.textContent = "";
|
2016-07-09 08:54:13 +00:00
|
|
|
steppers = [];
|
|
|
|
},
|
|
|
|
enabled: false,
|
|
|
|
active: false,
|
|
|
|
// Stepper specific functions.
|
|
|
|
create: function create(pageIndex) {
|
2021-05-14 07:29:24 +00:00
|
|
|
var debug = document.createElement("div");
|
|
|
|
debug.id = "stepper" + pageIndex;
|
|
|
|
debug.setAttribute("hidden", true);
|
|
|
|
debug.className = "stepper";
|
2016-07-09 08:54:13 +00:00
|
|
|
stepperDiv.appendChild(debug);
|
2021-05-14 07:29:24 +00:00
|
|
|
var b = document.createElement("option");
|
|
|
|
b.textContent = "Page " + (pageIndex + 1);
|
2016-07-09 08:54:13 +00:00
|
|
|
b.value = pageIndex;
|
|
|
|
stepperChooser.appendChild(b);
|
|
|
|
var initBreakPoints = breakPoints[pageIndex] || [];
|
|
|
|
var stepper = new Stepper(debug, pageIndex, initBreakPoints);
|
|
|
|
steppers.push(stepper);
|
|
|
|
if (steppers.length === 1) {
|
|
|
|
this.selectStepper(pageIndex, false);
|
|
|
|
}
|
|
|
|
return stepper;
|
|
|
|
},
|
|
|
|
selectStepper: function selectStepper(pageIndex, selectPanel) {
|
|
|
|
var i;
|
|
|
|
pageIndex = pageIndex | 0;
|
|
|
|
if (selectPanel) {
|
|
|
|
this.manager.selectPanel(this);
|
|
|
|
}
|
|
|
|
for (i = 0; i < steppers.length; ++i) {
|
|
|
|
var stepper = steppers[i];
|
|
|
|
if (stepper.pageIndex === pageIndex) {
|
2021-05-14 07:29:24 +00:00
|
|
|
stepper.panel.removeAttribute("hidden");
|
2016-07-09 08:54:13 +00:00
|
|
|
} else {
|
2021-05-14 07:29:24 +00:00
|
|
|
stepper.panel.setAttribute("hidden", true);
|
2016-07-09 08:54:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
var options = stepperChooser.options;
|
|
|
|
for (i = 0; i < options.length; ++i) {
|
|
|
|
var option = options[i];
|
|
|
|
option.selected = (option.value | 0) === pageIndex;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
saveBreakPoints: function saveBreakPoints(pageIndex, bps) {
|
|
|
|
breakPoints[pageIndex] = bps;
|
2021-05-14 07:29:24 +00:00
|
|
|
sessionStorage.setItem("pdfjsBreakPoints", JSON.stringify(breakPoints));
|
2019-04-13 13:02:01 +00:00
|
|
|
},
|
2016-07-09 08:54:13 +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);
|
|
|
|
if (textContent) {
|
|
|
|
d.textContent = textContent;
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
function simplifyArgs(args) {
|
2021-05-14 07:29:24 +00:00
|
|
|
if (typeof args === "string") {
|
2016-07-09 08:54:13 +00:00
|
|
|
var MAX_STRING_LENGTH = 75;
|
2021-05-14 07:29:24 +00:00
|
|
|
return args.length <= MAX_STRING_LENGTH
|
|
|
|
? args
|
|
|
|
: args.substring(0, MAX_STRING_LENGTH) + "...";
|
2016-07-09 08:54:13 +00:00
|
|
|
}
|
2021-05-14 07:29:24 +00:00
|
|
|
if (typeof args !== "object" || args === null) {
|
2016-07-09 08:54:13 +00:00
|
|
|
return args;
|
|
|
|
}
|
2021-05-14 07:29:24 +00:00
|
|
|
if ("length" in args) {
|
|
|
|
// array
|
|
|
|
var simpleArgs = [],
|
|
|
|
i,
|
|
|
|
ii;
|
2016-07-09 08:54:13 +00:00
|
|
|
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) {
|
2021-05-14 07:29:24 +00:00
|
|
|
simpleArgs.push("...");
|
2016-07-09 08:54:13 +00:00
|
|
|
}
|
|
|
|
return simpleArgs;
|
|
|
|
}
|
|
|
|
var simpleObj = {};
|
|
|
|
for (var key in args) {
|
|
|
|
simpleObj[key] = simplifyArgs(args[key]);
|
|
|
|
}
|
|
|
|
return simpleObj;
|
|
|
|
}
|
|
|
|
|
2021-05-14 07:29:24 +00:00
|
|
|
// eslint-disable-next-line no-shadow
|
2016-07-09 08:54:13 +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 = {
|
2017-05-13 12:01:52 +00:00
|
|
|
init: function init(operatorList) {
|
2016-07-09 08:54:13 +00:00
|
|
|
var panel = this.panel;
|
2021-05-14 07:29:24 +00:00
|
|
|
var content = c("div", "c=continue, s=step");
|
|
|
|
var table = c("table");
|
2016-07-09 08:54:13 +00:00
|
|
|
content.appendChild(table);
|
|
|
|
table.cellSpacing = 0;
|
2021-05-14 07:29:24 +00:00
|
|
|
var headerRow = c("tr");
|
2016-07-09 08:54:13 +00:00
|
|
|
table.appendChild(headerRow);
|
2021-05-14 07:29:24 +00:00
|
|
|
headerRow.appendChild(c("th", "Break"));
|
|
|
|
headerRow.appendChild(c("th", "Idx"));
|
|
|
|
headerRow.appendChild(c("th", "fn"));
|
|
|
|
headerRow.appendChild(c("th", "args"));
|
2016-07-09 08:54:13 +00:00
|
|
|
panel.appendChild(content);
|
|
|
|
this.table = table;
|
2017-05-13 12:01:52 +00:00
|
|
|
this.updateOperatorList(operatorList);
|
2016-07-09 08:54:13 +00:00
|
|
|
},
|
|
|
|
updateOperatorList: function updateOperatorList(operatorList) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
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();
|
2021-05-14 07:29:24 +00:00
|
|
|
var operatorsToDisplay = Math.min(
|
|
|
|
MAX_OPERATORS_COUNT,
|
|
|
|
operatorList.fnArray.length
|
|
|
|
);
|
2016-07-09 08:54:13 +00:00
|
|
|
for (var i = this.operatorListIdx; i < operatorsToDisplay; i++) {
|
2021-05-14 07:29:24 +00:00
|
|
|
var line = c("tr");
|
|
|
|
line.className = "line";
|
2016-07-09 08:54:13 +00:00
|
|
|
line.dataset.idx = i;
|
|
|
|
chunk.appendChild(line);
|
2019-04-13 13:02:01 +00:00
|
|
|
var checked = this.breakPoints.includes(i);
|
2016-07-09 08:54:13 +00:00
|
|
|
var args = operatorList.argsArray[i] || [];
|
|
|
|
|
2021-05-14 07:29:24 +00:00
|
|
|
var breakCell = c("td");
|
|
|
|
var cbox = c("input");
|
|
|
|
cbox.type = "checkbox";
|
|
|
|
cbox.className = "points";
|
2016-07-09 08:54:13 +00:00
|
|
|
cbox.checked = checked;
|
|
|
|
cbox.dataset.idx = i;
|
|
|
|
cbox.onclick = cboxOnClick;
|
|
|
|
|
|
|
|
breakCell.appendChild(cbox);
|
|
|
|
line.appendChild(breakCell);
|
2021-05-14 07:29:24 +00:00
|
|
|
line.appendChild(c("td", i.toString()));
|
2016-07-09 08:54:13 +00:00
|
|
|
var fn = opMap[operatorList.fnArray[i]];
|
|
|
|
var decArgs = args;
|
2021-05-14 07:29:24 +00:00
|
|
|
if (fn === "showText") {
|
2016-07-09 08:54:13 +00:00
|
|
|
var glyphs = args[0];
|
|
|
|
var newArgs = [];
|
|
|
|
var str = [];
|
|
|
|
for (var j = 0; j < glyphs.length; j++) {
|
|
|
|
var glyph = glyphs[j];
|
2021-05-14 07:29:24 +00:00
|
|
|
if (typeof glyph === "object" && glyph !== null) {
|
2016-07-09 08:54:13 +00:00
|
|
|
str.push(glyph.fontChar);
|
|
|
|
} else {
|
|
|
|
if (str.length > 0) {
|
2021-05-14 07:29:24 +00:00
|
|
|
newArgs.push(str.join(""));
|
2016-07-09 08:54:13 +00:00
|
|
|
str = [];
|
|
|
|
}
|
|
|
|
newArgs.push(glyph); // null or number
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (str.length > 0) {
|
2021-05-14 07:29:24 +00:00
|
|
|
newArgs.push(str.join(""));
|
2016-07-09 08:54:13 +00:00
|
|
|
}
|
|
|
|
decArgs = [newArgs];
|
|
|
|
}
|
2021-05-14 07:29:24 +00:00
|
|
|
line.appendChild(c("td", fn));
|
|
|
|
line.appendChild(c("td", JSON.stringify(simplifyArgs(decArgs))));
|
2016-07-09 08:54:13 +00:00
|
|
|
}
|
|
|
|
if (operatorsToDisplay < operatorList.fnArray.length) {
|
2021-05-14 07:29:24 +00:00
|
|
|
var lastCell = c("td", "...");
|
2016-07-09 08:54:13 +00:00
|
|
|
lastCell.colspan = 4;
|
|
|
|
chunk.appendChild(lastCell);
|
|
|
|
}
|
|
|
|
this.operatorListIdx = operatorList.fnArray.length;
|
|
|
|
this.table.appendChild(chunk);
|
|
|
|
},
|
|
|
|
getNextBreakPoint: function getNextBreakPoint() {
|
2021-05-14 07:29:24 +00:00
|
|
|
this.breakPoints.sort(function (a, b) {
|
2019-04-13 13:02:01 +00:00
|
|
|
return a - b;
|
|
|
|
});
|
2016-07-09 08:54:13 +00:00
|
|
|
for (var i = 0; i < this.breakPoints.length; i++) {
|
|
|
|
if (this.breakPoints[i] > this.currentIdx) {
|
|
|
|
return this.breakPoints[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
breakIt: function breakIt(idx, callback) {
|
|
|
|
StepperManager.selectStepper(this.pageIndex, true);
|
|
|
|
var self = this;
|
|
|
|
var dom = document;
|
|
|
|
self.currentIdx = idx;
|
2021-05-14 07:29:24 +00:00
|
|
|
var listener = function (e) {
|
2016-07-09 08:54:13 +00:00
|
|
|
switch (e.keyCode) {
|
|
|
|
case 83: // step
|
2021-05-14 07:29:24 +00:00
|
|
|
dom.removeEventListener("keydown", listener);
|
2016-07-09 08:54:13 +00:00
|
|
|
self.nextBreakPoint = self.currentIdx + 1;
|
|
|
|
self.goTo(-1);
|
|
|
|
callback();
|
|
|
|
break;
|
|
|
|
case 67: // continue
|
2021-05-14 07:29:24 +00:00
|
|
|
dom.removeEventListener("keydown", listener);
|
2016-07-09 08:54:13 +00:00
|
|
|
var breakPoint = self.getNextBreakPoint();
|
|
|
|
self.nextBreakPoint = breakPoint;
|
|
|
|
self.goTo(-1);
|
|
|
|
callback();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2021-05-14 07:29:24 +00:00
|
|
|
dom.addEventListener("keydown", listener);
|
2016-07-09 08:54:13 +00:00
|
|
|
self.goTo(idx);
|
|
|
|
},
|
|
|
|
goTo: function goTo(idx) {
|
2021-05-14 07:29:24 +00:00
|
|
|
var allRows = this.panel.getElementsByClassName("line");
|
2016-07-09 08:54:13 +00:00
|
|
|
for (var x = 0, xx = allRows.length; x < xx; ++x) {
|
|
|
|
var row = allRows[x];
|
|
|
|
if ((row.dataset.idx | 0) === idx) {
|
2021-05-14 07:29:24 +00:00
|
|
|
row.style.backgroundColor = "rgb(251,250,207)";
|
2016-07-09 08:54:13 +00:00
|
|
|
row.scrollIntoView();
|
|
|
|
} else {
|
|
|
|
row.style.backgroundColor = null;
|
|
|
|
}
|
|
|
|
}
|
2019-04-13 13:02:01 +00:00
|
|
|
},
|
2016-07-09 08:54:13 +00:00
|
|
|
};
|
|
|
|
return Stepper;
|
|
|
|
})();
|
|
|
|
|
|
|
|
var Stats = (function Stats() {
|
|
|
|
var stats = [];
|
|
|
|
function clear(node) {
|
|
|
|
while (node.hasChildNodes()) {
|
|
|
|
node.removeChild(node.lastChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function getStatIndex(pageNumber) {
|
|
|
|
for (var i = 0, ii = stats.length; i < ii; ++i) {
|
|
|
|
if (stats[i].pageNumber === pageNumber) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
// Properties/functions needed by PDFBug.
|
2021-05-14 07:29:24 +00:00
|
|
|
id: "Stats",
|
|
|
|
name: "Stats",
|
2016-07-09 08:54:13 +00:00
|
|
|
panel: null,
|
|
|
|
manager: null,
|
2021-05-14 07:29:24 +00:00
|
|
|
init(pdfjsLib) {},
|
2016-07-09 08:54:13 +00:00
|
|
|
enabled: false,
|
|
|
|
active: false,
|
|
|
|
// Stats specific functions.
|
2019-04-13 13:02:01 +00:00
|
|
|
add(pageNumber, stat) {
|
2016-07-09 08:54:13 +00:00
|
|
|
if (!stat) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var statsIndex = getStatIndex(pageNumber);
|
|
|
|
if (statsIndex !== false) {
|
2021-05-14 07:29:24 +00:00
|
|
|
const b = stats[statsIndex];
|
2016-07-09 08:54:13 +00:00
|
|
|
this.panel.removeChild(b.div);
|
|
|
|
stats.splice(statsIndex, 1);
|
|
|
|
}
|
2021-05-14 07:29:24 +00:00
|
|
|
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");
|
2016-07-09 08:54:13 +00:00
|
|
|
statsDiv.textContent = stat.toString();
|
|
|
|
wrapper.appendChild(title);
|
|
|
|
wrapper.appendChild(statsDiv);
|
2021-05-14 07:29:24 +00:00
|
|
|
stats.push({ pageNumber, div: wrapper });
|
|
|
|
stats.sort(function (a, b) {
|
2019-04-13 13:02:01 +00:00
|
|
|
return a.pageNumber - b.pageNumber;
|
|
|
|
});
|
2016-07-09 08:54:13 +00:00
|
|
|
clear(this.panel);
|
|
|
|
for (var i = 0, ii = stats.length; i < ii; ++i) {
|
|
|
|
this.panel.appendChild(stats[i].div);
|
|
|
|
}
|
|
|
|
},
|
2019-04-13 13:02:01 +00:00
|
|
|
cleanup() {
|
2016-07-09 08:54:13 +00:00
|
|
|
stats = [];
|
|
|
|
clear(this.panel);
|
2019-04-13 13:02:01 +00:00
|
|
|
},
|
2016-07-09 08:54:13 +00:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Manages all the debugging tools.
|
2019-04-13 13:02:01 +00:00
|
|
|
window.PDFBug = (function PDFBugClosure() {
|
2016-07-09 08:54:13 +00:00
|
|
|
var panelWidth = 300;
|
|
|
|
var buttons = [];
|
|
|
|
var activePanel = null;
|
|
|
|
|
|
|
|
return {
|
2021-05-14 07:29:24 +00:00
|
|
|
tools: [FontInspector, StepperManager, Stats],
|
2019-04-13 13:02:01 +00:00
|
|
|
enable(ids) {
|
2021-05-14 07:29:24 +00:00
|
|
|
var all = false,
|
|
|
|
tools = this.tools;
|
|
|
|
if (ids.length === 1 && ids[0] === "all") {
|
2016-07-09 08:54:13 +00:00
|
|
|
all = true;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < tools.length; ++i) {
|
|
|
|
var tool = tools[i];
|
2019-04-13 13:02:01 +00:00
|
|
|
if (all || ids.includes(tool.id)) {
|
2016-07-09 08:54:13 +00:00
|
|
|
tool.enabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!all) {
|
|
|
|
// Sort the tools by the order they are enabled.
|
2021-05-14 07:29:24 +00:00
|
|
|
tools.sort(function (a, b) {
|
2016-07-09 08:54:13 +00:00
|
|
|
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-04-13 13:02:01 +00:00
|
|
|
init(pdfjsLib, container) {
|
2016-07-09 08:54:13 +00:00
|
|
|
/*
|
|
|
|
* Basic Layout:
|
|
|
|
* PDFBug
|
|
|
|
* Controls
|
|
|
|
* Panels
|
|
|
|
* Panel
|
|
|
|
* Panel
|
|
|
|
* ...
|
|
|
|
*/
|
2021-05-14 07:29:24 +00:00
|
|
|
var ui = document.createElement("div");
|
|
|
|
ui.id = "PDFBug";
|
2016-07-09 08:54:13 +00:00
|
|
|
|
2021-05-14 07:29:24 +00:00
|
|
|
var controls = document.createElement("div");
|
|
|
|
controls.setAttribute("class", "controls");
|
2016-07-09 08:54:13 +00:00
|
|
|
ui.appendChild(controls);
|
|
|
|
|
2021-05-14 07:29:24 +00:00
|
|
|
var panels = document.createElement("div");
|
|
|
|
panels.setAttribute("class", "panels");
|
2016-07-09 08:54:13 +00:00
|
|
|
ui.appendChild(panels);
|
|
|
|
|
|
|
|
container.appendChild(ui);
|
2021-05-14 07:29:24 +00:00
|
|
|
container.style.right = panelWidth + "px";
|
2016-07-09 08:54:13 +00:00
|
|
|
|
|
|
|
// Initialize all the debugging tools.
|
|
|
|
var tools = this.tools;
|
|
|
|
var self = this;
|
|
|
|
for (var i = 0; i < tools.length; ++i) {
|
|
|
|
var tool = tools[i];
|
2021-05-14 07:29:24 +00:00
|
|
|
var panel = document.createElement("div");
|
|
|
|
var panelButton = document.createElement("button");
|
2016-07-09 08:54:13 +00:00
|
|
|
panelButton.textContent = tool.name;
|
2021-05-14 07:29:24 +00:00
|
|
|
panelButton.addEventListener(
|
|
|
|
"click",
|
|
|
|
(function (selected) {
|
|
|
|
return function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
self.selectPanel(selected);
|
|
|
|
};
|
|
|
|
})(i)
|
|
|
|
);
|
2016-07-09 08:54:13 +00:00
|
|
|
controls.appendChild(panelButton);
|
|
|
|
panels.appendChild(panel);
|
|
|
|
tool.panel = panel;
|
|
|
|
tool.manager = this;
|
|
|
|
if (tool.enabled) {
|
|
|
|
tool.init(pdfjsLib);
|
|
|
|
} else {
|
2021-05-14 07:29:24 +00:00
|
|
|
panel.textContent =
|
|
|
|
tool.name +
|
|
|
|
" is disabled. To enable add " +
|
|
|
|
' "' +
|
|
|
|
tool.id +
|
|
|
|
'" to the pdfBug parameter ' +
|
|
|
|
"and refresh (separate multiple by commas).";
|
2016-07-09 08:54:13 +00:00
|
|
|
}
|
|
|
|
buttons.push(panelButton);
|
|
|
|
}
|
|
|
|
this.selectPanel(0);
|
|
|
|
},
|
2019-04-13 13:02:01 +00:00
|
|
|
cleanup() {
|
2016-07-09 08:54:13 +00:00
|
|
|
for (var i = 0, ii = this.tools.length; i < ii; i++) {
|
|
|
|
if (this.tools[i].enabled) {
|
|
|
|
this.tools[i].cleanup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2019-04-13 13:02:01 +00:00
|
|
|
selectPanel(index) {
|
2021-05-14 07:29:24 +00:00
|
|
|
if (typeof index !== "number") {
|
2016-07-09 08:54:13 +00:00
|
|
|
index = this.tools.indexOf(index);
|
|
|
|
}
|
|
|
|
if (index === activePanel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
activePanel = index;
|
|
|
|
var tools = this.tools;
|
|
|
|
for (var j = 0; j < tools.length; ++j) {
|
|
|
|
if (j === index) {
|
2021-05-14 07:29:24 +00:00
|
|
|
buttons[j].setAttribute("class", "active");
|
2016-07-09 08:54:13 +00:00
|
|
|
tools[j].active = true;
|
2021-05-14 07:29:24 +00:00
|
|
|
tools[j].panel.removeAttribute("hidden");
|
2016-07-09 08:54:13 +00:00
|
|
|
} else {
|
2021-05-14 07:29:24 +00:00
|
|
|
buttons[j].setAttribute("class", "");
|
2016-07-09 08:54:13 +00:00
|
|
|
tools[j].active = false;
|
2021-05-14 07:29:24 +00:00
|
|
|
tools[j].panel.setAttribute("hidden", "true");
|
2016-07-09 08:54:13 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-13 13:02:01 +00:00
|
|
|
},
|
2016-07-09 08:54:13 +00:00
|
|
|
};
|
|
|
|
})();
|