mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
Merge pull request #4444 from nnethercote/min-length
Estimate the size of decoded streams in advance.
This commit is contained in:
commit
1c0e1cc591
5 changed files with 85 additions and 60 deletions
|
@ -645,7 +645,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
var preprocessor = new EvaluatorPreprocessor(stream, xref);
|
||||
var res = resources;
|
||||
|
||||
var chunk = '';
|
||||
var chunkBuf = [];
|
||||
var font = null;
|
||||
var charSpace = 0, wordSpace = 0;
|
||||
var operation;
|
||||
|
@ -694,37 +694,37 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
var items = args[0];
|
||||
for (var j = 0, jj = items.length; j < jj; j++) {
|
||||
if (typeof items[j] === 'string') {
|
||||
chunk += fontCharsToUnicode(items[j], font);
|
||||
chunkBuf.push(fontCharsToUnicode(items[j], font));
|
||||
} else if (items[j] < 0 && font.spaceWidth > 0) {
|
||||
var fakeSpaces = -items[j] / font.spaceWidth;
|
||||
if (fakeSpaces > MULTI_SPACE_FACTOR) {
|
||||
fakeSpaces = Math.round(fakeSpaces);
|
||||
while (fakeSpaces--) {
|
||||
chunk += ' ';
|
||||
chunkBuf.push(' ');
|
||||
}
|
||||
} else if (fakeSpaces > SPACE_FACTOR) {
|
||||
chunk += ' ';
|
||||
chunkBuf.push(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OPS.showText:
|
||||
chunk += fontCharsToUnicode(args[0], font);
|
||||
chunkBuf.push(fontCharsToUnicode(args[0], font));
|
||||
break;
|
||||
case OPS.nextLineShowText:
|
||||
// For search, adding a extra white space for line breaks would be
|
||||
// better here, but that causes too much spaces in the
|
||||
// text-selection divs.
|
||||
chunk += fontCharsToUnicode(args[0], font);
|
||||
chunkBuf.push(fontCharsToUnicode(args[0], font));
|
||||
break;
|
||||
case OPS.nextLineSetSpacingShowText:
|
||||
// Note comment in "'"
|
||||
chunk += fontCharsToUnicode(args[2], font);
|
||||
chunkBuf.push(fontCharsToUnicode(args[2], font));
|
||||
break;
|
||||
case OPS.paintXObject:
|
||||
// Set the chunk such that the following if won't add something
|
||||
// to the state.
|
||||
chunk = '';
|
||||
chunkBuf.length = 0;
|
||||
|
||||
if (args[0].code) {
|
||||
break;
|
||||
|
@ -773,7 +773,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
break;
|
||||
} // switch
|
||||
|
||||
if (chunk !== '') {
|
||||
if (chunkBuf.length > 0) {
|
||||
var chunk = chunkBuf.join('');
|
||||
var bidiResult = PDFJS.bidi(chunk, -1, font.vertical);
|
||||
var bidiText = {
|
||||
str: bidiResult.str,
|
||||
|
@ -795,7 +796,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
bidiText.size = fontHeight;
|
||||
bidiTexts.push(bidiText);
|
||||
|
||||
chunk = '';
|
||||
chunkBuf.length = 0;
|
||||
}
|
||||
} // while
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue