1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 07:08:08 +02:00

Refactor text extraction / font loading logic

This commit is contained in:
Yury Delendik 2012-09-13 08:09:46 -07:00
parent 6fc70bb2a7
commit e086cf36f4
4 changed files with 98 additions and 144 deletions

View file

@ -1844,22 +1844,18 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) {
return;
}
var textDiv = textDivs.shift();
if (textDiv.dataset.textLength > 0) {
textLayerDiv.appendChild(textDiv);
textLayerDiv.appendChild(textDiv);
if (textDiv.dataset.textLength > 1) { // avoid div by zero
// Adjust div width to match canvas text
ctx.font = textDiv.style.fontSize + ' sans-serif';
var width = ctx.measureText(textDiv.textContent).width;
ctx.font = textDiv.style.fontSize + ' sans-serif';
var width = ctx.measureText(textDiv.textContent).width;
if (width > 0) {
var textScale = textDiv.dataset.canvasWidth / width;
var textScale = textDiv.dataset.canvasWidth / width;
CustomStyle.setProp('transform' , textDiv,
'scale(' + textScale + ', 1)');
CustomStyle.setProp('transformOrigin' , textDiv, '0% 0%');
}
} // textLength > 0
CustomStyle.setProp('transform' , textDiv,
'scale(' + textScale + ', 1)');
CustomStyle.setProp('transformOrigin' , textDiv, '0% 0%');
}
}
renderTimer = setInterval(renderTextLayer, renderInterval);
@ -1899,7 +1895,6 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) {
textDiv.style.top = (text.geom.y - fontHeight) + 'px';
textDiv.textContent = PDFJS.bidi(text, -1);
textDiv.dir = text.direction;
textDiv.dataset.textLength = text.length;
this.textDivs.push(textDiv);
};
};
@ -2068,7 +2063,7 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
});
document.getElementById('searchTermsInput').addEventListener('keydown',
function() {
function(event) {
if (event.keyCode == 13) {
PDFView.search();
}