mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Ensure that there's always a setFont (Tf) operator before text rendering operators (issue 11651)
The PDF document in question is *corrupt*, since it contains multiple instances of incorrect operators. We obviously don't want to slow down parsing of *all* documents (since most are valid), just to accommodate a particular bad PDF generator, hence the reason for the inline check before calling the `ensureStateFont` method.
This commit is contained in:
parent
52749d1f0d
commit
65e514e063
4 changed files with 67 additions and 0 deletions
|
@ -795,6 +795,26 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
return glyphs;
|
||||
},
|
||||
|
||||
ensureStateFont(state) {
|
||||
if (state.font) {
|
||||
return;
|
||||
}
|
||||
const reason = new FormatError(
|
||||
"Missing setFont (Tf) operator before text rendering operator."
|
||||
);
|
||||
|
||||
if (this.options.ignoreErrors) {
|
||||
// Missing setFont operator before text rendering operator -- sending
|
||||
// unsupported feature notification and allow rendering to continue.
|
||||
this.handler.send("UnsupportedFeature", {
|
||||
featureId: UNSUPPORTED_FEATURES.font,
|
||||
});
|
||||
warn(`ensureStateFont: "${reason}".`);
|
||||
return;
|
||||
}
|
||||
throw reason;
|
||||
},
|
||||
|
||||
setGState: function PartialEvaluator_setGState(
|
||||
resources,
|
||||
gState,
|
||||
|
@ -1364,9 +1384,17 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
);
|
||||
return;
|
||||
case OPS.showText:
|
||||
if (!stateManager.state.font) {
|
||||
self.ensureStateFont(stateManager.state);
|
||||
continue;
|
||||
}
|
||||
args[0] = self.handleText(args[0], stateManager.state);
|
||||
break;
|
||||
case OPS.showSpacedText:
|
||||
if (!stateManager.state.font) {
|
||||
self.ensureStateFont(stateManager.state);
|
||||
continue;
|
||||
}
|
||||
var arr = args[0];
|
||||
var combinedGlyphs = [];
|
||||
var arrLength = arr.length;
|
||||
|
@ -1386,11 +1414,19 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
fn = OPS.showText;
|
||||
break;
|
||||
case OPS.nextLineShowText:
|
||||
if (!stateManager.state.font) {
|
||||
self.ensureStateFont(stateManager.state);
|
||||
continue;
|
||||
}
|
||||
operatorList.addOp(OPS.nextLine);
|
||||
args[0] = self.handleText(args[0], stateManager.state);
|
||||
fn = OPS.showText;
|
||||
break;
|
||||
case OPS.nextLineSetSpacingShowText:
|
||||
if (!stateManager.state.font) {
|
||||
self.ensureStateFont(stateManager.state);
|
||||
continue;
|
||||
}
|
||||
operatorList.addOp(OPS.nextLine);
|
||||
operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
|
||||
operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
|
||||
|
@ -2056,6 +2092,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
textState.textLineMatrix = IDENTITY_MATRIX.slice();
|
||||
break;
|
||||
case OPS.showSpacedText:
|
||||
if (!stateManager.state.font) {
|
||||
self.ensureStateFont(stateManager.state);
|
||||
continue;
|
||||
}
|
||||
var items = args[0];
|
||||
var offset;
|
||||
for (var j = 0, jj = items.length; j < jj; j++) {
|
||||
|
@ -2105,14 +2145,26 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
}
|
||||
break;
|
||||
case OPS.showText:
|
||||
if (!stateManager.state.font) {
|
||||
self.ensureStateFont(stateManager.state);
|
||||
continue;
|
||||
}
|
||||
buildTextContentItem(args[0]);
|
||||
break;
|
||||
case OPS.nextLineShowText:
|
||||
if (!stateManager.state.font) {
|
||||
self.ensureStateFont(stateManager.state);
|
||||
continue;
|
||||
}
|
||||
flushTextContentItem();
|
||||
textState.carriageReturn();
|
||||
buildTextContentItem(args[0]);
|
||||
break;
|
||||
case OPS.nextLineSetSpacingShowText:
|
||||
if (!stateManager.state.font) {
|
||||
self.ensureStateFont(stateManager.state);
|
||||
continue;
|
||||
}
|
||||
flushTextContentItem();
|
||||
textState.wordSpacing = args[0];
|
||||
textState.charSpacing = args[1];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue