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
This commit is contained in:
parent
3db4e7266e
commit
83c499595c
22
src/bidi.js
22
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;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user