[Pkg-javascript-commits] [pdf.js] 149/210: Handle nested post script arguments in the preprocessor

David Prévot taffit at moszumanska.debian.org
Thu Jun 5 14:21:12 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch upstream
in repository pdf.js.

commit 3e7bcaa89202394154b8f4a47defacabeae820a9
Author: Christian Krebs <chrisk at opera.com>
Date:   Thu May 15 08:07:43 2014 +0200

    Handle nested post script arguments in the preprocessor
    
    Fix for issue #4785
---
 src/core/evaluator.js       | 12 ++++++++++++
 test/unit/evaluator_spec.js | 22 ++++++++++++++++++----
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/core/evaluator.js b/src/core/evaluator.js
index 70fcc6a..29411bb 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -1846,6 +1846,7 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
     // dictionary
     this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
     this.stateManager = stateManager;
+    this.nonProcessedArgs = [];
   }
 
   EvaluatorPreprocessor.prototype = {
@@ -1879,6 +1880,17 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
 
         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
         if (opSpec.variableArgs) {
           if (args.length > opSpec.numArgs) {
diff --git a/test/unit/evaluator_spec.js b/test/unit/evaluator_spec.js
index 23722be..1786ceb 100644
--- a/test/unit/evaluator_spec.js
+++ b/test/unit/evaluator_spec.js
@@ -18,7 +18,7 @@ describe('evaluator', function() {
   }
   HandlerMock.prototype = {
     send: function(name, data) {
-      this.inputs({name: name, data: data});
+      this.inputs.push({name: name, data: data});
     }
   };
   function ResourcesMock() { }
@@ -149,11 +149,25 @@ describe('evaluator', function() {
                                            'prefix');
       var stream = new StringStream('5 1 4 d0');
       var result = evaluator.getOperatorList(stream, new ResourcesMock());
-      expect(result.argsArray[0][0]).toEqual(5);
-      expect(result.argsArray[0][1]).toEqual(1);
-      expect(result.argsArray[0][2]).toEqual(4);
+      expect(result.argsArray[0][0]).toEqual(1);
+      expect(result.argsArray[0][1]).toEqual(4);
       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() {
       var evaluator = new PartialEvaluator(new PdfManagerMock(),
                                            new XrefMock(), new HandlerMock(),

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list