From ff17a5db5aad39cdfde6b53e2a8267c5b0daf0fc Mon Sep 17 00:00:00 2001 From: Saebekassebil Date: Thu, 7 Jul 2011 01:02:42 +0200 Subject: [PATCH 1/4] Updated Dict object. Perf. Improv. --- pdf.js | 63 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/pdf.js b/pdf.js index 2151c0497..7dbc187fc 100644 --- a/pdf.js +++ b/pdf.js @@ -1917,32 +1917,37 @@ var Cmd = (function() { var Dict = (function() { function constructor() { - this.map = Object.create(null); + this.map = {}; } constructor.prototype = { - get: function(key) { - if (key in this.map) - return this.map[key]; - return null; - }, - get2: function(key1, key2) { - return this.get(key1) || this.get(key2); + get: function(key1, key2, key3) { + var value; + if (typeof (value = this.map[key1]) != 'undefined' || key1 in map || typeof key2 == 'undefined') { + return value; + } + if (typeof (value = this.map[key2]) != 'undefined' || key2 in map || typeof key3 == 'undefined') { + return value; + } + + return this.map[key3] || null; }, - get3: function(key1, key2, key3) { - return this.get(key1) || this.get(key2) || this.get(key3); + + set: function(key, value) { + this.map[key] = value; }, + has: function(key) { return key in this.map; }, - set: function(key, value) { - this.map[key] = value; - }, - forEach: function(aCallback) { - for (var key in this.map) - aCallback(key, this.map[key]); + + forEach: function(callback) { + for (var key in this.map) { + callback.call(null, key, this.map[key]); + } } }; + return constructor; })(); @@ -2459,8 +2464,8 @@ var Parser = (function() { return stream; }, filter: function(stream, dict, length) { - var filter = dict.get2('Filter', 'F'); - var params = dict.get2('DecodeParms', 'DP'); + var filter = dict.get('Filter', 'F'); + var params = dict.get('DecodeParms', 'DP'); if (IsName(filter)) return this.makeFilter(stream, filter.name, length, params); if (IsArray(filter)) { @@ -3472,7 +3477,7 @@ var CanvasGraphics = (function() { assertWellFormed(IsName(fontName), 'invalid font name'); fontName = fontName.name.replace('+', '_'); - var fontFile = descriptor.get3('FontFile', 'FontFile2', 'FontFile3'); + var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3'); if (!fontFile) error('FontFile not found for font: ' + fontName); fontFile = xref.fetchIfRef(fontFile); @@ -4204,7 +4209,7 @@ var CanvasGraphics = (function() { if (background) TODO('handle background colors'); - var cs = shading.get2('ColorSpace', 'CS'); + var cs = shading.get('ColorSpace', 'CS'); cs = ColorSpace.parse(cs, this.xref, this.res); var types = [null, @@ -4368,8 +4373,8 @@ var CanvasGraphics = (function() { var ctx = this.ctx; var dict = image.dict; - var w = dict.get2('Width', 'W'); - var h = dict.get2('Height', 'H'); + var w = dict.get('Width', 'W'); + var h = dict.get('Height', 'H'); // scale the image to the unit square ctx.scale(1 / w, -1 / h); @@ -4786,18 +4791,18 @@ var PDFImage = (function() { // TODO cache rendered images? var dict = image.dict; - this.width = dict.get2('Width', 'W'); - this.height = dict.get2('Height', 'H'); + this.width = dict.get('Width', 'W'); + this.height = dict.get('Height', 'H'); if (this.width < 1 || this.height < 1) error('Invalid image width or height'); - this.interpolate = dict.get2('Interpolate', 'I') || false; - this.imageMask = dict.get2('ImageMask', 'IM') || false; + this.interpolate = dict.get('Interpolate', 'I') || false; + this.imageMask = dict.get('ImageMask', 'IM') || false; var bitsPerComponent = image.bitsPerComponent; if (!bitsPerComponent) { - bitsPerComponent = dict.get2('BitsPerComponent', 'BPC'); + bitsPerComponent = dict.get('BitsPerComponent', 'BPC'); if (!bitsPerComponent) { if (this.imageMask) bitsPerComponent = 1; @@ -4807,11 +4812,11 @@ var PDFImage = (function() { } this.bpc = bitsPerComponent; - var colorSpace = dict.get2('ColorSpace', 'CS'); + var colorSpace = dict.get('ColorSpace', 'CS'); this.colorSpace = ColorSpace.parse(colorSpace, xref, res); this.numComps = this.colorSpace.numComps; - this.decode = dict.get2('Decode', 'D'); + this.decode = dict.get('Decode', 'D'); var mask = xref.fetchIfRef(image.dict.get('Mask')); var smask = xref.fetchIfRef(image.dict.get('SMask')); From 056a729115c2c2299fafc6d1c31efe135a9c78e4 Mon Sep 17 00:00:00 2001 From: Saebekassebil Date: Thu, 7 Jul 2011 16:06:45 +0200 Subject: [PATCH 2/4] Use .call instead of .apply. minor. --- pdf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdf.js b/pdf.js index 7dbc187fc..73fdeee2a 100644 --- a/pdf.js +++ b/pdf.js @@ -4989,7 +4989,7 @@ var PDFFunction = (function() { if (!typeFn) error('Unknown type of function'); - typeFn.apply(this, [fn, dict]); + typeFn.call(this, fn, dict); }; constructor.prototype = { From 42cdf6bf028afba0b7babded7c9855f6b6d150de Mon Sep 17 00:00:00 2001 From: Saebekassebil Date: Thu, 7 Jul 2011 16:51:44 +0200 Subject: [PATCH 3/4] Fixing typo in Dict --- pdf.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pdf.js b/pdf.js index 73fdeee2a..72557ccd9 100644 --- a/pdf.js +++ b/pdf.js @@ -1923,10 +1923,10 @@ var Dict = (function() { constructor.prototype = { get: function(key1, key2, key3) { var value; - if (typeof (value = this.map[key1]) != 'undefined' || key1 in map || typeof key2 == 'undefined') { + if (typeof (value = this.map[key1]) != 'undefined' || key1 in this.map || typeof key2 == 'undefined') { return value; } - if (typeof (value = this.map[key2]) != 'undefined' || key2 in map || typeof key3 == 'undefined') { + if (typeof (value = this.map[key2]) != 'undefined' || key2 in this.map || typeof key3 == 'undefined') { return value; } From dc9316db2daa67e951a1055d2e0237b78798e4e6 Mon Sep 17 00:00:00 2001 From: Saebekassebil Date: Thu, 7 Jul 2011 17:03:24 +0200 Subject: [PATCH 4/4] Better debug at glyphs --- fonts.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fonts.js b/fonts.js index d85d40b2f..25fef9ac6 100755 --- a/fonts.js +++ b/fonts.js @@ -2,7 +2,7 @@ /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ 'use strict'; - +var missingGlyphs = []; var isWorker = (typeof window == 'undefined'); /** @@ -1661,9 +1661,11 @@ CFF.prototype = { for (var i = 0; i < glyphs.length; i++) { var glyph = glyphs[i]; var unicode = GlyphsUnicode[glyph.glyph]; + if (!unicode) { if (glyph.glyph != '.notdef') { - warn(glyph + + missingGlyphs.push(glyph.glyph); + warn(glyph.glyph + ' does not have an entry in the glyphs unicode dictionary'); } } else {