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) {
|
function bidiResult(content, direction) {
|
||||||
var str = text.str;
|
this.content = content;
|
||||||
|
this.direction = direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bidi(str, startLevel) {
|
||||||
|
var direction = '';
|
||||||
var strLength = str.length;
|
var strLength = str.length;
|
||||||
if (strLength == 0)
|
if (strLength == 0)
|
||||||
return str;
|
return new bidiResult(str, direction);
|
||||||
|
|
||||||
// get types, fill arrays
|
// 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 less than 30% chars are rtl then string is primarily ltr
|
||||||
// if more than 30% chars are rtl then string is primarily rtl
|
// if more than 30% chars are rtl then string is primarily rtl
|
||||||
if (numBidi == 0) {
|
if (numBidi == 0) {
|
||||||
text.direction = 'ltr';
|
direction = 'ltr';
|
||||||
return str;
|
return new bidiResult(str, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startLevel == -1) {
|
if (startLevel == -1) {
|
||||||
if ((strLength / numBidi) < 0.3) {
|
if ((strLength / numBidi) < 0.3) {
|
||||||
text.direction = 'ltr';
|
direction = 'ltr';
|
||||||
startLevel = 0;
|
startLevel = 0;
|
||||||
} else {
|
} else {
|
||||||
text.direction = 'rtl';
|
direction = 'rtl';
|
||||||
startLevel = 1;
|
startLevel = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -438,7 +443,8 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
|
|||||||
if (ch != '<' && ch != '>')
|
if (ch != '<' && ch != '>')
|
||||||
result += ch;
|
result += ch;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
|
return new bidiResult(str, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bidi;
|
return bidi;
|
||||||
|
@ -1911,9 +1911,8 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) {
|
|||||||
textDiv.style.left = text.geom.x + 'px';
|
textDiv.style.left = text.geom.x + 'px';
|
||||||
textDiv.style.top = (text.geom.y - fontHeight) + 'px';
|
textDiv.style.top = (text.geom.y - fontHeight) + 'px';
|
||||||
|
|
||||||
// The `text.direction` is added inside the PDFJS.bidi function.
|
// The content of the div is set in the `setTextContent` function.
|
||||||
// textDiv.textContent = PDFJS.bidi(text, -1);
|
|
||||||
// textDiv.dir = text.direction;
|
|
||||||
this.textDivs.push(textDiv);
|
this.textDivs.push(textDiv);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1923,7 +1922,11 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) {
|
|||||||
var textDivs = this.textDivs;
|
var textDivs = this.textDivs;
|
||||||
|
|
||||||
for (var i = 0; i < textContent.length; i++) {
|
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();
|
this.setupRenderLayoutTimer();
|
||||||
|
Loading…
Reference in New Issue
Block a user