From: Artur Adib Date: Wed, 18 Jan 2012 17:07:25 +0000 (-0500) Subject: Fix previous commit X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=1c7f1b98819ad9d3b8f8e91622974e634a12e041;p=pdf.js.git Fix previous commit --- diff --git a/web/viewer.js b/web/viewer.js index 319946c..bfa5467 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -973,14 +973,18 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) { return; } var textDiv = textDivs.shift(); - if (textDiv.dataset.textLength > 1) { // avoid div by zero - // Adjust div width (via letterSpacing) to match canvas text - // Due to the .offsetWidth calls, this is slow - textDiv.style.letterSpacing = - ((textDiv.dataset.canvasWidth - textDiv.offsetWidth) / - (textDiv.dataset.textLength - 1)) + 'px'; - } - textLayerDiv.appendChild(textDiv); + if (textDiv.dataset.textLength > 0) { + textLayerDiv.appendChild(textDiv); + + if (textDiv.dataset.textLength > 1) { // avoid div by zero + // Adjust div width (via letterSpacing) to match canvas text + // Due to the .offsetWidth calls, this is slow + // **This needs to come after appending to the DOM** + textDiv.style.letterSpacing = + ((textDiv.dataset.canvasWidth - textDiv.offsetWidth) / + (textDiv.dataset.textLength - 1)) + 'px'; + } + } // textLength > 0 } renderTimer = setInterval(renderTextLayer, renderInterval);