Fix previous commit

This commit is contained in:
Artur Adib 2012-01-18 12:07:25 -05:00
parent 5f4d462144
commit 1c7f1b9881

View File

@ -973,14 +973,18 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) {
return; return;
} }
var textDiv = textDivs.shift(); var textDiv = textDivs.shift();
if (textDiv.dataset.textLength > 1) { // avoid div by zero if (textDiv.dataset.textLength > 0) {
// Adjust div width (via letterSpacing) to match canvas text textLayerDiv.appendChild(textDiv);
// Due to the .offsetWidth calls, this is slow
textDiv.style.letterSpacing = if (textDiv.dataset.textLength > 1) { // avoid div by zero
((textDiv.dataset.canvasWidth - textDiv.offsetWidth) / // Adjust div width (via letterSpacing) to match canvas text
(textDiv.dataset.textLength - 1)) + 'px'; // Due to the .offsetWidth calls, this is slow
} // **This needs to come after appending to the DOM**
textLayerDiv.appendChild(textDiv); textDiv.style.letterSpacing =
((textDiv.dataset.canvasWidth - textDiv.offsetWidth) /
(textDiv.dataset.textLength - 1)) + 'px';
}
} // textLength > 0
} }
renderTimer = setInterval(renderTextLayer, renderInterval); renderTimer = setInterval(renderTextLayer, renderInterval);