[Pkg-javascript-commits] [pdf.js] 198/246: Refactors SVG api

David Prévot taffit at moszumanska.debian.org
Sun Sep 7 15:36:40 UTC 2014


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

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

commit bc574aa629b968107a8cc35ff08b0953731f10b6
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Thu Aug 14 12:56:11 2014 -0500

    Refactors SVG api
---
 examples/node/pdf2svg.js     |  4 ++--
 examples/svgviewer/viewer.js |  4 ++--
 src/display/svg.js           | 49 +++++++++++++++++++++++---------------------
 3 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/examples/node/pdf2svg.js b/examples/node/pdf2svg.js
index 6da69b1..4827149 100644
--- a/examples/node/pdf2svg.js
+++ b/examples/node/pdf2svg.js
@@ -65,8 +65,8 @@ PDFJS.getDocument(data).then(function (doc) {
       
       return page.getOperatorList().then(function (opList) {
         var svgGfx = new PDFJS.SVGGraphics(page.commonObjs, page.objs);
-        return svgGfx.loadDependencies(opList).then(function (values) {
-          var svgDump = svgGfx.getSVG(viewport, pageNum, opList).toString();
+        return svgGfx.getSVG(opList, viewport).then(function (svg) {
+          var svgDump = svg.toString();
           writeToFile(svgDump, pageNum);
         });
       });
diff --git a/examples/svgviewer/viewer.js b/examples/svgviewer/viewer.js
index 90d8de3..ddbb6fa 100644
--- a/examples/svgviewer/viewer.js
+++ b/examples/svgviewer/viewer.js
@@ -48,8 +48,8 @@ PDFJS.getDocument(url).then(function(pdf) {
 
         return page.getOperatorList().then(function (opList) {
           var svgGfx = new PDFJS.SVGGraphics(page.commonObjs, page.objs);
-          return svgGfx.loadDependencies(opList).then(function (values) {
-            container.appendChild(svgGfx.getSVG(viewport, pageNum, opList));
+          return svgGfx.getSVG(opList, viewport).then(function (svg) {
+            container.appendChild(svg);
           });
         });
       });
diff --git a/src/display/svg.js b/src/display/svg.js
index 124861a..3c8fd24 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -19,16 +19,6 @@
 
 'use strict';
 
-function createScratchSVG(width, height) {
-  var NS = 'http://www.w3.org/2000/svg';
-  var svg = document.createElementNS(NS, 'svg:svg');
-  svg.setAttributeNS(null, 'version', '1.1');
-  svg.setAttributeNS(null, 'width', width + 'px');
-  svg.setAttributeNS(null, 'height', height + 'px');
-  svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
-  return svg;
-}
-
 var convertImgDataToPng = (function convertImgDataToPngClosure() {
   var PNG_HEADER =
     new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
@@ -281,6 +271,16 @@ var SVGExtraState = (function SVGExtraStateClosure() {
 })();
 
 var SVGGraphics = (function SVGGraphicsClosure() {
+  function createScratchSVG(width, height) {
+    var NS = 'http://www.w3.org/2000/svg';
+    var svg = document.createElementNS(NS, 'svg:svg');
+    svg.setAttributeNS(null, 'version', '1.1');
+    svg.setAttributeNS(null, 'width', width + 'px');
+    svg.setAttributeNS(null, 'height', height + 'px');
+    svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
+    return svg;
+  }
+
   function opListToTree(opList) {
     var opTree = [];
     var tmp = [];
@@ -431,21 +431,24 @@ var SVGGraphics = (function SVGGraphicsClosure() {
       this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
     },
 
-    getSVG: function SVGGraphics_getSVG(viewport, pageNum, operatorList) {
+    getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
       this.svg = createScratchSVG(viewport.width, viewport.height);
       this.viewport = viewport;
-      this.transformMatrix = IDENTITY_MATRIX;
-      this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
-      this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
-      this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
-      this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
-      this.defs = document.createElementNS(NS, 'svg:defs');
-      this.pgrp.appendChild(this.defs);
-      this.pgrp.appendChild(this.tgrp);
-      this.svg.appendChild(this.pgrp);
-      var opTree = this.convertOpList(operatorList);
-      this.executeOpTree(opTree);
-      return this.svg;
+
+      return this.loadDependencies(operatorList).then(function () {
+        this.transformMatrix = IDENTITY_MATRIX;
+        this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
+        this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
+        this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
+        this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
+        this.defs = document.createElementNS(NS, 'svg:defs');
+        this.pgrp.appendChild(this.defs);
+        this.pgrp.appendChild(this.tgrp);
+        this.svg.appendChild(this.pgrp);
+        var opTree = this.convertOpList(operatorList);
+        this.executeOpTree(opTree);
+        return this.svg;
+      }.bind(this));
     },
 
     convertOpList: function SVGGraphics_convertOpList(operatorList) {

-- 
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