From 17f1857556bf27146a3647fe01c81f7d29327a97 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Fri, 4 Jun 2021 09:48:30 -0700 Subject: [PATCH] Add more info for showText operator in stepper. Adds a table that shows original char code, font char code, and unicode. --- src/core/fonts.js | 6 ++++++ web/debugger.js | 37 ++++++++++++++++++++++++------------- web/viewer.css | 13 +++++++++++++ 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/core/fonts.js b/src/core/fonts.js index ba9c49528..874f903a8 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -159,6 +159,7 @@ function adjustToUnicode(properties, builtInEncoding) { class Glyph { constructor( + originalCharCode, fontChar, unicode, accent, @@ -168,6 +169,7 @@ class Glyph { isSpace, isInFont ) { + this.originalCharCode = originalCharCode; this.fontChar = fontChar; this.unicode = unicode; this.accent = accent; @@ -179,6 +181,7 @@ class Glyph { } matchesForCache( + originalCharCode, fontChar, unicode, accent, @@ -189,6 +192,7 @@ class Glyph { isInFont ) { return ( + this.originalCharCode === originalCharCode && this.fontChar === fontChar && this.unicode === unicode && this.accent === accent && @@ -2956,6 +2960,7 @@ class Font { if ( !glyph || !glyph.matchesForCache( + charcode, fontChar, unicode, accent, @@ -2967,6 +2972,7 @@ class Font { ) ) { glyph = new Glyph( + charcode, fontChar, unicode, accent, diff --git a/web/debugger.js b/web/debugger.js index 6f8b4a9f0..dcaf267ea 100644 --- a/web/debugger.js +++ b/web/debugger.js @@ -357,27 +357,38 @@ const Stepper = (function StepperClosure() { let decArgs = args; if (fn === "showText") { const glyphs = args[0]; - const newArgs = []; - let str = []; + const charCodeRow = c("tr"); + const fontCharRow = c("tr"); + const unicodeRow = c("tr"); for (let j = 0; j < glyphs.length; j++) { const glyph = glyphs[j]; if (typeof glyph === "object" && glyph !== null) { - str.push(glyph.fontChar); + charCodeRow.appendChild(c("td", glyph.originalCharCode)); + fontCharRow.appendChild(c("td", glyph.fontChar)); + unicodeRow.appendChild(c("td", glyph.unicode)); } else { - if (str.length > 0) { - newArgs.push(str.join("")); - str = []; - } - newArgs.push(glyph); // null or number + // null or number + const advanceEl = c("td", glyph); + advanceEl.classList.add("advance"); + charCodeRow.appendChild(advanceEl); + fontCharRow.appendChild(c("td")); + unicodeRow.appendChild(c("td")); } } - if (str.length > 0) { - newArgs.push(str.join("")); - } - decArgs = [newArgs]; + decArgs = c("td"); + const table = c("table"); + table.classList.add("showText"); + decArgs.appendChild(table); + table.appendChild(charCodeRow); + table.appendChild(fontCharRow); + table.appendChild(unicodeRow); } line.appendChild(c("td", fn)); - line.appendChild(c("td", JSON.stringify(simplifyArgs(decArgs)))); + if (decArgs instanceof HTMLElement) { + line.appendChild(decArgs); + } else { + line.appendChild(c("td", JSON.stringify(simplifyArgs(decArgs)))); + } } if (operatorsToDisplay < operatorList.fnArray.length) { const lastCell = c("td", "..."); diff --git a/web/viewer.css b/web/viewer.css index ee03ee920..419293476 100644 --- a/web/viewer.css +++ b/web/viewer.css @@ -1699,6 +1699,19 @@ html[dir="rtl"] #documentPropertiesOverlay .row > * { #PDFBug table { font-size: 10px; } +#PDFBug table.showText { + border-collapse: collapse; + text-align: center; +} +#PDFBug table.showText, +#PDFBug table.showText tr, +#PDFBug table.showText td { + border: 1px solid black; + padding: 1px; +} +#PDFBug table.showText td.advance { + color: grey; +} #viewer.textLayer-visible .textLayer { opacity: 1;