From c7195a44505443407a22273ff069d704763ec227 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Wed, 31 Aug 2011 14:41:21 +0200 Subject: [PATCH 1/3] Chromium throw an error on calling defineProperty on a getter only --- pdf.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pdf.js b/pdf.js index 46f946c40..1a586e48a 100644 --- a/pdf.js +++ b/pdf.js @@ -55,11 +55,17 @@ function backtrace() { } function shadow(obj, prop, value) { - Object.defineProperty(obj, prop, { value: value, - enumerable: true, - configurable: true, - writable: false }); - return value; + try { + Object.defineProperty(obj, prop, { value: value, + enumerable: true, + configurable: true, + writable: false }); + } catch(e) { + obj.__defineGetter__(prop, function() { + return value; + }); + } + return value; } function bytesToString(bytes) { @@ -4275,6 +4281,10 @@ var PartialEvaluator = (function() { case 'Type1': baseEncoding = Encodings.StandardEncoding.slice(); break; + case 'Type3': + // There is no baseEncoding for a Type3 font, the 'Encoding' + // entry is required and should provide a complete encoding + break; default: warn('Unknown type of font: ' + fontType); break; @@ -4298,6 +4308,10 @@ var PartialEvaluator = (function() { glyphsMap[glyph] = encodingMap[i] = GlyphsUnicode[glyph] || i; } + + if (fontType == 'Type3') + log(glyphsMap); + if (fontType == 'TrueType' && fontDict.has('ToUnicode') && differences) { var cmapObj = xref.fetchIfRef(fontDict.get('ToUnicode')); if (IsName(cmapObj)) { From 59c4ba0fb9943377d28b9e21d0851ce96221cfb1 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Wed, 31 Aug 2011 23:26:34 +0200 Subject: [PATCH 2/3] Fix for issue #418 --- fonts.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/fonts.js b/fonts.js index 02aa52601..adf0a48e3 100755 --- a/fonts.js +++ b/fonts.js @@ -2208,21 +2208,28 @@ var Type2CFF = (function() { var charstrings = []; var differences = properties.differences; - var index = 0; + var index = 0, code = 0; var kCmapGlyphOffset = 0xE000; for (var i = 1; i < charsets.length; i++) { var glyph = charsets[i]; - for (var j = index; j < differences.length; j++) { - if (differences[j]) { - index = j; - break; + if (differences.length) { + for (var j = index; j < differences.length; j++) { + if (differences[j]) { + index = j; + break; + } } + + code = differences.indexOf(glyph); + if (code == -1) + code = properties.glyphs[glyph] || index; + } else { + code = GlyphsUnicode[glyph] || index; + index = code; } - var code = differences.indexOf(glyph); - if (code == -1) - code = properties.glyphs[glyph] || index; - + if (!code) + continue; var width = widths[code] || defaultWidth; properties.encoding[index] = index + kCmapGlyphOffset; charstrings.push({unicode: code + kCmapGlyphOffset, width: width, gid: i}); From 81e1485e1421ee014841e163367382d409f9cc56 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Thu, 1 Sep 2011 01:16:40 +0200 Subject: [PATCH 3/3] Address review comment for pull #419 --- fonts.js | 33 +++++++++++++++------------------ pdf.js | 8 -------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/fonts.js b/fonts.js index adf0a48e3..6488c073b 100755 --- a/fonts.js +++ b/fonts.js @@ -2207,32 +2207,29 @@ var Type2CFF = (function() { var nominalWidth = privDict['nominalWidthX']; var charstrings = []; - var differences = properties.differences; - var index = 0, code = 0; var kCmapGlyphOffset = 0xE000; + var differences = properties.differences; + var index = 0; for (var i = 1; i < charsets.length; i++) { + var code = -1; var glyph = charsets[i]; - if (differences.length) { - for (var j = index; j < differences.length; j++) { - if (differences[j]) { - index = j; - break; - } + for (var j = index; j < differences.length; j++) { + if (differences[j]) { + index = j; + code = differences.indexOf(glyph); + break; } - - code = differences.indexOf(glyph); - if (code == -1) - code = properties.glyphs[glyph] || index; - } else { - code = GlyphsUnicode[glyph] || index; - index = code; } - if (!code) - continue; + if (code == -1) + index = code = properties.glyphs[glyph] || index; + var width = widths[code] || defaultWidth; properties.encoding[index] = index + kCmapGlyphOffset; - charstrings.push({unicode: code + kCmapGlyphOffset, width: width, gid: i}); + charstrings.push({ + unicode: code + kCmapGlyphOffset, + width: width, gid: i + }); index++; } diff --git a/pdf.js b/pdf.js index 1a586e48a..df8871e7f 100644 --- a/pdf.js +++ b/pdf.js @@ -4281,10 +4281,6 @@ var PartialEvaluator = (function() { case 'Type1': baseEncoding = Encodings.StandardEncoding.slice(); break; - case 'Type3': - // There is no baseEncoding for a Type3 font, the 'Encoding' - // entry is required and should provide a complete encoding - break; default: warn('Unknown type of font: ' + fontType); break; @@ -4308,10 +4304,6 @@ var PartialEvaluator = (function() { glyphsMap[glyph] = encodingMap[i] = GlyphsUnicode[glyph] || i; } - - if (fontType == 'Type3') - log(glyphsMap); - if (fontType == 'TrueType' && fontDict.has('ToUnicode') && differences) { var cmapObj = xref.fetchIfRef(fontDict.get('ToUnicode')); if (IsName(cmapObj)) {