mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Attempt to ignore multiple identical Tf (setFont) commands in PartialEvaluator_getTextContent
(issue 5808)
This patch improves the performance of issue 5808, but I'm not sure if it's enough to call it fixed. On average, this patch reduces the number of textLayer div's by a factor of 3, and it also reduces the time spend in `getTextContent` by a factor of ~2. The PDF file is generated by `Scribus PDF`, which for reasons I cannot understand is placing redundant `Tf` commands before *every* showText command. Note how the PDF file also contains lots of (basically) identical fonts, but with slightly different names, which causes unnecessary font-switching. This causes some unnecessary breaking of textLayer div's, but this issue cannot be easily worked around.
This commit is contained in:
parent
19105f0669
commit
77c6ed5389
4 changed files with 169 additions and 2 deletions
|
@ -1423,9 +1423,17 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
|
||||
switch (fn | 0) {
|
||||
case OPS.setFont:
|
||||
// Optimization to ignore multiple identical Tf commands.
|
||||
var fontNameArg = args[0].name, fontSizeArg = args[1];
|
||||
if (textState.font && fontNameArg === textState.fontName &&
|
||||
fontSizeArg === textState.fontSize) {
|
||||
break;
|
||||
}
|
||||
|
||||
flushTextContentItem();
|
||||
textState.fontSize = args[1];
|
||||
next(handleSetFont(args[0].name, null));
|
||||
textState.fontName = fontNameArg;
|
||||
textState.fontSize = fontSizeArg;
|
||||
next(handleSetFont(fontNameArg, null));
|
||||
return;
|
||||
case OPS.setTextRise:
|
||||
flushTextContentItem();
|
||||
|
@ -1643,6 +1651,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
}
|
||||
var gStateFont = gState.get('Font');
|
||||
if (gStateFont) {
|
||||
textState.fontName = null;
|
||||
textState.fontSize = gStateFont[1];
|
||||
next(handleSetFont(null, gStateFont[0]));
|
||||
return;
|
||||
|
@ -2562,6 +2571,7 @@ var StateManager = (function StateManagerClosure() {
|
|||
var TextState = (function TextStateClosure() {
|
||||
function TextState() {
|
||||
this.ctm = new Float32Array(IDENTITY_MATRIX);
|
||||
this.fontName = null;
|
||||
this.fontSize = 0;
|
||||
this.font = null;
|
||||
this.fontMatrix = FONT_IDENTITY_MATRIX;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue