Browse Source

PDF.js version 1.9.607 - See mozilla/pdf.js@b3f84112643c31d0260460c19f1c67cf3acdbc07

pdfjsbot 7 years ago
parent
commit
ac98014536

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "pdfjs-dist",
-  "version": "1.9.604",
+  "version": "1.9.607",
   "main": [
     "build/pdf.js",
     "build/pdf.worker.js"

File diff suppressed because it is too large
+ 102 - 1078
build/pdf.combined.js


File diff suppressed because it is too large
+ 0 - 0
build/pdf.combined.js.map


+ 7 - 7
build/pdf.js

@@ -2949,7 +2949,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
   if (worker.destroyed) {
     return Promise.reject(new Error('Worker was destroyed'));
   }
-  var apiVersion = '1.9.604';
+  var apiVersion = '1.9.607';
   source.disableAutoFetch = (0, _dom_utils.getDefaultSetting)('disableAutoFetch');
   source.disableStream = (0, _dom_utils.getDefaultSetting)('disableStream');
   source.chunkedViewerLoading = !!pdfDataRangeTransport;
@@ -4340,8 +4340,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() {
 }();
 var version, build;
 {
-  exports.version = version = '1.9.604';
-  exports.build = build = 'f206ee56';
+  exports.version = version = '1.9.607';
+  exports.build = build = 'b3f84112';
 }
 exports.getDocument = getDocument;
 exports.LoopbackPort = LoopbackPort;
@@ -7413,8 +7413,8 @@ exports.SVGGraphics = SVGGraphics;
 "use strict";
 
 
-var pdfjsVersion = '1.9.604';
-var pdfjsBuild = 'f206ee56';
+var pdfjsVersion = '1.9.607';
+var pdfjsBuild = 'b3f84112';
 var pdfjsSharedUtil = __w_pdfjs_require__(0);
 var pdfjsDisplayGlobal = __w_pdfjs_require__(82);
 var pdfjsDisplayAPI = __w_pdfjs_require__(48);
@@ -13276,8 +13276,8 @@ if (!_global_scope2.default.PDFJS) {
 }
 var PDFJS = _global_scope2.default.PDFJS;
 {
-  PDFJS.version = '1.9.604';
-  PDFJS.build = 'f206ee56';
+  PDFJS.version = '1.9.607';
+  PDFJS.build = 'b3f84112';
 }
 PDFJS.pdfBug = false;
 if (PDFJS.verbosity !== undefined) {

File diff suppressed because it is too large
+ 0 - 0
build/pdf.js.map


File diff suppressed because it is too large
+ 0 - 0
build/pdf.min.js


File diff suppressed because it is too large
+ 102 - 1078
build/pdf.worker.js


File diff suppressed because it is too large
+ 0 - 0
build/pdf.worker.js.map


File diff suppressed because it is too large
+ 0 - 0
build/pdf.worker.min.js


+ 14 - 16
lib/core/colorspace.js

@@ -23,8 +23,6 @@ var _util = require('../shared/util');
 
 var _primitives = require('./primitives');
 
-var _function = require('./function');
-
 var ColorSpace = function ColorSpaceClosure() {
   function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
     var COMPONENTS = 3;
@@ -134,11 +132,11 @@ var ColorSpace = function ColorSpaceClosure() {
     },
     usesZeroToOneRange: true
   };
-  ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
-    var IR = ColorSpace.parseToIR(cs, xref, res);
-    return ColorSpace.fromIR(IR);
+  ColorSpace.parse = function (cs, xref, res, pdfFunctionFactory) {
+    var IR = ColorSpace.parseToIR(cs, xref, res, pdfFunctionFactory);
+    return ColorSpace.fromIR(IR, pdfFunctionFactory);
   };
-  ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
+  ColorSpace.fromIR = function (IR, pdfFunctionFactory) {
     var name = Array.isArray(IR) ? IR[0] : IR;
     var whitePoint, blackPoint, gamma;
     switch (name) {
@@ -162,19 +160,19 @@ var ColorSpace = function ColorSpaceClosure() {
       case 'PatternCS':
         var basePatternCS = IR[1];
         if (basePatternCS) {
-          basePatternCS = ColorSpace.fromIR(basePatternCS);
+          basePatternCS = ColorSpace.fromIR(basePatternCS, pdfFunctionFactory);
         }
         return new PatternCS(basePatternCS);
       case 'IndexedCS':
         var baseIndexedCS = IR[1];
         var hiVal = IR[2];
         var lookup = IR[3];
-        return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
+        return new IndexedCS(ColorSpace.fromIR(baseIndexedCS, pdfFunctionFactory), hiVal, lookup);
       case 'AlternateCS':
         var numComps = IR[1];
         var alt = IR[2];
         var tintFnIR = IR[3];
-        return new AlternateCS(numComps, ColorSpace.fromIR(alt), _function.PDFFunction.fromIR(tintFnIR));
+        return new AlternateCS(numComps, ColorSpace.fromIR(alt, pdfFunctionFactory), pdfFunctionFactory.createFromIR(tintFnIR));
       case 'LabCS':
         whitePoint = IR[1];
         blackPoint = IR[2];
@@ -184,7 +182,7 @@ var ColorSpace = function ColorSpaceClosure() {
         throw new _util.FormatError('Unknown colorspace name: ' + name);
     }
   };
-  ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
+  ColorSpace.parseToIR = function (cs, xref, res, pdfFunctionFactory) {
     if ((0, _primitives.isName)(cs)) {
       var colorSpaces = res.get('ColorSpace');
       if ((0, _primitives.isDict)(colorSpaces)) {
@@ -244,8 +242,8 @@ var ColorSpace = function ColorSpaceClosure() {
           numComps = dict.get('N');
           alt = dict.get('Alternate');
           if (alt) {
-            var altIR = ColorSpace.parseToIR(alt, xref, res);
-            var altCS = ColorSpace.fromIR(altIR);
+            var altIR = ColorSpace.parseToIR(alt, xref, res, pdfFunctionFactory);
+            var altCS = ColorSpace.fromIR(altIR, pdfFunctionFactory);
             if (altCS.numComps === numComps) {
               return altIR;
             }
@@ -262,12 +260,12 @@ var ColorSpace = function ColorSpaceClosure() {
         case 'Pattern':
           var basePatternCS = cs[1] || null;
           if (basePatternCS) {
-            basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
+            basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res, pdfFunctionFactory);
           }
           return ['PatternCS', basePatternCS];
         case 'Indexed':
         case 'I':
-          var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
+          var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res, pdfFunctionFactory);
           var hiVal = xref.fetchIfRef(cs[2]) + 1;
           var lookup = xref.fetchIfRef(cs[3]);
           if ((0, _primitives.isStream)(lookup)) {
@@ -278,8 +276,8 @@ var ColorSpace = function ColorSpaceClosure() {
         case 'DeviceN':
           var name = xref.fetchIfRef(cs[1]);
           numComps = Array.isArray(name) ? name.length : 1;
-          alt = ColorSpace.parseToIR(cs[2], xref, res);
-          var tintFnIR = _function.PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
+          alt = ColorSpace.parseToIR(cs[2], xref, res, pdfFunctionFactory);
+          var tintFnIR = pdfFunctionFactory.createIR(xref.fetchIfRef(cs[3]));
           return ['AlternateCS', numComps, alt, tintFnIR];
         case 'Lab':
           params = xref.fetchIfRef(cs[1]);

+ 51 - 27
lib/core/document.js

@@ -45,7 +45,16 @@ var Page = function PageClosure() {
   function isAnnotationRenderable(annotation, intent) {
     return intent === 'display' && annotation.viewable || intent === 'print' && annotation.printable;
   }
-  function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache, builtInCMapCache) {
+  function Page(_ref) {
+    var pdfManager = _ref.pdfManager,
+        xref = _ref.xref,
+        pageIndex = _ref.pageIndex,
+        pageDict = _ref.pageDict,
+        ref = _ref.ref,
+        fontCache = _ref.fontCache,
+        builtInCMapCache = _ref.builtInCMapCache,
+        pdfFunctionFactory = _ref.pdfFunctionFactory;
+
     this.pdfManager = pdfManager;
     this.pageIndex = pageIndex;
     this.pageDict = pageDict;
@@ -53,6 +62,7 @@ var Page = function PageClosure() {
     this.ref = ref;
     this.fontCache = fontCache;
     this.builtInCMapCache = builtInCMapCache;
+    this.pdfFunctionFactory = pdfFunctionFactory;
     this.evaluatorOptions = pdfManager.evaluatorOptions;
     this.resourcesPromise = null;
     var uniquePrefix = 'p' + this.pageIndex + '_';
@@ -172,13 +182,13 @@ var Page = function PageClosure() {
         return objectLoader.load();
       });
     },
-    getOperatorList: function getOperatorList(_ref) {
+    getOperatorList: function getOperatorList(_ref2) {
       var _this2 = this;
 
-      var handler = _ref.handler,
-          task = _ref.task,
-          intent = _ref.intent,
-          renderInteractiveForms = _ref.renderInteractiveForms;
+      var handler = _ref2.handler,
+          task = _ref2.task,
+          intent = _ref2.intent,
+          renderInteractiveForms = _ref2.renderInteractiveForms;
 
       var contentStreamPromise = this.pdfManager.ensure(this, 'getContentStream');
       var resourcesPromise = this.loadResources(['ExtGState', 'ColorSpace', 'Pattern', 'Shading', 'XObject', 'Font']);
@@ -190,12 +200,13 @@ var Page = function PageClosure() {
         idFactory: this.idFactory,
         fontCache: this.fontCache,
         builtInCMapCache: this.builtInCMapCache,
-        options: this.evaluatorOptions
+        options: this.evaluatorOptions,
+        pdfFunctionFactory: this.pdfFunctionFactory
       });
       var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
-      var pageListPromise = dataPromises.then(function (_ref2) {
-        var _ref3 = _slicedToArray(_ref2, 1),
-            contentStream = _ref3[0];
+      var pageListPromise = dataPromises.then(function (_ref3) {
+        var _ref4 = _slicedToArray(_ref3, 1),
+            contentStream = _ref4[0];
 
         var opList = new _evaluator.OperatorList(intent, handler, _this2.pageIndex);
         handler.send('StartRenderPage', {
@@ -213,10 +224,10 @@ var Page = function PageClosure() {
         });
       });
       var annotationsPromise = this.pdfManager.ensure(this, 'annotations');
-      return Promise.all([pageListPromise, annotationsPromise]).then(function (_ref4) {
-        var _ref5 = _slicedToArray(_ref4, 2),
-            pageOpList = _ref5[0],
-            annotations = _ref5[1];
+      return Promise.all([pageListPromise, annotationsPromise]).then(function (_ref5) {
+        var _ref6 = _slicedToArray(_ref5, 2),
+            pageOpList = _ref6[0],
+            annotations = _ref6[1];
 
         if (annotations.length === 0) {
           pageOpList.flush(true);
@@ -241,21 +252,21 @@ var Page = function PageClosure() {
         });
       });
     },
-    extractTextContent: function extractTextContent(_ref6) {
+    extractTextContent: function extractTextContent(_ref7) {
       var _this3 = this;
 
-      var handler = _ref6.handler,
-          task = _ref6.task,
-          normalizeWhitespace = _ref6.normalizeWhitespace,
-          sink = _ref6.sink,
-          combineTextItems = _ref6.combineTextItems;
+      var handler = _ref7.handler,
+          task = _ref7.task,
+          normalizeWhitespace = _ref7.normalizeWhitespace,
+          sink = _ref7.sink,
+          combineTextItems = _ref7.combineTextItems;
 
       var contentStreamPromise = this.pdfManager.ensure(this, 'getContentStream');
       var resourcesPromise = this.loadResources(['ExtGState', 'XObject', 'Font']);
       var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
-      return dataPromises.then(function (_ref7) {
-        var _ref8 = _slicedToArray(_ref7, 1),
-            contentStream = _ref8[0];
+      return dataPromises.then(function (_ref8) {
+        var _ref9 = _slicedToArray(_ref8, 1),
+            contentStream = _ref9[0];
 
         var partialEvaluator = new _evaluator.PartialEvaluator({
           pdfManager: _this3.pdfManager,
@@ -265,7 +276,8 @@ var Page = function PageClosure() {
           idFactory: _this3.idFactory,
           fontCache: _this3.fontCache,
           builtInCMapCache: _this3.builtInCMapCache,
-          options: _this3.evaluatorOptions
+          options: _this3.evaluatorOptions,
+          pdfFunctionFactory: _this3.pdfFunctionFactory
         });
         return partialEvaluator.getTextContent({
           stream: contentStream,
@@ -321,6 +333,11 @@ var PDFDocument = function PDFDocumentClosure() {
     this.pdfManager = pdfManager;
     this.stream = stream;
     this.xref = new _obj.XRef(stream, pdfManager);
+    var evaluatorOptions = pdfManager.evaluatorOptions;
+    this.pdfFunctionFactory = new _function.PDFFunctionFactory({
+      xref: this.xref,
+      isEvalSupported: evaluatorOptions.isEvalSupported
+    });
   }
   function find(stream, needle, limit, backwards) {
     var pos = stream.pos;
@@ -472,12 +489,19 @@ var PDFDocument = function PDFDocumentClosure() {
       this.xref.parse(recoveryMode);
       var pageFactory = {
         createPage: function createPage(pageIndex, dict, ref, fontCache, builtInCMapCache) {
-          return new Page(_this4.pdfManager, _this4.xref, pageIndex, dict, ref, fontCache, builtInCMapCache);
+          return new Page({
+            pdfManager: _this4.pdfManager,
+            xref: _this4.xref,
+            pageIndex: pageIndex,
+            pageDict: dict,
+            ref: ref,
+            fontCache: fontCache,
+            builtInCMapCache: builtInCMapCache,
+            pdfFunctionFactory: _this4.pdfFunctionFactory
+          });
         }
       };
       this.catalog = new _obj.Catalog(this.pdfManager, this.xref, pageFactory);
-      var evaluatorOptions = this.pdfManager.evaluatorOptions;
-      _function.PDFFunction.setIsEvalSupported(evaluatorOptions.isEvalSupported);
     },
     get numPages() {
       var linearization = this.linearization;

+ 87 - 52
lib/core/evaluator.js

@@ -39,8 +39,6 @@ var _standard_fonts = require('./standard_fonts');
 
 var _pattern = require('./pattern');
 
-var _function = require('./function');
-
 var _parser = require('./parser');
 
 var _bidi = require('./bidi');
@@ -51,6 +49,8 @@ var _glyphlist = require('./glyphlist');
 
 var _metrics = require('./metrics');
 
+var _function = require('./function');
+
 var _murmurhash = require('./murmurhash3');
 
 var _image = require('./image');
@@ -64,20 +64,28 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
     ignoreErrors: false,
     isEvalSupported: true
   };
-  function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
+  function NativeImageDecoder(_ref) {
+    var xref = _ref.xref,
+        resources = _ref.resources,
+        handler = _ref.handler,
+        _ref$forceDataSchema = _ref.forceDataSchema,
+        forceDataSchema = _ref$forceDataSchema === undefined ? false : _ref$forceDataSchema,
+        pdfFunctionFactory = _ref.pdfFunctionFactory;
+
     this.xref = xref;
     this.resources = resources;
     this.handler = handler;
     this.forceDataSchema = forceDataSchema;
+    this.pdfFunctionFactory = pdfFunctionFactory;
   }
   NativeImageDecoder.prototype = {
     canDecode: function canDecode(image) {
-      return image instanceof _stream.JpegStream && NativeImageDecoder.isDecodable(image, this.xref, this.resources);
+      return image instanceof _stream.JpegStream && NativeImageDecoder.isDecodable(image, this.xref, this.resources, this.pdfFunctionFactory);
     },
     decode: function decode(image) {
       var dict = image.dict;
       var colorSpace = dict.get('ColorSpace', 'CS');
-      colorSpace = _colorspace.ColorSpace.parse(colorSpace, this.xref, this.resources);
+      colorSpace = _colorspace.ColorSpace.parse(colorSpace, this.xref, this.resources, this.pdfFunctionFactory);
       var numComps = colorSpace.numComps;
       var decodePromise = this.handler.sendWithPromise('JpegDecode', [image.getIR(this.forceDataSchema), numComps]);
       return decodePromise.then(function (message) {
@@ -86,34 +94,35 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
       });
     }
   };
-  NativeImageDecoder.isSupported = function NativeImageDecoder_isSupported(image, xref, res) {
+  NativeImageDecoder.isSupported = function (image, xref, res, pdfFunctionFactory) {
     var dict = image.dict;
     if (dict.has('DecodeParms') || dict.has('DP')) {
       return false;
     }
-    var cs = _colorspace.ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
+    var cs = _colorspace.ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res, pdfFunctionFactory);
     return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
   };
-  NativeImageDecoder.isDecodable = function NativeImageDecoder_isDecodable(image, xref, res) {
+  NativeImageDecoder.isDecodable = function (image, xref, res, pdfFunctionFactory) {
     var dict = image.dict;
     if (dict.has('DecodeParms') || dict.has('DP')) {
       return false;
     }
-    var cs = _colorspace.ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
+    var cs = _colorspace.ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res, pdfFunctionFactory);
     return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
   };
-  function PartialEvaluator(_ref) {
+  function PartialEvaluator(_ref2) {
     var _this = this;
 
-    var pdfManager = _ref.pdfManager,
-        xref = _ref.xref,
-        handler = _ref.handler,
-        pageIndex = _ref.pageIndex,
-        idFactory = _ref.idFactory,
-        fontCache = _ref.fontCache,
-        builtInCMapCache = _ref.builtInCMapCache,
-        _ref$options = _ref.options,
-        options = _ref$options === undefined ? null : _ref$options;
+    var pdfManager = _ref2.pdfManager,
+        xref = _ref2.xref,
+        handler = _ref2.handler,
+        pageIndex = _ref2.pageIndex,
+        idFactory = _ref2.idFactory,
+        fontCache = _ref2.fontCache,
+        builtInCMapCache = _ref2.builtInCMapCache,
+        _ref2$options = _ref2.options,
+        options = _ref2$options === undefined ? null : _ref2$options,
+        pdfFunctionFactory = _ref2.pdfFunctionFactory;
 
     this.pdfManager = pdfManager;
     this.xref = xref;
@@ -123,6 +132,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
     this.fontCache = fontCache;
     this.builtInCMapCache = builtInCMapCache;
     this.options = options || DefaultPartialEvaluatorOptions;
+    this.pdfFunctionFactory = pdfFunctionFactory;
     this.fetchBuiltInCMap = function (name) {
       var cachedCMap = _this.builtInCMapCache[name];
       if (cachedCMap) {
@@ -281,11 +291,13 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
           knockout: false
         };
         var groupSubtype = group.get('S');
-        var colorSpace;
+        var colorSpace = null;
         if ((0, _primitives.isName)(groupSubtype, 'Transparency')) {
           groupOptions.isolated = group.get('I') || false;
           groupOptions.knockout = group.get('K') || false;
-          colorSpace = group.has('CS') ? _colorspace.ColorSpace.parse(group.get('CS'), this.xref, resources) : null;
+          if (group.has('CS')) {
+            colorSpace = _colorspace.ColorSpace.parse(group.get('CS'), this.xref, resources, this.pdfFunctionFactory);
+          }
         }
         if (smask && smask.backdrop) {
           colorSpace = colorSpace || _colorspace.ColorSpace.singletons.rgb;
@@ -330,8 +342,13 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
         var bitStrideLength = width + 7 >> 3;
         var imgArray = image.getBytes(bitStrideLength * height);
         var decode = dict.getArray('Decode', 'D');
-        var inverseDecode = !!decode && decode[0] > 0;
-        imgData = _image.PDFImage.createMask(imgArray, width, height, image instanceof _stream.DecodeStream, inverseDecode);
+        imgData = _image.PDFImage.createMask({
+          imgArray: imgArray,
+          width: width,
+          height: height,
+          imageIsFromDecodeStream: image instanceof _stream.DecodeStream,
+          inverseDecode: !!decode && decode[0] > 0
+        });
         imgData.cached = true;
         args = [imgData];
         operatorList.addOp(_util.OPS.paintImageMaskXObject, args);
@@ -347,7 +364,12 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
       var mask = dict.get('Mask') || false;
       var SMALL_IMAGE_DIMENSIONS = 200;
       if (inline && !softMask && !mask && !(image instanceof _stream.JpegStream) && w + h < SMALL_IMAGE_DIMENSIONS) {
-        var imageObj = new _image.PDFImage(this.xref, resources, image, inline, null, null);
+        var imageObj = new _image.PDFImage({
+          xref: this.xref,
+          res: resources,
+          image: image,
+          pdfFunctionFactory: this.pdfFunctionFactory
+        });
         imgData = imageObj.createImageData(true);
         operatorList.addOp(_util.OPS.paintInlineImageXObject, [imgData]);
         return;
@@ -356,7 +378,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
       var objId = 'img_' + this.idFactory.createObjId();
       operatorList.addDependency(objId);
       args = [objId, w, h];
-      if (nativeImageDecoderSupport !== _util.NativeImageDecoding.NONE && !softMask && !mask && image instanceof _stream.JpegStream && NativeImageDecoder.isSupported(image, this.xref, resources)) {
+      if (nativeImageDecoderSupport !== _util.NativeImageDecoding.NONE && !softMask && !mask && image instanceof _stream.JpegStream && NativeImageDecoder.isSupported(image, this.xref, resources, this.pdfFunctionFactory)) {
         operatorList.addOp(_util.OPS.paintJpegXObject, args);
         this.handler.send('obj', [objId, this.pageIndex, 'JpegStream', image.getIR(this.options.forceDataSchema)]);
         if (cacheKey) {
@@ -369,9 +391,22 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
       }
       var nativeImageDecoder = null;
       if (nativeImageDecoderSupport === _util.NativeImageDecoding.DECODE && (image instanceof _stream.JpegStream || mask instanceof _stream.JpegStream || softMask instanceof _stream.JpegStream)) {
-        nativeImageDecoder = new NativeImageDecoder(this.xref, resources, this.handler, this.options.forceDataSchema);
+        nativeImageDecoder = new NativeImageDecoder({
+          xref: this.xref,
+          resources: resources,
+          handler: this.handler,
+          forceDataSchema: this.options.forceDataSchema,
+          pdfFunctionFactory: this.pdfFunctionFactory
+        });
       }
-      _image.PDFImage.buildImage(this.handler, this.xref, resources, image, inline, nativeImageDecoder).then(function (imageObj) {
+      _image.PDFImage.buildImage({
+        handler: this.handler,
+        xref: this.xref,
+        res: resources,
+        image: image,
+        nativeDecoder: nativeImageDecoder,
+        pdfFunctionFactory: this.pdfFunctionFactory
+      }).then(function (imageObj) {
         var imgData = imageObj.createImageData(false);
         _this2.handler.send('obj', [objId, _this2.pageIndex, 'Image', imgData], [imgData.data.buffer]);
       }).catch(function (reason) {
@@ -394,7 +429,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
       };
       var transferObj = smask.get('TR');
       if ((0, _function.isPDFFunction)(transferObj)) {
-        var transferFn = _function.PDFFunction.parse(this.xref, transferObj);
+        var transferFn = this.pdfFunctionFactory.create(transferObj);
         var transferMap = new Uint8Array(256);
         var tmp = new Float32Array(1);
         for (var i = 0; i < 256; i++) {
@@ -689,7 +724,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
         } else if (typeNum === SHADING_PATTERN) {
           var shading = dict.get('Shading');
           var matrix = dict.getArray('Matrix');
-          pattern = _pattern.Pattern.parseShading(shading, matrix, this.xref, resources, this.handler);
+          pattern = _pattern.Pattern.parseShading(shading, matrix, this.xref, resources, this.handler, this.pdfFunctionFactory);
           operatorList.addOp(fn, pattern.getIR());
           return Promise.resolve();
         }
@@ -698,15 +733,15 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
       operatorList.addOp(fn, args);
       return Promise.resolve();
     },
-    getOperatorList: function getOperatorList(_ref2) {
+    getOperatorList: function getOperatorList(_ref3) {
       var _this8 = this;
 
-      var stream = _ref2.stream,
-          task = _ref2.task,
-          resources = _ref2.resources,
-          operatorList = _ref2.operatorList,
-          _ref2$initialState = _ref2.initialState,
-          initialState = _ref2$initialState === undefined ? null : _ref2$initialState;
+      var stream = _ref3.stream,
+          task = _ref3.task,
+          resources = _ref3.resources,
+          operatorList = _ref3.operatorList,
+          _ref3$initialState = _ref3.initialState,
+          initialState = _ref3$initialState === undefined ? null : _ref3$initialState;
 
       resources = resources || _primitives.Dict.empty;
       initialState = initialState || new EvalState();
@@ -844,10 +879,10 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
               stateManager.state.textRenderingMode = args[0];
               break;
             case _util.OPS.setFillColorSpace:
-              stateManager.state.fillColorSpace = _colorspace.ColorSpace.parse(args[0], xref, resources);
+              stateManager.state.fillColorSpace = _colorspace.ColorSpace.parse(args[0], xref, resources, self.pdfFunctionFactory);
               continue;
             case _util.OPS.setStrokeColorSpace:
-              stateManager.state.strokeColorSpace = _colorspace.ColorSpace.parse(args[0], xref, resources);
+              stateManager.state.strokeColorSpace = _colorspace.ColorSpace.parse(args[0], xref, resources, self.pdfFunctionFactory);
               continue;
             case _util.OPS.setFillColor:
               cs = stateManager.state.fillColorSpace;
@@ -914,7 +949,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
               if (!shading) {
                 throw new _util.FormatError('No shading object found');
               }
-              var shadingFill = _pattern.Pattern.parseShading(shading, null, xref, resources, self.handler);
+              var shadingFill = _pattern.Pattern.parseShading(shading, null, xref, resources, self.handler, self.pdfFunctionFactory);
               var patternIR = shadingFill.getIR();
               args = [patternIR];
               fn = _util.OPS.shadingFill;
@@ -978,21 +1013,21 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
         throw reason;
       });
     },
-    getTextContent: function getTextContent(_ref3) {
+    getTextContent: function getTextContent(_ref4) {
       var _this9 = this;
 
-      var stream = _ref3.stream,
-          task = _ref3.task,
-          resources = _ref3.resources,
-          _ref3$stateManager = _ref3.stateManager,
-          stateManager = _ref3$stateManager === undefined ? null : _ref3$stateManager,
-          _ref3$normalizeWhites = _ref3.normalizeWhitespace,
-          normalizeWhitespace = _ref3$normalizeWhites === undefined ? false : _ref3$normalizeWhites,
-          _ref3$combineTextItem = _ref3.combineTextItems,
-          combineTextItems = _ref3$combineTextItem === undefined ? false : _ref3$combineTextItem,
-          sink = _ref3.sink,
-          _ref3$seenStyles = _ref3.seenStyles,
-          seenStyles = _ref3$seenStyles === undefined ? Object.create(null) : _ref3$seenStyles;
+      var stream = _ref4.stream,
+          task = _ref4.task,
+          resources = _ref4.resources,
+          _ref4$stateManager = _ref4.stateManager,
+          stateManager = _ref4$stateManager === undefined ? null : _ref4$stateManager,
+          _ref4$normalizeWhites = _ref4.normalizeWhitespace,
+          normalizeWhitespace = _ref4$normalizeWhites === undefined ? false : _ref4$normalizeWhites,
+          _ref4$combineTextItem = _ref4.combineTextItems,
+          combineTextItems = _ref4$combineTextItem === undefined ? false : _ref4$combineTextItem,
+          sink = _ref4.sink,
+          _ref4$seenStyles = _ref4.seenStyles,
+          seenStyles = _ref4$seenStyles === undefined ? Object.create(null) : _ref4$seenStyles;
 
       resources = resources || _primitives.Dict.empty;
       stateManager = stateManager || new StateManager(new TextState());

+ 183 - 36
lib/core/function.js

@@ -17,35 +17,86 @@
 Object.defineProperty(exports, "__esModule", {
   value: true
 });
-exports.PostScriptCompiler = exports.PostScriptEvaluator = exports.PDFFunction = exports.isPDFFunction = undefined;
+exports.PostScriptCompiler = exports.PostScriptEvaluator = exports.PDFFunctionFactory = exports.isPDFFunction = undefined;
 
 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
 
+var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
+
 var _util = require('../shared/util');
 
 var _primitives = require('./primitives');
 
 var _ps_parser = require('./ps_parser');
 
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+
 var IsEvalSupportedCached = {
   get value() {
     return (0, _util.shadow)(this, 'value', (0, _util.isEvalSupported)());
   }
 };
+
+var PDFFunctionFactory = function () {
+  function PDFFunctionFactory(_ref) {
+    var xref = _ref.xref,
+        _ref$isEvalSupported = _ref.isEvalSupported,
+        isEvalSupported = _ref$isEvalSupported === undefined ? true : _ref$isEvalSupported;
+
+    _classCallCheck(this, PDFFunctionFactory);
+
+    this.xref = xref;
+    this.isEvalSupported = isEvalSupported !== false;
+  }
+
+  _createClass(PDFFunctionFactory, [{
+    key: 'create',
+    value: function create(fn) {
+      return PDFFunction.parse({
+        xref: this.xref,
+        isEvalSupported: this.isEvalSupported,
+        fn: fn
+      });
+    }
+  }, {
+    key: 'createFromArray',
+    value: function createFromArray(fnObj) {
+      return PDFFunction.parseArray({
+        xref: this.xref,
+        isEvalSupported: this.isEvalSupported,
+        fnObj: fnObj
+      });
+    }
+  }, {
+    key: 'createFromIR',
+    value: function createFromIR(IR) {
+      return PDFFunction.fromIR({
+        xref: this.xref,
+        isEvalSupported: this.isEvalSupported,
+        IR: IR
+      });
+    }
+  }, {
+    key: 'createIR',
+    value: function createIR(fn) {
+      return PDFFunction.getIR({
+        xref: this.xref,
+        isEvalSupported: this.isEvalSupported,
+        fn: fn
+      });
+    }
+  }]);
+
+  return PDFFunctionFactory;
+}();
+
 var PDFFunction = function PDFFunctionClosure() {
   var CONSTRUCT_SAMPLED = 0;
   var CONSTRUCT_INTERPOLATED = 2;
   var CONSTRUCT_STICHED = 3;
   var CONSTRUCT_POSTSCRIPT = 4;
-  var isEvalSupported = true;
   return {
-    setIsEvalSupported: function setIsEvalSupported() {
-      var support = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
-
-      isEvalSupported = support !== false;
-    },
-
-    getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps, str) {
+    getSampleArray: function getSampleArray(size, outputSize, bps, stream) {
       var i, ii;
       var length = 1;
       for (i = 0, ii = size.length; i < ii; i++) {
@@ -56,7 +107,7 @@ var PDFFunction = function PDFFunctionClosure() {
       var codeSize = 0;
       var codeBuf = 0;
       var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
-      var strBytes = str.getBytes((length * bps + 7) / 8);
+      var strBytes = stream.getBytes((length * bps + 7) / 8);
       var strIdx = 0;
       for (i = 0; i < length; i++) {
         while (codeSize < bps) {
@@ -70,7 +121,11 @@ var PDFFunction = function PDFFunctionClosure() {
       }
       return array;
     },
-    getIR: function PDFFunction_getIR(xref, fn) {
+    getIR: function getIR(_ref2) {
+      var xref = _ref2.xref,
+          isEvalSupported = _ref2.isEvalSupported,
+          fn = _ref2.fn;
+
       var dict = fn.dict;
       if (!dict) {
         dict = fn;
@@ -81,33 +136,81 @@ var PDFFunction = function PDFFunctionClosure() {
       if (!typeFn) {
         throw new _util.FormatError('Unknown type of function');
       }
-      return typeFn.call(this, fn, dict, xref);
+      return typeFn.call(this, {
+        xref: xref,
+        isEvalSupported: isEvalSupported,
+        fn: fn,
+        dict: dict
+      });
     },
-    fromIR: function PDFFunction_fromIR(IR) {
+    fromIR: function fromIR(_ref3) {
+      var xref = _ref3.xref,
+          isEvalSupported = _ref3.isEvalSupported,
+          IR = _ref3.IR;
+
       var type = IR[0];
       switch (type) {
         case CONSTRUCT_SAMPLED:
-          return this.constructSampledFromIR(IR);
+          return this.constructSampledFromIR({
+            xref: xref,
+            isEvalSupported: isEvalSupported,
+            IR: IR
+          });
         case CONSTRUCT_INTERPOLATED:
-          return this.constructInterpolatedFromIR(IR);
+          return this.constructInterpolatedFromIR({
+            xref: xref,
+            isEvalSupported: isEvalSupported,
+            IR: IR
+          });
         case CONSTRUCT_STICHED:
-          return this.constructStichedFromIR(IR);
+          return this.constructStichedFromIR({
+            xref: xref,
+            isEvalSupported: isEvalSupported,
+            IR: IR
+          });
         default:
-          return this.constructPostScriptFromIR(IR);
+          return this.constructPostScriptFromIR({
+            xref: xref,
+            isEvalSupported: isEvalSupported,
+            IR: IR
+          });
       }
     },
-    parse: function PDFFunction_parse(xref, fn) {
-      var IR = this.getIR(xref, fn);
-      return this.fromIR(IR);
+    parse: function parse(_ref4) {
+      var xref = _ref4.xref,
+          isEvalSupported = _ref4.isEvalSupported,
+          fn = _ref4.fn;
+
+      var IR = this.getIR({
+        xref: xref,
+        isEvalSupported: isEvalSupported,
+        fn: fn
+      });
+      return this.fromIR({
+        xref: xref,
+        isEvalSupported: isEvalSupported,
+        IR: IR
+      });
     },
-    parseArray: function PDFFunction_parseArray(xref, fnObj) {
+    parseArray: function parseArray(_ref5) {
+      var xref = _ref5.xref,
+          isEvalSupported = _ref5.isEvalSupported,
+          fnObj = _ref5.fnObj;
+
       if (!Array.isArray(fnObj)) {
-        return this.parse(xref, fnObj);
+        return this.parse({
+          xref: xref,
+          isEvalSupported: isEvalSupported,
+          fn: fnObj
+        });
       }
       var fnArray = [];
       for (var j = 0, jj = fnObj.length; j < jj; j++) {
-        var obj = xref.fetchIfRef(fnObj[j]);
-        fnArray.push(PDFFunction.parse(xref, obj));
+        fnArray.push(this.parse({
+          xref: xref,
+          isEvalSupported: isEvalSupported,
+          fn: xref.fetchIfRef(fnObj[j])
+        }));
       }
       return function (src, srcOffset, dest, destOffset) {
         for (var i = 0, ii = fnArray.length; i < ii; i++) {
@@ -115,7 +218,12 @@ var PDFFunction = function PDFFunctionClosure() {
         }
       };
     },
-    constructSampled: function PDFFunction_constructSampled(str, dict) {
+    constructSampled: function constructSampled(_ref6) {
+      var xref = _ref6.xref,
+          isEvalSupported = _ref6.isEvalSupported,
+          fn = _ref6.fn,
+          dict = _ref6.dict;
+
       function toMultiArray(arr) {
         var inputLength = arr.length;
         var out = [];
@@ -156,10 +264,14 @@ var PDFFunction = function PDFFunctionClosure() {
       } else {
         decode = toMultiArray(decode);
       }
-      var samples = this.getSampleArray(size, outputSize, bps, str);
+      var samples = this.getSampleArray(size, outputSize, bps, fn);
       return [CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size, outputSize, Math.pow(2, bps) - 1, range];
     },
-    constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
+    constructSampledFromIR: function constructSampledFromIR(_ref7) {
+      var xref = _ref7.xref,
+          isEvalSupported = _ref7.isEvalSupported,
+          IR = _ref7.IR;
+
       function interpolate(x, xmin, xmax, ymin, ymax) {
         return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin));
       }
@@ -215,7 +327,12 @@ var PDFFunction = function PDFFunctionClosure() {
         }
       };
     },
-    constructInterpolated: function PDFFunction_constructInterpolated(str, dict) {
+    constructInterpolated: function constructInterpolated(_ref8) {
+      var xref = _ref8.xref,
+          isEvalSupported = _ref8.isEvalSupported,
+          fn = _ref8.fn,
+          dict = _ref8.dict;
+
       var c0 = dict.getArray('C0') || [0];
       var c1 = dict.getArray('C1') || [1];
       var n = dict.get('N');
@@ -229,7 +346,11 @@ var PDFFunction = function PDFFunctionClosure() {
       }
       return [CONSTRUCT_INTERPOLATED, c0, diff, n];
     },
-    constructInterpolatedFromIR: function PDFFunction_constructInterpolatedFromIR(IR) {
+    constructInterpolatedFromIR: function constructInterpolatedFromIR(_ref9) {
+      var xref = _ref9.xref,
+          isEvalSupported = _ref9.isEvalSupported,
+          IR = _ref9.IR;
+
       var c0 = IR[1];
       var diff = IR[2];
       var n = IR[3];
@@ -241,7 +362,12 @@ var PDFFunction = function PDFFunctionClosure() {
         }
       };
     },
-    constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
+    constructStiched: function constructStiched(_ref10) {
+      var xref = _ref10.xref,
+          isEvalSupported = _ref10.isEvalSupported,
+          fn = _ref10.fn,
+          dict = _ref10.dict;
+
       var domain = dict.getArray('Domain');
       if (!domain) {
         throw new _util.FormatError('No domain');
@@ -253,13 +379,21 @@ var PDFFunction = function PDFFunctionClosure() {
       var fnRefs = dict.get('Functions');
       var fns = [];
       for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
-        fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
+        fns.push(this.getIR({
+          xref: xref,
+          isEvalSupported: isEvalSupported,
+          fn: xref.fetchIfRef(fnRefs[i])
+        }));
       }
       var bounds = dict.getArray('Bounds');
       var encode = dict.getArray('Encode');
       return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
     },
-    constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
+    constructStichedFromIR: function constructStichedFromIR(_ref11) {
+      var xref = _ref11.xref,
+          isEvalSupported = _ref11.isEvalSupported,
+          IR = _ref11.IR;
+
       var domain = IR[1];
       var bounds = IR[2];
       var encode = IR[3];
@@ -267,7 +401,11 @@ var PDFFunction = function PDFFunctionClosure() {
       var fns = [];
       var tmpBuf = new Float32Array(1);
       for (var i = 0, ii = fnsIR.length; i < ii; i++) {
-        fns.push(PDFFunction.fromIR(fnsIR[i]));
+        fns.push(this.fromIR({
+          xref: xref,
+          isEvalSupported: isEvalSupported,
+          IR: fnsIR[i]
+        }));
       }
       return function constructStichedFromIRResult(src, srcOffset, dest, destOffset) {
         var clip = function constructStichedFromIRClip(v, min, max) {
@@ -298,7 +436,12 @@ var PDFFunction = function PDFFunctionClosure() {
         fns[i](tmpBuf, 0, dest, destOffset);
       };
     },
-    constructPostScript: function PDFFunction_constructPostScript(fn, dict, xref) {
+    constructPostScript: function constructPostScript(_ref12) {
+      var xref = _ref12.xref,
+          isEvalSupported = _ref12.isEvalSupported,
+          fn = _ref12.fn,
+          dict = _ref12.dict;
+
       var domain = dict.getArray('Domain');
       var range = dict.getArray('Range');
       if (!domain) {
@@ -312,7 +455,11 @@ var PDFFunction = function PDFFunctionClosure() {
       var code = parser.parse();
       return [CONSTRUCT_POSTSCRIPT, domain, range, code];
     },
-    constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(IR) {
+    constructPostScriptFromIR: function constructPostScriptFromIR(_ref13) {
+      var xref = _ref13.xref,
+          isEvalSupported = _ref13.isEvalSupported,
+          IR = _ref13.IR;
+
       var domain = IR[1];
       var range = IR[2];
       var code = IR[3];
@@ -990,6 +1137,6 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
   return PostScriptCompiler;
 }();
 exports.isPDFFunction = isPDFFunction;
-exports.PDFFunction = PDFFunction;
+exports.PDFFunctionFactory = PDFFunctionFactory;
 exports.PostScriptEvaluator = PostScriptEvaluator;
 exports.PostScriptCompiler = PostScriptCompiler;

+ 69 - 18
lib/core/image.js

@@ -19,6 +19,8 @@ Object.defineProperty(exports, "__esModule", {
 });
 exports.PDFImage = undefined;
 
+var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
+
 var _util = require('../shared/util');
 
 var _stream = require('./stream');
@@ -64,7 +66,18 @@ var PDFImage = function PDFImageClosure() {
     }
     return dest;
   }
-  function PDFImage(xref, res, image, inline, smask, mask, isMask) {
+  function PDFImage(_ref) {
+    var xref = _ref.xref,
+        res = _ref.res,
+        image = _ref.image,
+        _ref$smask = _ref.smask,
+        smask = _ref$smask === undefined ? null : _ref$smask,
+        _ref$mask = _ref.mask,
+        mask = _ref$mask === undefined ? null : _ref$mask,
+        _ref$isMask = _ref.isMask,
+        isMask = _ref$isMask === undefined ? false : _ref$isMask,
+        pdfFunctionFactory = _ref.pdfFunctionFactory;
+
     this.image = image;
     var dict = image.dict;
     if (dict.has('Filter')) {
@@ -118,7 +131,7 @@ var PDFImage = function PDFImageClosure() {
             throw new Error('JPX images with ' + this.numComps + ' ' + 'color components not supported.');
         }
       }
-      this.colorSpace = _colorspace.ColorSpace.parse(colorSpace, xref, res);
+      this.colorSpace = _colorspace.ColorSpace.parse(colorSpace, xref, res, pdfFunctionFactory);
       this.numComps = this.colorSpace.numComps;
     }
     this.decode = dict.getArray('Decode', 'D');
@@ -136,7 +149,12 @@ var PDFImage = function PDFImageClosure() {
       }
     }
     if (smask) {
-      this.smask = new PDFImage(xref, res, smask, false);
+      this.smask = new PDFImage({
+        xref: xref,
+        res: res,
+        image: smask,
+        pdfFunctionFactory: pdfFunctionFactory
+      });
     } else if (mask) {
       if ((0, _primitives.isStream)(mask)) {
         var maskDict = mask.dict,
@@ -144,14 +162,28 @@ var PDFImage = function PDFImageClosure() {
         if (!imageMask) {
           (0, _util.warn)('Ignoring /Mask in image without /ImageMask.');
         } else {
-          this.mask = new PDFImage(xref, res, mask, false, null, null, true);
+          this.mask = new PDFImage({
+            xref: xref,
+            res: res,
+            image: mask,
+            isMask: true,
+            pdfFunctionFactory: pdfFunctionFactory
+          });
         }
       } else {
         this.mask = mask;
       }
     }
   }
-  PDFImage.buildImage = function PDFImage_buildImage(handler, xref, res, image, inline, nativeDecoder) {
+  PDFImage.buildImage = function (_ref2) {
+    var handler = _ref2.handler,
+        xref = _ref2.xref,
+        res = _ref2.res,
+        image = _ref2.image,
+        _ref2$nativeDecoder = _ref2.nativeDecoder,
+        nativeDecoder = _ref2$nativeDecoder === undefined ? null : _ref2$nativeDecoder,
+        pdfFunctionFactory = _ref2.pdfFunctionFactory;
+
     var imagePromise = handleImageData(image, nativeDecoder);
     var smaskPromise;
     var maskPromise;
@@ -175,14 +207,29 @@ var PDFImage = function PDFImageClosure() {
         maskPromise = Promise.resolve(null);
       }
     }
-    return Promise.all([imagePromise, smaskPromise, maskPromise]).then(function (results) {
-      var imageData = results[0];
-      var smaskData = results[1];
-      var maskData = results[2];
-      return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
+    return Promise.all([imagePromise, smaskPromise, maskPromise]).then(function (_ref3) {
+      var _ref4 = _slicedToArray(_ref3, 3),
+          imageData = _ref4[0],
+          smaskData = _ref4[1],
+          maskData = _ref4[2];
+
+      return new PDFImage({
+        xref: xref,
+        res: res,
+        image: imageData,
+        smask: smaskData,
+        mask: maskData,
+        pdfFunctionFactory: pdfFunctionFactory
+      });
     });
   };
-  PDFImage.createMask = function PDFImage_createMask(imgArray, width, height, imageIsFromDecodeStream, inverseDecode) {
+  PDFImage.createMask = function (_ref5) {
+    var imgArray = _ref5.imgArray,
+        width = _ref5.width,
+        height = _ref5.height,
+        imageIsFromDecodeStream = _ref5.imageIsFromDecodeStream,
+        inverseDecode = _ref5.inverseDecode;
+
     var computedLength = (width + 7 >> 3) * height;
     var actualLength = imgArray.byteLength;
     var haveFullData = computedLength === actualLength;
@@ -217,7 +264,7 @@ var PDFImage = function PDFImageClosure() {
     get drawHeight() {
       return Math.max(this.height, this.smask && this.smask.height || 0, this.mask && this.mask.height || 0);
     },
-    decodeBuffer: function PDFImage_decodeBuffer(buffer) {
+    decodeBuffer: function decodeBuffer(buffer) {
       var bpc = this.bpc;
       var numComps = this.numComps;
       var decodeAddends = this.decodeAddends;
@@ -238,7 +285,7 @@ var PDFImage = function PDFImageClosure() {
         }
       }
     },
-    getComponents: function PDFImage_getComponents(buffer) {
+    getComponents: function getComponents(buffer) {
       var bpc = this.bpc;
       if (bpc === 8) {
         return buffer;
@@ -301,7 +348,7 @@ var PDFImage = function PDFImageClosure() {
       }
       return output;
     },
-    fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height, actualHeight, image) {
+    fillOpacity: function fillOpacity(rgbaBuf, width, height, actualHeight, image) {
       var smask = this.smask;
       var mask = this.mask;
       var alphaBuf, sw, sh, i, ii, j;
@@ -356,7 +403,7 @@ var PDFImage = function PDFImageClosure() {
         }
       }
     },
-    undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
+    undoPreblend: function undoPreblend(buffer, width, height) {
       var matte = this.smask && this.smask.matte;
       if (!matte) {
         return;
@@ -384,7 +431,9 @@ var PDFImage = function PDFImageClosure() {
         buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
       }
     },
-    createImageData: function PDFImage_createImageData(forceRGBA) {
+    createImageData: function createImageData() {
+      var forceRGBA = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
+
       var drawWidth = this.drawWidth;
       var drawHeight = this.drawHeight;
       var imgData = {
@@ -454,7 +503,7 @@ var PDFImage = function PDFImageClosure() {
       }
       return imgData;
     },
-    fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
+    fillGrayBuffer: function fillGrayBuffer(buffer) {
       var numComps = this.numComps;
       if (numComps !== 1) {
         throw new _util.FormatError('Reading gray scale from a color image: ' + numComps);
@@ -488,7 +537,9 @@ var PDFImage = function PDFImageClosure() {
         buffer[i] = scale * comps[i] | 0;
       }
     },
-    getImageBytes: function PDFImage_getImageBytes(length, drawWidth, drawHeight, forceRGB) {
+    getImageBytes: function getImageBytes(length, drawWidth, drawHeight) {
+      var forceRGB = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
+
       this.image.reset();
       this.image.drawWidth = drawWidth || this.width;
       this.image.drawHeight = drawHeight || this.height;

+ 9 - 11
lib/core/pattern.js

@@ -25,8 +25,6 @@ var _colorspace = require('./colorspace');
 
 var _primitives = require('./primitives');
 
-var _function = require('./function');
-
 var ShadingType = {
   FUNCTION_BASED: 1,
   AXIAL: 2,
@@ -45,19 +43,19 @@ var Pattern = function PatternClosure() {
       throw new Error('Should not call Pattern.getStyle: ' + ctx);
     }
   };
-  Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref, res, handler) {
+  Pattern.parseShading = function (shading, matrix, xref, res, handler, pdfFunctionFactory) {
     var dict = (0, _primitives.isStream)(shading) ? shading.dict : shading;
     var type = dict.get('ShadingType');
     try {
       switch (type) {
         case ShadingType.AXIAL:
         case ShadingType.RADIAL:
-          return new Shadings.RadialAxial(dict, matrix, xref, res);
+          return new Shadings.RadialAxial(dict, matrix, xref, res, pdfFunctionFactory);
         case ShadingType.FREE_FORM_MESH:
         case ShadingType.LATTICE_FORM_MESH:
         case ShadingType.COONS_PATCH_MESH:
         case ShadingType.TENSOR_PATCH_MESH:
-          return new Shadings.Mesh(shading, matrix, xref, res);
+          return new Shadings.Mesh(shading, matrix, xref, res, pdfFunctionFactory);
         default:
           throw new _util.FormatError('Unsupported ShadingType: ' + type);
       }
@@ -75,13 +73,13 @@ var Pattern = function PatternClosure() {
 var Shadings = {};
 Shadings.SMALL_NUMBER = 1e-6;
 Shadings.RadialAxial = function RadialAxialClosure() {
-  function RadialAxial(dict, matrix, xref, res) {
+  function RadialAxial(dict, matrix, xref, res, pdfFunctionFactory) {
     this.matrix = matrix;
     this.coordsArr = dict.getArray('Coords');
     this.shadingType = dict.get('ShadingType');
     this.type = 'Pattern';
     var cs = dict.get('ColorSpace', 'CS');
-    cs = _colorspace.ColorSpace.parse(cs, xref, res);
+    cs = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
     this.cs = cs;
     var t0 = 0.0,
         t1 = 1.0;
@@ -112,7 +110,7 @@ Shadings.RadialAxial = function RadialAxialClosure() {
     this.extendStart = extendStart;
     this.extendEnd = extendEnd;
     var fnObj = dict.get('Function');
-    var fn = _function.PDFFunction.parseArray(xref, fnObj);
+    var fn = pdfFunctionFactory.createFromArray(fnObj);
     var diff = t1 - t0;
     var step = diff / 10;
     var colorStops = this.colorStops = [];
@@ -705,7 +703,7 @@ Shadings.Mesh = function MeshClosure() {
       }
     }
   }
-  function Mesh(stream, matrix, xref, res) {
+  function Mesh(stream, matrix, xref, res, pdfFunctionFactory) {
     if (!(0, _primitives.isStream)(stream)) {
       throw new _util.FormatError('Mesh data is not a stream');
     }
@@ -715,11 +713,11 @@ Shadings.Mesh = function MeshClosure() {
     this.type = 'Pattern';
     this.bbox = dict.getArray('BBox');
     var cs = dict.get('ColorSpace', 'CS');
-    cs = _colorspace.ColorSpace.parse(cs, xref, res);
+    cs = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
     this.cs = cs;
     this.background = dict.has('Background') ? cs.getRgb(dict.get('Background'), 0) : null;
     var fnObj = dict.get('Function');
-    var fn = fnObj ? _function.PDFFunction.parseArray(xref, fnObj) : null;
+    var fn = fnObj ? pdfFunctionFactory.createFromArray(fnObj) : null;
     this.coords = [];
     this.colors = [];
     this.figures = [];

+ 1 - 1
lib/core/worker.js

@@ -208,7 +208,7 @@ var WorkerMessageHandler = {
     var cancelXHRs = null;
     var WorkerTasks = [];
     var apiVersion = docParams.apiVersion;
-    var workerVersion = '1.9.604';
+    var workerVersion = '1.9.607';
     if (apiVersion !== null && apiVersion !== workerVersion) {
       throw new Error('The API version "' + apiVersion + '" does not match ' + ('the Worker version "' + workerVersion + '".'));
     }

+ 3 - 3
lib/display/api.js

@@ -193,7 +193,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
   if (worker.destroyed) {
     return Promise.reject(new Error('Worker was destroyed'));
   }
-  var apiVersion = '1.9.604';
+  var apiVersion = '1.9.607';
   source.disableAutoFetch = (0, _dom_utils.getDefaultSetting)('disableAutoFetch');
   source.disableStream = (0, _dom_utils.getDefaultSetting)('disableStream');
   source.chunkedViewerLoading = !!pdfDataRangeTransport;
@@ -1584,8 +1584,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() {
 }();
 var version, build;
 {
-  exports.version = version = '1.9.604';
-  exports.build = build = 'f206ee56';
+  exports.version = version = '1.9.607';
+  exports.build = build = 'b3f84112';
 }
 exports.getDocument = getDocument;
 exports.LoopbackPort = LoopbackPort;

+ 2 - 2
lib/display/global.js

@@ -45,8 +45,8 @@ if (!_global_scope2.default.PDFJS) {
 }
 var PDFJS = _global_scope2.default.PDFJS;
 {
-  PDFJS.version = '1.9.604';
-  PDFJS.build = 'f206ee56';
+  PDFJS.version = '1.9.607';
+  PDFJS.build = 'b3f84112';
 }
 PDFJS.pdfBug = false;
 if (PDFJS.verbosity !== undefined) {

+ 2 - 2
lib/pdf.js

@@ -14,8 +14,8 @@
  */
 'use strict';
 
-var pdfjsVersion = '1.9.604';
-var pdfjsBuild = 'f206ee56';
+var pdfjsVersion = '1.9.607';
+var pdfjsBuild = 'b3f84112';
 var pdfjsSharedUtil = require('./shared/util.js');
 var pdfjsDisplayGlobal = require('./display/global.js');
 var pdfjsDisplayAPI = require('./display/api.js');

+ 2 - 2
lib/pdf.worker.js

@@ -14,7 +14,7 @@
  */
 'use strict';
 
-var pdfjsVersion = '1.9.604';
-var pdfjsBuild = 'f206ee56';
+var pdfjsVersion = '1.9.607';
+var pdfjsBuild = 'b3f84112';
 var pdfjsCoreWorker = require('./core/worker.js');
 exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler;

+ 24 - 11
lib/test/unit/colorspace_spec.js

@@ -20,6 +20,8 @@ var _stream = require('../../core/stream');
 
 var _colorspace = require('../../core/colorspace');
 
+var _function = require('../../core/function');
+
 var _test_utils = require('./test_utils');
 
 describe('colorspace', function () {
@@ -49,7 +51,8 @@ describe('colorspace', function () {
         data: new _primitives.Dict()
       }]);
       var res = new _primitives.Dict();
-      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res);
+      var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
+      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
       var testSrc = new Uint8Array([27, 125, 250, 131]);
       var testDest = new Uint8Array(4 * 4 * 3);
       var expectedDest = new Uint8Array([27, 27, 27, 27, 27, 27, 125, 125, 125, 125, 125, 125, 27, 27, 27, 27, 27, 27, 125, 125, 125, 125, 125, 125, 250, 250, 250, 250, 250, 250, 131, 131, 131, 131, 131, 131, 250, 250, 250, 250, 250, 250, 131, 131, 131, 131, 131, 131]);
@@ -66,7 +69,8 @@ describe('colorspace', function () {
         data: _primitives.Name.get('DeviceGray')
       }]);
       var res = new _primitives.Dict();
-      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res);
+      var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
+      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
       var testSrc = new Uint8Array([27, 125, 250, 131]);
       var testDest = new Uint8Array(3 * 3 * 3);
       var expectedDest = new Uint8Array([27, 27, 27, 27, 27, 27, 125, 125, 125, 27, 27, 27, 27, 27, 27, 125, 125, 125, 250, 250, 250, 250, 250, 250, 131, 131, 131]);
@@ -85,7 +89,8 @@ describe('colorspace', function () {
         data: new _primitives.Dict()
       }]);
       var res = new _primitives.Dict();
-      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res);
+      var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
+      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
       var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
       var testDest = new Uint8Array(4 * 4 * 3);
       var expectedDest = new Uint8Array([27, 125, 250, 27, 125, 250, 131, 139, 140, 131, 139, 140, 27, 125, 250, 27, 125, 250, 131, 139, 140, 131, 139, 140, 111, 25, 198, 111, 25, 198, 21, 147, 255, 21, 147, 255, 111, 25, 198, 111, 25, 198, 21, 147, 255, 21, 147, 255]);
@@ -102,7 +107,8 @@ describe('colorspace', function () {
         data: _primitives.Name.get('DeviceRGB')
       }]);
       var res = new _primitives.Dict();
-      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res);
+      var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
+      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
       var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
       var testDest = new Uint8Array(3 * 3 * 3);
       var expectedDest = new Uint8Array([27, 125, 250, 27, 125, 250, 131, 139, 140, 27, 125, 250, 27, 125, 250, 131, 139, 140, 111, 25, 198, 111, 25, 198, 21, 147, 255]);
@@ -121,7 +127,8 @@ describe('colorspace', function () {
         data: new _primitives.Dict()
       }]);
       var res = new _primitives.Dict();
-      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res);
+      var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
+      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
       var testSrc = new Uint8Array([27, 125, 250, 128, 131, 139, 140, 45, 111, 25, 198, 78, 21, 147, 255, 69]);
       var testDest = new Uint8Array(4 * 4 * 3);
       var expectedDest = new Uint8Array([135, 80, 18, 135, 80, 18, 113, 102, 97, 113, 102, 97, 135, 80, 18, 135, 80, 18, 113, 102, 97, 113, 102, 97, 112, 143, 75, 112, 143, 75, 188, 98, 27, 188, 98, 27, 112, 143, 75, 112, 143, 75, 188, 98, 27, 188, 98, 27]);
@@ -138,7 +145,8 @@ describe('colorspace', function () {
         data: _primitives.Name.get('DeviceCMYK')
       }]);
       var res = new _primitives.Dict();
-      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res);
+      var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
+      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
       var testSrc = new Uint8Array([27, 125, 250, 128, 131, 139, 140, 45, 111, 25, 198, 78, 21, 147, 255, 69]);
       var testDest = new Uint8Array(3 * 3 * 3);
       var expectedDest = new Uint8Array([135, 80, 18, 135, 80, 18, 113, 102, 97, 135, 80, 18, 135, 80, 18, 113, 102, 97, 112, 143, 75, 112, 143, 75, 188, 98, 27]);
@@ -161,7 +169,8 @@ describe('colorspace', function () {
         data: new _primitives.Dict()
       }]);
       var res = new _primitives.Dict();
-      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res);
+      var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
+      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
       var testSrc = new Uint8Array([27, 125, 250, 131]);
       var testDest = new Uint8Array(4 * 4 * 3);
       var expectedDest = new Uint8Array([25, 25, 25, 25, 25, 25, 143, 143, 143, 143, 143, 143, 25, 25, 25, 25, 25, 25, 143, 143, 143, 143, 143, 143, 251, 251, 251, 251, 251, 251, 148, 148, 148, 148, 148, 148, 251, 251, 251, 251, 251, 251, 148, 148, 148, 148, 148, 148]);
@@ -185,7 +194,8 @@ describe('colorspace', function () {
         data: new _primitives.Dict()
       }]);
       var res = new _primitives.Dict();
-      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res);
+      var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
+      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
       var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
       var testDest = new Uint8Array(3 * 3 * 3);
       var expectedDest = new Uint8Array([0, 238, 255, 0, 238, 255, 185, 196, 195, 0, 238, 255, 0, 238, 255, 185, 196, 195, 235, 0, 243, 235, 0, 243, 0, 255, 255]);
@@ -208,7 +218,8 @@ describe('colorspace', function () {
         data: new _primitives.Dict()
       }]);
       var res = new _primitives.Dict();
-      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res);
+      var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
+      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
       var testSrc = new Uint8Array([27, 25, 50, 31, 19, 40, 11, 25, 98, 21, 47, 55]);
       var testDest = new Uint8Array(3 * 3 * 3);
       var expectedDest = new Uint8Array([0, 49, 101, 0, 49, 101, 0, 53, 116, 0, 49, 101, 0, 49, 101, 0, 53, 116, 0, 40, 39, 0, 40, 39, 0, 43, 90]);
@@ -229,7 +240,8 @@ describe('colorspace', function () {
         data: new _primitives.Dict()
       }]);
       var res = new _primitives.Dict();
-      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res);
+      var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
+      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
       var testSrc = new Uint8Array([2, 2, 0, 1]);
       var testDest = new Uint8Array(3 * 3 * 3);
       var expectedDest = new Uint8Array([255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 23, 155, 35, 23, 155, 35, 147, 69, 93]);
@@ -256,7 +268,8 @@ describe('colorspace', function () {
         data: fn
       }]);
       var res = new _primitives.Dict();
-      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res);
+      var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
+      var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
       var testSrc = new Uint8Array([27, 25, 50, 31]);
       var testDest = new Uint8Array(3 * 3 * 3);
       var expectedDest = new Uint8Array([227, 243, 242, 227, 243, 242, 228, 243, 242, 227, 243, 242, 227, 243, 242, 228, 243, 242, 203, 233, 229, 203, 233, 229, 222, 241, 239]);

+ 8 - 2
lib/test/unit/document_spec.js

@@ -19,8 +19,14 @@ var _document = require('../../core/document');
 describe('document', function () {
   describe('Page', function () {
     it('should create correct objId using the idFactory', function () {
-      var page1 = new _document.Page({}, null, 0, null, null, null, null);
-      var page2 = new _document.Page({}, null, 1, null, null, null, null);
+      var page1 = new _document.Page({
+        pdfManager: {},
+        pageIndex: 0
+      });
+      var page2 = new _document.Page({
+        pdfManager: {},
+        pageIndex: 1
+      });
       var idFactory1 = page1.idFactory,
           idFactory2 = page2.idFactory;
       expect(idFactory1.createObjId()).toEqual('p0_1');

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "pdfjs-dist",
-  "version": "1.9.604",
+  "version": "1.9.607",
   "main": "build/pdf.js",
   "description": "Generic build of Mozilla's PDF.js library.",
   "keywords": [

Some files were not shown because too many files changed in this diff