From 309342748015b483a91a26a00221453ce2e13fed Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Fri, 10 Aug 2012 21:31:33 -0500 Subject: [PATCH 1/2] Marks xref entries with offset 0 as free --- src/obj.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/obj.js b/src/obj.js index c01ffab58..d04234f07 100644 --- a/src/obj.js +++ b/src/obj.js @@ -624,7 +624,7 @@ var XRef = (function XRefClosure() { var e = this.entries[i]; if (e === null) return null; - return e.free ? null : e; // returns null is the entry is free + return e.free || !e.offset ? null : e; // returns null if entry is free }, fetchIfRef: function XRef_fetchIfRef(obj) { if (!isRef(obj)) From b4d75ca83b1a5b74986021a21be4efc89e074f4d Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Sat, 11 Aug 2012 11:57:42 -0500 Subject: [PATCH 2/2] Adds callothersubr support --- src/fonts.js | 49 +++++++++++++++++++++++++++---------- test/pdfs/issue845.pdf.link | 1 + test/test_manifest.json | 7 ++++++ 3 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 test/pdfs/issue845.pdf.link diff --git a/src/fonts.js b/src/fonts.js index b16c2621a..ae6d330b5 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -3293,6 +3293,14 @@ var Font = (function FontClosure() { return Font; })(); +var CallothersubrCmd = (function CallothersubrCmdClosure() { + function CallothersubrCmd(index) { + this.index = index; + } + + return CallothersubrCmd; +})(); + /* * Type1Parser encapsulate the needed code for parsing a Type1 font * program. Some of its logic depends on the Type2 charstrings @@ -3498,6 +3506,10 @@ var Type1Parser = function type1Parser() { i++; continue; } + + assert(argc == 0, 'callothersubr with arguments is not supported'); + charstring.push(new CallothersubrCmd(index)); + continue; } else if (escape == 17 || escape == 33) { // pop or setcurrentpoint commands can be ignored // since we are not doing callothersubr @@ -4017,14 +4029,14 @@ Type1Font.prototype = { }, getType2Charstrings: function Type1Font_getType2Charstrings( - type1Charstrings) { + type1Subrs) { var type2Charstrings = []; - var count = type1Charstrings.length; - for (var i = 0; i < count; i++) { - var charstring = type1Charstrings[i].charstring; - type2Charstrings.push(this.flattenCharstring(charstring.slice(), - this.commandsMap)); - } + var count = type1Subrs.length; + var type1Charstrings = []; + for (var i = 0; i < count; i++) + type1Charstrings.push(type1Subrs[i].charstring.slice()); + for (var i = 0; i < count; i++) + type2Charstrings.push(this.flattenCharstring(type1Charstrings, i)); return type2Charstrings; }, @@ -4044,11 +4056,7 @@ Type1Font.prototype = { type2Subrs.push([0x0B]); for (var i = 0; i < count; i++) { - var subr = type1Subrs[i]; - if (!subr) - subr = [0x0B]; - - type2Subrs.push(this.flattenCharstring(subr, this.commandsMap)); + type2Subrs.push(this.flattenCharstring(type1Subrs, i)); } return type2Subrs; @@ -4080,7 +4088,11 @@ Type1Font.prototype = { 'hvcurveto': 31 }, - flattenCharstring: function Type1Font_flattenCharstring(charstring, map) { + flattenCharstring: function Type1Font_flattenCharstring(charstrings, index) { + var charstring = charstrings[index]; + if (!charstring) + return [0x0B]; + var map = this.commandsMap; // charstring changes size - can't cache .length in loop for (var i = 0; i < charstring.length; i++) { var command = charstring[i]; @@ -4092,6 +4104,17 @@ Type1Font.prototype = { charstring.splice(i++, 1, cmd[0], cmd[1]); else charstring[i] = cmd; + } else if (command instanceof CallothersubrCmd) { + var otherSubrCharstring = charstrings[command.index]; + if (otherSubrCharstring) { + var lastCommand = otherSubrCharstring.indexOf('return'); + if (lastCommand >= 0) + otherSubrCharstring = otherSubrCharstring.slice(0, lastCommand); + charstring.splice.apply(charstring, + [i, 1].concat(otherSubrCharstring)); + } else + charstring.splice(i, 1); // ignoring empty subr call + i--; } else { // Type1 charstring use a division for number above 32000 if (command > 32000) { diff --git a/test/pdfs/issue845.pdf.link b/test/pdfs/issue845.pdf.link new file mode 100644 index 000000000..b315abebb --- /dev/null +++ b/test/pdfs/issue845.pdf.link @@ -0,0 +1 @@ +http://www.mediafire.com/?k8t1he9aa1pt840 diff --git a/test/test_manifest.json b/test/test_manifest.json index 166b4fdc7..d894a97a1 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -619,6 +619,13 @@ "link": true, "type": "eq" }, + { "id": "issue845", + "file": "pdfs/issue845.pdf", + "md5": "89ddf9e63cac4fa2dedcfe32a62e5407", + "rounds": 1, + "link": true, + "type": "eq" + }, { "id": "issue818", "file": "pdfs/issue818.pdf", "md5": "dd2f8a5bd65164ad74da2b45a6ca90cc",