From 83c499595c2720a90fe9409c0a3fd1e08c16745c Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Tue, 11 Sep 2012 16:42:24 -0700 Subject: [PATCH] Change the PDFJS.bidi function calls slightly to avoid creating a seperate object to pass to PDF.JS bidi and just pass in a string --- src/bidi.js | 22 ++++++++++++++-------- web/viewer.js | 11 +++++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/bidi.js b/src/bidi.js index cf0a3a4cc..ed7b3f35c 100644 --- a/src/bidi.js +++ b/src/bidi.js @@ -138,11 +138,16 @@ var bidi = PDFJS.bidi = (function bidiClosure() { } } - function bidi(text, startLevel) { - var str = text.str; + function bidiResult(content, direction) { + this.content = content; + this.direction = direction; + } + + function bidi(str, startLevel) { + var direction = ''; var strLength = str.length; if (strLength == 0) - return str; + return new bidiResult(str, direction); // get types, fill arrays @@ -176,16 +181,16 @@ var bidi = PDFJS.bidi = (function bidiClosure() { // if less than 30% chars are rtl then string is primarily ltr // if more than 30% chars are rtl then string is primarily rtl if (numBidi == 0) { - text.direction = 'ltr'; - return str; + direction = 'ltr'; + return new bidiResult(str, direction); } if (startLevel == -1) { if ((strLength / numBidi) < 0.3) { - text.direction = 'ltr'; + direction = 'ltr'; startLevel = 0; } else { - text.direction = 'rtl'; + direction = 'rtl'; startLevel = 1; } } @@ -438,7 +443,8 @@ var bidi = PDFJS.bidi = (function bidiClosure() { if (ch != '<' && ch != '>') result += ch; } - return result; + + return new bidiResult(str, direction); } return bidi; diff --git a/web/viewer.js b/web/viewer.js index b0bb0e475..d87c804ae 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -1911,9 +1911,8 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) { textDiv.style.left = text.geom.x + 'px'; textDiv.style.top = (text.geom.y - fontHeight) + 'px'; - // The `text.direction` is added inside the PDFJS.bidi function. - // textDiv.textContent = PDFJS.bidi(text, -1); - // textDiv.dir = text.direction; + // The content of the div is set in the `setTextContent` function. + this.textDivs.push(textDiv); }; @@ -1923,7 +1922,11 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) { var textDivs = this.textDivs; for (var i = 0; i < textContent.length; i++) { - textDivs[i].textContent = textContent[i]; + var textDiv = textDivs[i]; + var bidiText = PDFJS.bidi(textContent[i], -1); + + textDiv.textContent = bidiText.content; + textDiv.dir = bidiText.direction; } this.setupRenderLayoutTimer();