Handle nested post script arguments in the preprocessor
Fix for issue #4785
This commit is contained in:
parent
6d330250da
commit
3e7bcaa892
@ -1846,6 +1846,7 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
|
|||||||
// dictionary
|
// dictionary
|
||||||
this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
|
this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
|
||||||
this.stateManager = stateManager;
|
this.stateManager = stateManager;
|
||||||
|
this.nonProcessedArgs = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
EvaluatorPreprocessor.prototype = {
|
EvaluatorPreprocessor.prototype = {
|
||||||
@ -1879,6 +1880,17 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
|
|||||||
|
|
||||||
var fn = opSpec.id;
|
var fn = opSpec.id;
|
||||||
|
|
||||||
|
// Some post script commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
|
||||||
|
if (!opSpec.variableArgs && args.length !== opSpec.numArgs) {
|
||||||
|
while (args.length > opSpec.numArgs) {
|
||||||
|
this.nonProcessedArgs.push(args.shift());
|
||||||
|
}
|
||||||
|
|
||||||
|
while (args.length < opSpec.numArgs && this.nonProcessedArgs.length) {
|
||||||
|
args.unshift(this.nonProcessedArgs.pop());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Validate the number of arguments for the command
|
// Validate the number of arguments for the command
|
||||||
if (opSpec.variableArgs) {
|
if (opSpec.variableArgs) {
|
||||||
if (args.length > opSpec.numArgs) {
|
if (args.length > opSpec.numArgs) {
|
||||||
|
@ -18,7 +18,7 @@ describe('evaluator', function() {
|
|||||||
}
|
}
|
||||||
HandlerMock.prototype = {
|
HandlerMock.prototype = {
|
||||||
send: function(name, data) {
|
send: function(name, data) {
|
||||||
this.inputs({name: name, data: data});
|
this.inputs.push({name: name, data: data});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function ResourcesMock() { }
|
function ResourcesMock() { }
|
||||||
@ -149,11 +149,25 @@ describe('evaluator', function() {
|
|||||||
'prefix');
|
'prefix');
|
||||||
var stream = new StringStream('5 1 4 d0');
|
var stream = new StringStream('5 1 4 d0');
|
||||||
var result = evaluator.getOperatorList(stream, new ResourcesMock());
|
var result = evaluator.getOperatorList(stream, new ResourcesMock());
|
||||||
expect(result.argsArray[0][0]).toEqual(5);
|
expect(result.argsArray[0][0]).toEqual(1);
|
||||||
expect(result.argsArray[0][1]).toEqual(1);
|
expect(result.argsArray[0][1]).toEqual(4);
|
||||||
expect(result.argsArray[0][2]).toEqual(4);
|
|
||||||
expect(result.fnArray[0]).toEqual(OPS.setCharWidth);
|
expect(result.fnArray[0]).toEqual(OPS.setCharWidth);
|
||||||
});
|
});
|
||||||
|
it('should execute if nested commands', function() {
|
||||||
|
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||||
|
new XrefMock(), new HandlerMock(),
|
||||||
|
'prefix');
|
||||||
|
var stream = new StringStream('/F2 /GS2 gs 5.711 Tf');
|
||||||
|
var result = evaluator.getOperatorList(stream, new ResourcesMock());
|
||||||
|
expect(result.fnArray.length).toEqual(3);
|
||||||
|
expect(result.fnArray[0]).toEqual(OPS.setGState);
|
||||||
|
expect(result.fnArray[1]).toEqual(OPS.dependency);
|
||||||
|
expect(result.fnArray[2]).toEqual(OPS.setFont);
|
||||||
|
expect(result.argsArray.length).toEqual(3);
|
||||||
|
expect(result.argsArray[0].length).toEqual(1);
|
||||||
|
expect(result.argsArray[1].length).toEqual(1);
|
||||||
|
expect(result.argsArray[2].length).toEqual(2);
|
||||||
|
});
|
||||||
it('should skip if too few arguments', function() {
|
it('should skip if too few arguments', function() {
|
||||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||||
new XrefMock(), new HandlerMock(),
|
new XrefMock(), new HandlerMock(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user