From 2c87a6467bc85a7ff82311c8627ba3fcb4e479cf Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Sat, 24 Nov 2012 15:13:13 -0600 Subject: [PATCH] Fixes function array support for radial/axial pattern --- src/pattern.js | 28 +++++++++++++++++++++++----- test/pdfs/issue2006.pdf.link | 1 + test/test_manifest.json | 8 ++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 test/pdfs/issue2006.pdf.link diff --git a/src/pattern.js b/src/pattern.js index e366c0942..8095d0acb 100644 --- a/src/pattern.js +++ b/src/pattern.js @@ -115,11 +115,29 @@ Shadings.RadialAxial = (function RadialAxialClosure() { this.extendEnd = extendEnd; var fnObj = dict.get('Function'); - if (isArray(fnObj)) - error('No support for array of functions'); - if (!isPDFFunction(fnObj)) - error('Invalid function'); - var fn = PDFFunction.parse(xref, fnObj); + var fn; + if (isArray(fnObj)) { + var fnArray = []; + for (var j = 0, jj = fnObj.length; j < jj; j++) { + var obj = xref.fetchIfRef(fnObj[j]); + if (!isPDFFunction(obj)) { + error('Invalid function'); + } + fnArray.push(PDFFunction.parse(xref, obj)); + } + fn = function radialAxialColorFunction(arg) { + var out = []; + for (var i = 0, ii = fnArray.length; i < ii; i++) { + out.push(fnArray[i](arg)[0]); + } + return out; + }; + } else { + if (!isPDFFunction(fnObj)) { + error('Invalid function'); + } + fn = PDFFunction.parse(xref, fnObj); + } // 10 samples seems good enough for now, but probably won't work // if there are sharp color changes. Ideally, we would implement diff --git a/test/pdfs/issue2006.pdf.link b/test/pdfs/issue2006.pdf.link new file mode 100644 index 000000000..ca0827725 --- /dev/null +++ b/test/pdfs/issue2006.pdf.link @@ -0,0 +1 @@ +http://pages.sencha.com/rs/sencha/images/Sencha-WP-Dev-Mgrs-Guide-to-HTML5.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index a174d2c80..52866e325 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -713,6 +713,14 @@ "link": true, "type": "eq" }, + { "id": "issue2006", + "file": "pdfs/issue2006.pdf", + "md5": "71ec73831ece9b508ad20efa6ff28642", + "rounds": 1, + "pageLimit": 1, + "link": true, + "type": "eq" + }, { "id": "issue1729", "file": "pdfs/issue1729.pdf", "md5": "29b0eddc3e1dcb23a44384037032d470",