From 1444a7e7947424b29df689599505b33f2b0e9382 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sun, 9 Oct 2011 09:13:10 -0500 Subject: [PATCH 01/43] Making Type 2 font sanitazable (#631) --- fonts.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fonts.js b/fonts.js index 2ab3a90b7..45fe9c974 100644 --- a/fonts.js +++ b/fonts.js @@ -2271,7 +2271,7 @@ CFF.prototype = { 'return': 11, 'sub': [12, 11], 'div': [12, 12], - 'pop': [1, 12, 18], + 'pop': [139, 12, 18], 'drop' : [12, 18], 'endchar': 14, 'rmoveto': 21, @@ -2287,9 +2287,11 @@ CFF.prototype = { var cmd = map[command]; assert(cmd, 'Unknow command: ' + command); - if (isArray(cmd)) + if (isArray(cmd)) { charstring.splice(i++, 1, cmd[0], cmd[1]); - else + if (cmd.length > 2) + charstring.splice(++i, 0, cmd[2]); + } else if (cmd !== null) charstring[i] = cmd; } else { // Type1 charstring use a division for number above 32000 From 8241733a20e95815504ca995f6932778d7338f76 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sun, 9 Oct 2011 22:40:49 -0500 Subject: [PATCH 02/43] Getting addition encoding information for cmap from the CFF data (#641) --- fonts.js | 95 +++++++++++++++++++++++++++++++++++++------------------- pdf.js | 8 +++++ 2 files changed, 71 insertions(+), 32 deletions(-) diff --git a/fonts.js b/fonts.js index 2ab3a90b7..4f0d55d74 100644 --- a/fonts.js +++ b/fonts.js @@ -2488,7 +2488,7 @@ var Type2CFF = (function type2CFF() { var charStrings = this.parseIndex(topDict.CharStrings); var charset = this.parseCharsets(topDict.charset, charStrings.length, strings); - var hasSupplement = this.parseEncoding(topDict.Encoding, properties, + var encoding = this.parseEncoding(topDict.Encoding, properties, strings, charset); // The font sanitizer does not support CFF encoding with a @@ -2496,8 +2496,8 @@ var Type2CFF = (function type2CFF() { // between gid to glyph, let's overwrite what is declared in // the top dictionary to let the sanitizer think the font use // StandardEncoding, that's a lie but that's ok. - if (hasSupplement) - bytes[topDict.Encoding] = 0; + if (encoding.hasSupplement) + bytes[topDict.Encoding] &= 0x7F; // The CFF specification state that the 'dotsection' command // (12, 0) is deprecated and treated as a no-op, but all Type2 @@ -2528,7 +2528,7 @@ var Type2CFF = (function type2CFF() { // charstrings contains info about glyphs (one element per glyph // containing mappings for {unicode, width}) - var charstrings = this.getCharStrings(charset, charStrings, + var charstrings = this.getCharStrings(charset, encoding.encoding, privateDict, this.properties); // create the mapping between charstring and glyph id @@ -2545,49 +2545,82 @@ var Type2CFF = (function type2CFF() { return data; }, - getCharStrings: function cff_charstrings(charsets, charStrings, + getCharStrings: function cff_charstrings(charsets, encoding, privateDict, properties) { var defaultWidth = privateDict['defaultWidthX']; var charstrings = []; var differences = properties.differences; - var index = properties.firstChar || 0; for (var i = 1; i < charsets.length; i++) { - var code = -1; + var inDifferences; var glyph = charsets[i]; + var code; for (var j = 0; j < differences.length; j++) { if (differences[j] == glyph) { - index = j; - code = differences.indexOf(glyph); + code = j; + inDifferences = true; break; } } + if (!inDifferences) { + var code = properties.firstChar + i; + for (var s in encoding) { + if (encoding[s] == i) { + code = s | 0; + break; + } + } + } - var mapping = - properties.glyphs[glyph] || properties.glyphs[index] || {}; - if (code == -1) - index = code = mapping.unicode || index; + if (properties.encoding[code] && + properties.encoding[code].inDifferences) + continue; - if (code <= 0x1f || (code >= 127 && code <= 255)) - code += kCmapGlyphOffset; + var mapping = properties.glyphs[code] || properties.glyphs[glyph] || {}; + var unicode = mapping.unicode || code; - var width = mapping.width; - properties.glyphs[glyph] = properties.encoding[index] = { - unicode: code, - width: isNum(width) ? width : defaultWidth + if (unicode <= 0x1f || (unicode >= 127 && unicode <= 255)) + unicode += kCmapGlyphOffset; + + var width = isNum(mapping.width) ? mapping.width : defaultWidth; + properties.encoding[code] = { + unicode: unicode, + width: width, + inDifferences: inDifferences }; charstrings.push({ - unicode: code, + unicode: unicode, width: width, gid: i }); - index++; } // sort the array by the unicode value charstrings.sort(function type2CFFGetCharStringsSort(a, b) { return a.unicode - b.unicode; }); + + // remove duplicates -- they might appear during selection: + // properties.glyphs[code] || properties.glyphs[glyph] + // TODO make more deterministic + var nextUnusedUnicode = kCmapGlyphOffset + 0x0020; + var lastUnicode = charstrings[0].unicode, wasModified = false; + for (var i = 1; i < charstrings.length; ++i) { + if (lastUnicode != charstrings[i].unicode) { + lastUnicode = charstrings[i].unicode; + continue; + } + // duplicate found -- changing the unicode for previous one + charstrings[i - 1].unicode = nextUnusedUnicode++; + wasModified = true; + } + if (!wasModified) + return charstrings; + + // sort the array by the unicode value (again) + charstrings.sort(function type2CFFGetCharStringsSort(a, b) { + return a.unicode - b.unicode; + }); return charstrings; }, @@ -2595,6 +2628,10 @@ var Type2CFF = (function type2CFF() { charset) { var encoding = {}; var bytes = this.bytes; + var result = { + encoding: encoding, + hasSupplement: false + }; function readSupplement() { var supplementsCount = bytes[pos++]; @@ -2621,11 +2658,6 @@ var Type2CFF = (function type2CFF() { var glyphsCount = bytes[pos++]; for (var i = 1; i <= glyphsCount; i++) encoding[bytes[pos++]] = i; - - if (format & 0x80) { - readSupplement(); - return true; - } break; case 1: @@ -2637,19 +2669,18 @@ var Type2CFF = (function type2CFF() { for (var j = start; j <= start + count; j++) encoding[j] = gid++; } - - if (format & 0x80) { - readSupplement(); - return true; - } break; default: error('Unknow encoding format: ' + format + ' in CFF'); break; } + if (format & 0x80) { + readSupplement(); + result.hasSupplement = true; + } } - return false; + return result; }, parseCharsets: function cff_parsecharsets(pos, length, strings) { diff --git a/pdf.js b/pdf.js index 847ed2ff4..82345b17b 100644 --- a/pdf.js +++ b/pdf.js @@ -3558,6 +3558,12 @@ var Page = (function pagePage() { var self = this; var stats = self.stats; stats.compile = stats.fonts = stats.render = 0; + if (!this.content) { + setTimeout(function norenderingSetTimeout() { + if (continuation) continuation(null); + }); + return; + } var gfx = new CanvasGraphics(canvasCtx); var fonts = []; @@ -4610,6 +4616,8 @@ var PartialEvaluator = (function partialEvaluator() { if (replaceGlyph || !glyphs[glyph]) glyphs[glyph] = map[i]; + if (replaceGlyph || !glyphs[index]) + glyphs[index] = map[i]; // If there is no file, the character mapping can't be modified // but this is unlikely that there is any standard encoding with From 030b498b6a9f5a0f8c9688c8a55dccb5ad34dbc5 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Mon, 10 Oct 2011 07:03:43 -0500 Subject: [PATCH 03/43] 1 instead of 0 --- fonts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fonts.js b/fonts.js index 45fe9c974..fa6da78e7 100644 --- a/fonts.js +++ b/fonts.js @@ -2271,7 +2271,7 @@ CFF.prototype = { 'return': 11, 'sub': [12, 11], 'div': [12, 12], - 'pop': [139, 12, 18], + 'pop': [140, 12, 18], 'drop' : [12, 18], 'endchar': 14, 'rmoveto': 21, From 2c09fed17ce039c15b093ff7b38b7f6189b879fa Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Mon, 10 Oct 2011 20:58:40 -0500 Subject: [PATCH 04/43] Implement type2 flex --- fonts.js | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/fonts.js b/fonts.js index fa6da78e7..20edc1529 100644 --- a/fonts.js +++ b/fonts.js @@ -1715,6 +1715,7 @@ var Type1Parser = function type1Parser() { var charstring = []; var lsb = 0; var width = 0; + var flexState = 0, flexPoints; var value = ''; var count = array.length; @@ -1748,8 +1749,9 @@ var Type1Parser = function type1Parser() { i++; continue; } - } else if (!kHintingEnabled && (value == 1 || value == 2)) { - charstring.push('drop', 'drop', 'drop', 'drop', 'drop', 'drop'); + } else if (escape == 17 || escape == 33) { + // pop or setcurrentpoint commands can be ignored + // since we are not doing callothersubr continue; } @@ -1775,6 +1777,31 @@ var Type1Parser = function type1Parser() { charstring.push(lsb, 'hmoveto'); continue; + } else if (value == 10) { // callsubr + if (charstring[charstring.length - 1] < 3) { // subr #0..2 + var subrNumber = charstring.pop(); + switch (subrNumber) { + case 1: + flexState = 1; // prepare for flex coordinates + flexPoints = 0; + break; + case 2: + flexState = 2; // flex in progress + flexPoints++; + break; + case 0: + // type2 flex command does not need final coords + charstring.push('exch', 'drop', 'exch', 'drop'); + charstring.push('flex'); + flexState = 0; + break; + } + continue; + } + } else if (value == 21 && flexState > 0) { + if (flexState > 1) + continue; // ignoring rmoveto + value = 5; // first segment replacing with rlineto } else if (!kHintingEnabled && (value == 1 || value == 3)) { charstring.push('drop', 'drop'); continue; @@ -2271,7 +2298,8 @@ CFF.prototype = { 'return': 11, 'sub': [12, 11], 'div': [12, 12], - 'pop': [140, 12, 18], + 'exch': [12, 28], + 'flex': [12, 35], 'drop' : [12, 18], 'endchar': 14, 'rmoveto': 21, @@ -2287,11 +2315,9 @@ CFF.prototype = { var cmd = map[command]; assert(cmd, 'Unknow command: ' + command); - if (isArray(cmd)) { + if (isArray(cmd)) charstring.splice(i++, 1, cmd[0], cmd[1]); - if (cmd.length > 2) - charstring.splice(++i, 0, cmd[2]); - } else if (cmd !== null) + else if (cmd !== null) charstring[i] = cmd; } else { // Type1 charstring use a division for number above 32000 From 25f6431607c1154936bd2ae3ca89ad965b1b4f46 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Mon, 10 Oct 2011 21:00:49 -0500 Subject: [PATCH 05/43] Cleaning up flex stuff --- fonts.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fonts.js b/fonts.js index 20edc1529..789261ee5 100644 --- a/fonts.js +++ b/fonts.js @@ -1715,7 +1715,7 @@ var Type1Parser = function type1Parser() { var charstring = []; var lsb = 0; var width = 0; - var flexState = 0, flexPoints; + var flexState = 0; var value = ''; var count = array.length; @@ -1783,11 +1783,9 @@ var Type1Parser = function type1Parser() { switch (subrNumber) { case 1: flexState = 1; // prepare for flex coordinates - flexPoints = 0; break; case 2: flexState = 2; // flex in progress - flexPoints++; break; case 0: // type2 flex command does not need final coords @@ -2317,7 +2315,7 @@ CFF.prototype = { if (isArray(cmd)) charstring.splice(i++, 1, cmd[0], cmd[1]); - else if (cmd !== null) + else charstring[i] = cmd; } else { // Type1 charstring use a division for number above 32000 From 04e467793b79f8403d499748dc33f1f9f58ee09f Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Mon, 10 Oct 2011 21:14:40 -0500 Subject: [PATCH 06/43] Fixing standard font name resolution (#649) --- fonts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fonts.js b/fonts.js index 2ab3a90b7..7aef5ec92 100644 --- a/fonts.js +++ b/fonts.js @@ -441,7 +441,7 @@ var Font = (function Font() { if (!file) { // The file data is not specified. Trying to fix the font name // to be used with the canvas.font. - var fontName = stdFontMap[name] || name.replace('_', '-'); + var fontName = stdFontMap[name.replace('-', '_')] || name.replace('_', '-'); this.bold = (fontName.search(/bold/gi) != -1); this.italic = (fontName.search(/oblique/gi) != -1) || (fontName.search(/italic/gi) != -1); From 1f532e6edbda223144e4f7558f352661f7c2c514 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Mon, 10 Oct 2011 22:40:43 -0500 Subject: [PATCH 07/43] Long line fix --- fonts.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fonts.js b/fonts.js index 7aef5ec92..1c0039264 100644 --- a/fonts.js +++ b/fonts.js @@ -441,7 +441,8 @@ var Font = (function Font() { if (!file) { // The file data is not specified. Trying to fix the font name // to be used with the canvas.font. - var fontName = stdFontMap[name.replace('-', '_')] || name.replace('_', '-'); + var fontName = stdFontMap[name.replace('-', '_')] || + name.replace('_', '-'); this.bold = (fontName.search(/bold/gi) != -1); this.italic = (fontName.search(/oblique/gi) != -1) || (fontName.search(/italic/gi) != -1); From 66074c08ebbaac0cd06c16440118aa7675f4da89 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Tue, 11 Oct 2011 07:17:45 -0500 Subject: [PATCH 08/43] returning vstem3 and hstem3 --- fonts.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fonts.js b/fonts.js index 789261ee5..3abaaa533 100644 --- a/fonts.js +++ b/fonts.js @@ -1753,6 +1753,9 @@ var Type1Parser = function type1Parser() { // pop or setcurrentpoint commands can be ignored // since we are not doing callothersubr continue; + } else if (!kHintingEnabled && (escape == 1 || escape == 2)) { + charstring.push('drop', 'drop', 'drop', 'drop', 'drop', 'drop'); + continue; } command = charStringDictionary['12'][escape]; From 74d80401ccf448ed40bc31c886287aaab2fc55b4 Mon Sep 17 00:00:00 2001 From: Artur Adib Date: Tue, 11 Oct 2011 15:22:33 -0400 Subject: [PATCH 09/43] 'make web' now also bundles extension (xpi) --- Makefile | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index a9cd2793f..ebffb374c 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ BUILD_DIR := build DEFAULT_BROWSERS := resources/browser_manifests/browser_manifest.json DEFAULT_TESTS := test_manifest.json +EXTENSION_SRC := ./extensions/firefox +EXTENSION_NAME := pdf.js.xpi + # Let folks define custom rules for their clones. -include local.mk @@ -103,14 +106,17 @@ lint: # TODO: Use the Closure compiler to optimize the pdf.js files. # GH_PAGES = $(BUILD_DIR)/gh-pages -web: | compiler pages-repo \ +web: | extension compiler pages-repo \ $(addprefix $(GH_PAGES)/, $(PDF_JS_FILES)) \ $(addprefix $(GH_PAGES)/, $(wildcard web/*.*)) \ - $(addprefix $(GH_PAGES)/, $(wildcard web/images/*.*)) + $(addprefix $(GH_PAGES)/, $(wildcard web/images/*.*)) \ + $(addprefix $(GH_PAGES)/, $(wildcard $(EXTENSION_SRC)/*.xpi)) @cp $(GH_PAGES)/web/index.html.template $(GH_PAGES)/index.html; @cd $(GH_PAGES); git add -A; + @echo @echo "Website built in $(GH_PAGES)." + @echo "Don't forget to cd into $(GH_PAGES)/ and issue 'git commit' to push changes." # make pages-repo # @@ -126,6 +132,7 @@ pages-repo: | $(BUILD_DIR) fi; @mkdir -p $(GH_PAGES)/web; @mkdir -p $(GH_PAGES)/web/images; + @mkdir -p $(GH_PAGES)/$(EXTENSION_SRC); $(GH_PAGES)/%.js: %.js @cp $< $@ @@ -136,6 +143,9 @@ $(GH_PAGES)/web/%: web/% $(GH_PAGES)/web/images/%: web/images/% @cp $< $@ +$(GH_PAGES)/$(EXTENSION_SRC)/%: $(EXTENSION_SRC)/% + @cp -R $< $@ + # # make compiler # # # # This target downloads the Closure compiler, and places it in the @@ -149,13 +159,11 @@ $(GH_PAGES)/web/images/%: web/images/% # curl $(COMPILER_URL) > $(BUILD_DIR)/compiler.zip; # cd $(BUILD_DIR); unzip compiler.zip compiler.jar; -# make firefox-extension +# make extension # # This target produce a restartless firefox extension containing a # copy of the pdf.js source. CONTENT_DIR := content -EXTENSION_SRC := ./extensions/firefox -EXTENSION_NAME := pdf.js.xpi PDF_WEB_FILES = \ web/images \ web/compatibility.js \ From b45f646267cf982b7441738f554abb7d7b806cba Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Tue, 11 Oct 2011 18:26:25 -0500 Subject: [PATCH 10/43] Add fit11-talk as a eq reftest --- test/pdfs/fit11-talk.pdf.link | 1 + test/test_manifest.json | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 test/pdfs/fit11-talk.pdf.link diff --git a/test/pdfs/fit11-talk.pdf.link b/test/pdfs/fit11-talk.pdf.link new file mode 100644 index 000000000..af7107ee2 --- /dev/null +++ b/test/pdfs/fit11-talk.pdf.link @@ -0,0 +1 @@ +http://www.ccs.neu.edu/home/samth/fit11-talk.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 43b799bad..1270cce29 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -144,6 +144,13 @@ "rounds": 1, "type": "eq" }, + { "id": "fit11-talk", + "file": "pdfs/fit11-talk.pdf", + "link": true, + "rounds": 1, + "skipPages": [12,31], + "type": "eq" + }, { "id": "fips197", "file": "pdfs/fips197.pdf", "link": true, From e745114a5e13b5a6e842d502cfd2bddba6381f03 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Tue, 11 Oct 2011 19:38:20 -0500 Subject: [PATCH 11/43] Making the normalized name same in pdf.js and fonts.js --- fonts.js | 83 ++++++++++++++++++++++++++++---------------------------- pdf.js | 2 +- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/fonts.js b/fonts.js index 1c0039264..120e5111c 100644 --- a/fonts.js +++ b/fonts.js @@ -26,53 +26,53 @@ var kHintingEnabled = false; */ var stdFontMap = { 'ArialNarrow': 'Helvetica', - 'ArialNarrow_Bold': 'Helvetica-Bold', - 'ArialNarrow_BoldItalic': 'Helvetica-BoldOblique', - 'ArialNarrow_Italic': 'Helvetica-Oblique', + 'ArialNarrow-Bold': 'Helvetica-Bold', + 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique', + 'ArialNarrow-Italic': 'Helvetica-Oblique', 'ArialBlack': 'Helvetica', - 'ArialBlack_Bold': 'Helvetica-Bold', - 'ArialBlack_BoldItalic': 'Helvetica-BoldOblique', - 'ArialBlack_Italic': 'Helvetica-Oblique', + 'ArialBlack-Bold': 'Helvetica-Bold', + 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique', + 'ArialBlack-Italic': 'Helvetica-Oblique', 'Arial': 'Helvetica', - 'Arial_Bold': 'Helvetica-Bold', - 'Arial_BoldItalic': 'Helvetica-BoldOblique', - 'Arial_Italic': 'Helvetica-Oblique', - 'Arial_BoldItalicMT': 'Helvetica-BoldOblique', - 'Arial_BoldMT': 'Helvetica-Bold', - 'Arial_ItalicMT': 'Helvetica-Oblique', + 'Arial-Bold': 'Helvetica-Bold', + 'Arial-BoldItalic': 'Helvetica-BoldOblique', + 'Arial-Italic': 'Helvetica-Oblique', + 'Arial-BoldItalicMT': 'Helvetica-BoldOblique', + 'Arial-BoldMT': 'Helvetica-Bold', + 'Arial-ItalicMT': 'Helvetica-Oblique', 'ArialMT': 'Helvetica', - 'Courier_Bold': 'Courier-Bold', - 'Courier_BoldItalic': 'Courier-BoldOblique', - 'Courier_Italic': 'Courier-Oblique', + 'Courier-Bold': 'Courier-Bold', + 'Courier-BoldItalic': 'Courier-BoldOblique', + 'Courier-Italic': 'Courier-Oblique', 'CourierNew': 'Courier', - 'CourierNew_Bold': 'Courier-Bold', - 'CourierNew_BoldItalic': 'Courier-BoldOblique', - 'CourierNew_Italic': 'Courier-Oblique', - 'CourierNewPS_BoldItalicMT': 'Courier-BoldOblique', - 'CourierNewPS_BoldMT': 'Courier-Bold', - 'CourierNewPS_ItalicMT': 'Courier-Oblique', + 'CourierNew-Bold': 'Courier-Bold', + 'CourierNew-BoldItalic': 'Courier-BoldOblique', + 'CourierNew-Italic': 'Courier-Oblique', + 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique', + 'CourierNewPS-BoldMT': 'Courier-Bold', + 'CourierNewPS-ItalicMT': 'Courier-Oblique', 'CourierNewPSMT': 'Courier', - 'Helvetica_Bold': 'Helvetica-Bold', - 'Helvetica_BoldItalic': 'Helvetica-BoldOblique', - 'Helvetica_Italic': 'Helvetica-Oblique', - 'Symbol_Bold': 'Symbol', - 'Symbol_BoldItalic': 'Symbol', - 'Symbol_Italic': 'Symbol', + 'Helvetica-Bold': 'Helvetica-Bold', + 'Helvetica-BoldItalic': 'Helvetica-BoldOblique', + 'Helvetica-Italic': 'Helvetica-Oblique', + 'Symbol-Bold': 'Symbol', + 'Symbol-BoldItalic': 'Symbol', + 'Symbol-Italic': 'Symbol', 'TimesNewRoman': 'Times-Roman', - 'TimesNewRoman_Bold': 'Times-Bold', - 'TimesNewRoman_BoldItalic': 'Times-BoldItalic', - 'TimesNewRoman_Italic': 'Times-Italic', + 'TimesNewRoman-Bold': 'Times-Bold', + 'TimesNewRoman-BoldItalic': 'Times-BoldItalic', + 'TimesNewRoman-Italic': 'Times-Italic', 'TimesNewRomanPS': 'Times-Roman', - 'TimesNewRomanPS_Bold': 'Times-Bold', - 'TimesNewRomanPS_BoldItalic': 'Times-BoldItalic', - 'TimesNewRomanPS_BoldItalicMT': 'Times-BoldItalic', - 'TimesNewRomanPS_BoldMT': 'Times-Bold', - 'TimesNewRomanPS_Italic': 'Times-Italic', - 'TimesNewRomanPS_ItalicMT': 'Times-Italic', + 'TimesNewRomanPS-Bold': 'Times-Bold', + 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic', + 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic', + 'TimesNewRomanPS-BoldMT': 'Times-Bold', + 'TimesNewRomanPS-Italic': 'Times-Italic', + 'TimesNewRomanPS-ItalicMT': 'Times-Italic', 'TimesNewRomanPSMT': 'Times-Roman', - 'TimesNewRomanPSMT_Bold': 'Times-Bold', - 'TimesNewRomanPSMT_BoldItalic': 'Times-BoldItalic', - 'TimesNewRomanPSMT_Italic': 'Times-Italic' + 'TimesNewRomanPSMT-Bold': 'Times-Bold', + 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic', + 'TimesNewRomanPSMT-Italic': 'Times-Italic' }; var serifFonts = { @@ -441,8 +441,9 @@ var Font = (function Font() { if (!file) { // The file data is not specified. Trying to fix the font name // to be used with the canvas.font. - var fontName = stdFontMap[name.replace('-', '_')] || - name.replace('_', '-'); + var fontName = name.replace(/,_/g, '-'); + fontName = stdFontMap[fontName] || fontName; + this.bold = (fontName.search(/bold/gi) != -1); this.italic = (fontName.search(/oblique/gi) != -1) || (fontName.search(/italic/gi) != -1); diff --git a/pdf.js b/pdf.js index 847ed2ff4..311194208 100644 --- a/pdf.js +++ b/pdf.js @@ -4783,7 +4783,7 @@ var PartialEvaluator = (function partialEvaluator() { return null; // Using base font name as a font name. - baseFontName = baseFontName.name.replace(/,/g, '_'); + baseFontName = baseFontName.name.replace(/,_/g, '-'); var metricsAndMap = this.getBaseFontMetricsAndMap(baseFontName); var properties = { From fae8459991951c4b7466bfc9ca10a45d3b69ce98 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Tue, 11 Oct 2011 19:45:55 -0500 Subject: [PATCH 12/43] Add standard font name test (also for #621) --- test/pdfs/pal-o47.pdf.link | 1 + test/test_manifest.json | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 test/pdfs/pal-o47.pdf.link diff --git a/test/pdfs/pal-o47.pdf.link b/test/pdfs/pal-o47.pdf.link new file mode 100644 index 000000000..e45c4873d --- /dev/null +++ b/test/pdfs/pal-o47.pdf.link @@ -0,0 +1 @@ +http://www1.cpdl.org/wiki/images/sheet/pal-o47.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 43b799bad..3ede43ceb 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -199,6 +199,12 @@ "rounds": 1, "type": "eq" }, + { "id": "pal-o47", + "file": "pdfs/pal-o47.pdf", + "link": true, + "rounds": 1, + "type": "eq" + }, { "id": "simpletype3font", "file": "pdfs/simpletype3font.pdf", "link": false, From 07aa691fe022fec90629a903616c4a1a29562f63 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Tue, 11 Oct 2011 20:27:47 -0500 Subject: [PATCH 13/43] Fixing invalid CFF DICT entry (#621) --- fonts.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fonts.js b/fonts.js index 2ab3a90b7..4aa72eee0 100644 --- a/fonts.js +++ b/fonts.js @@ -2859,7 +2859,15 @@ var Type2CFF = (function type2CFF() { if (b <= 21) { if (b === 12) { ++pos; - var b = (b << 8) | dict[pos]; + var op = dict[pos]; + if ((op > 14 && op < 17) || + (op > 23 && op < 30) || op > 38) { + warn('Invalid CFF dictionary key: ' + op); + // trying to replace it with initialRandomSeed + // to pass sanitizer + dict[pos] = 19; + } + var b = (b << 8) | op; } entries.push([b, operands]); operands = []; From 5ec177d88e0f80eb4d66f4288828f59f8c4e461c Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Wed, 12 Oct 2011 17:37:55 -0500 Subject: [PATCH 14/43] Nit: Rename 's' by 'charcode' --- fonts.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fonts.js b/fonts.js index f31c52b76..d4183f146 100644 --- a/fonts.js +++ b/fonts.js @@ -2565,9 +2565,9 @@ var Type2CFF = (function type2CFF() { } if (!inDifferences) { var code = properties.firstChar + i; - for (var s in encoding) { + for (var charcode in encoding) { if (encoding[s] == i) { - code = s | 0; + code = charcode | 0; break; } } From 53cfe2792b1047019cdf4618d26daa44c2b9526e Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Wed, 12 Oct 2011 17:52:11 -0500 Subject: [PATCH 15/43] Fixing #650 regression --- fonts.js | 2 +- pdf.js | 2 +- test/test_manifest.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fonts.js b/fonts.js index efc9afe47..b05ad07c2 100644 --- a/fonts.js +++ b/fonts.js @@ -441,7 +441,7 @@ var Font = (function Font() { if (!file) { // The file data is not specified. Trying to fix the font name // to be used with the canvas.font. - var fontName = name.replace(/,_/g, '-'); + var fontName = name.replace(/[,_]/g, '-'); fontName = stdFontMap[fontName] || fontName; this.bold = (fontName.search(/bold/gi) != -1); diff --git a/pdf.js b/pdf.js index 9b78a8b2a..b8bc2b545 100644 --- a/pdf.js +++ b/pdf.js @@ -4783,7 +4783,7 @@ var PartialEvaluator = (function partialEvaluator() { return null; // Using base font name as a font name. - baseFontName = baseFontName.name.replace(/,_/g, '-'); + baseFontName = baseFontName.name.replace(/[,_]/g, '-'); var metricsAndMap = this.getBaseFontMetricsAndMap(baseFontName); var properties = { diff --git a/test/test_manifest.json b/test/test_manifest.json index 3ede43ceb..9149a61a1 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -148,7 +148,7 @@ "file": "pdfs/fips197.pdf", "link": true, "rounds": 1, - "type": "load" + "type": "eq" }, { "id": "txt2pdf", "file": "pdfs/txt2pdf.pdf", From 01f026ce14cf0a147f900f510897d7b058f29459 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Wed, 12 Oct 2011 19:53:57 -0500 Subject: [PATCH 16/43] Fixing duplicate charstring selection --- fonts.js | 61 +++++++++++++++++++++++++++++--------------------------- pdf.js | 4 ++-- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/fonts.js b/fonts.js index d4183f146..e4e7bb289 100644 --- a/fonts.js +++ b/fonts.js @@ -2551,34 +2551,34 @@ var Type2CFF = (function type2CFF() { privateDict, properties) { var defaultWidth = privateDict['defaultWidthX']; var charstrings = []; - var differences = properties.differences; - for (var i = 1; i < charsets.length; i++) { - var inDifferences; + var firstChar = properties.firstChar; + var glyphMap = {}; + for (var i = 0; i < charsets.length; i++) { var glyph = charsets[i]; - var code; - for (var j = 0; j < differences.length; j++) { - if (differences[j] == glyph) { - code = j; - inDifferences = true; - break; - } - } - if (!inDifferences) { - var code = properties.firstChar + i; - for (var charcode in encoding) { - if (encoding[s] == i) { - code = charcode | 0; - break; - } - } + for (var charcode in encoding) { + if (encoding[charcode] == i) + glyphMap[glyph] = charcode | 0; } + } - if (properties.encoding[code] && - properties.encoding[code].inDifferences) - continue; + var differences = properties.differences; + for (var i = 0; i < differences.length; ++i) { + var glyph = differences[i]; + if (!glyph) + continue; + var oldGlyph = charsets[i]; + if (oldGlyph) + delete glyphMap[oldGlyph]; + glyphMap[differences[i]] = i; + } - var mapping = properties.glyphs[code] || properties.glyphs[glyph] || {}; - var unicode = mapping.unicode || code; + var glyphs = properties.glyphs; + for (var i = 1; i < charsets.length; i++) { + var glyph = charsets[i]; + var code = glyphMap[glyph] || 0; + + var mapping = glyphs[code] || glyphs[glyph] || {}; + var unicode = mapping.unicode; if (unicode <= 0x1f || (unicode >= 127 && unicode <= 255)) unicode += kCmapGlyphOffset; @@ -2586,13 +2586,13 @@ var Type2CFF = (function type2CFF() { var width = isNum(mapping.width) ? mapping.width : defaultWidth; properties.encoding[code] = { unicode: unicode, - width: width, - inDifferences: inDifferences + width: width }; charstrings.push({ unicode: unicode, width: width, + code: code, gid: i }); } @@ -2604,7 +2604,6 @@ var Type2CFF = (function type2CFF() { // remove duplicates -- they might appear during selection: // properties.glyphs[code] || properties.glyphs[glyph] - // TODO make more deterministic var nextUnusedUnicode = kCmapGlyphOffset + 0x0020; var lastUnicode = charstrings[0].unicode, wasModified = false; for (var i = 1; i < charstrings.length; ++i) { @@ -2612,8 +2611,12 @@ var Type2CFF = (function type2CFF() { lastUnicode = charstrings[i].unicode; continue; } - // duplicate found -- changing the unicode for previous one - charstrings[i - 1].unicode = nextUnusedUnicode++; + // duplicate found -- keeping the item that has + // different code and unicode, that one created + // as result of modification of the base encoding + var duplicateIndex = + charstrings[i].unicode == charstrings[i].code ? i : i - 1; + charstrings[duplicateIndex].unicode = nextUnusedUnicode++; wasModified = true; } if (!wasModified) diff --git a/pdf.js b/pdf.js index 6f4524db5..c76ae7da0 100644 --- a/pdf.js +++ b/pdf.js @@ -4615,9 +4615,9 @@ var PartialEvaluator = (function partialEvaluator() { }; if (replaceGlyph || !glyphs[glyph]) - glyphs[glyph] = map[i]; + glyphs[glyph] = map[i]; if (replaceGlyph || !glyphs[index]) - glyphs[index] = map[i]; + glyphs[index] = map[i]; // If there is no file, the character mapping can't be modified // but this is unlikely that there is any standard encoding with From 1c1633e87cd62d37efca451abdde6b7de546a79e Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 13 Oct 2011 14:50:47 -0700 Subject: [PATCH 17/43] Making the test for extgstate be an 'eq' test and making the extgstate pdf more robust for picking up errors. --- pdf.js | 2 ++ test/pdfs/extgstate.pdf | 33 ++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/pdf.js b/pdf.js index c76ae7da0..4f5bf08a1 100644 --- a/pdf.js +++ b/pdf.js @@ -4384,6 +4384,7 @@ var PartialEvaluator = (function partialEvaluator() { while (!isEOF(obj = parser.getObj())) { if (isCmd(obj)) { + debugger; var cmd = obj.cmd; var fn = OP_MAP[cmd]; if (!fn) { @@ -5273,6 +5274,7 @@ var CanvasGraphics = (function canvasGraphics() { this.current.leading = -leading; }, setFont: function canvasGraphicsSetFont(fontRef, size) { + debugger; var font; // the tf command uses a name, but graphics state uses a reference if (isName(fontRef)) { diff --git a/test/pdfs/extgstate.pdf b/test/pdfs/extgstate.pdf index 711c45147..3392d9a66 100644 --- a/test/pdfs/extgstate.pdf +++ b/test/pdfs/extgstate.pdf @@ -36,8 +36,9 @@ endobj /Length 8 0 R >> stream + /F0 12 Tf +/F1 12 Tf /GS1 gs -/F0 12 Tf BT 100 700 Td (I should be courier!) Tj @@ -56,10 +57,11 @@ endobj 7 0 obj << /F0 10 0 R +/F1 11 0 R >> endobj 8 0 obj -82 +93 endobj 9 0 obj << @@ -81,25 +83,34 @@ endobj /Encoding /WinAnsiEncoding >> endobj +11 0 obj +<< +/Type /Font +/Subtype /Type1 +/BaseFont /Times-Italic +/Encoding /WinAnsiEncoding +>> +endobj xref -0 11 +0 12 0000000000 65535 f 0000000015 00000 n 0000000078 00000 n 0000000135 00000 n 0000000239 00000 n 0000000304 00000 n -0000000441 00000 n -0000000473 00000 n -0000000505 00000 n -0000000523 00000 n -0000000653 00000 n +0000000452 00000 n +0000000484 00000 n +0000000527 00000 n +0000000545 00000 n +0000000675 00000 n +0000000771 00000 n trailer << /Root 1 0 R -/ID [ ] -/Size 11 +/ID [ ] +/Size 12 >> startxref -749 +872 %%EOF From adfb3b8d318dff0208185d61d49e6b8acb4e94e0 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 13 Oct 2011 14:53:46 -0700 Subject: [PATCH 18/43] Remove debugs --- pdf.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/pdf.js b/pdf.js index 4f5bf08a1..c76ae7da0 100644 --- a/pdf.js +++ b/pdf.js @@ -4384,7 +4384,6 @@ var PartialEvaluator = (function partialEvaluator() { while (!isEOF(obj = parser.getObj())) { if (isCmd(obj)) { - debugger; var cmd = obj.cmd; var fn = OP_MAP[cmd]; if (!fn) { @@ -5274,7 +5273,6 @@ var CanvasGraphics = (function canvasGraphics() { this.current.leading = -leading; }, setFont: function canvasGraphicsSetFont(fontRef, size) { - debugger; var font; // the tf command uses a name, but graphics state uses a reference if (isName(fontRef)) { From 69648006d09dc75899ee2e2c47c766bbdb9d527e Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 13 Oct 2011 14:57:56 -0700 Subject: [PATCH 19/43] Change rotation and extgstate to eq tests. --- test/test_manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_manifest.json b/test/test_manifest.json index 413df5d1f..f564bc48e 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -100,7 +100,7 @@ { "id": "rotation", "file": "pdfs/rotation.pdf", "rounds": 1, - "type": "load" + "type": "eq" }, { "id": "ecma262-pdf", "file": "pdfs/ecma262.pdf", @@ -179,7 +179,7 @@ "file": "pdfs/extgstate.pdf", "link": false, "rounds": 1, - "type": "load" + "type": "eq" }, { "id": "usmanm-bad", "file": "pdfs/usmanm-bad.pdf", From b54be346b59b868c473a985242271e7e1f5696d4 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Fri, 14 Oct 2011 21:05:57 -0500 Subject: [PATCH 20/43] Add "bookmark" icon; and fixing scale/ current page number issues --- pdf.js | 5 +- web/images/bookmark.svg | 661 ++++++++++++++++++++++++++++++++++++++++ web/viewer.css | 4 + web/viewer.html | 4 + web/viewer.js | 98 ++++-- 5 files changed, 748 insertions(+), 24 deletions(-) create mode 100644 web/images/bookmark.svg diff --git a/pdf.js b/pdf.js index 3ebddd119..84ddd3800 100644 --- a/pdf.js +++ b/pdf.js @@ -3634,8 +3634,8 @@ var Page = (function pagePage() { gfx.execute(this.code, xref, resources); gfx.endDrawing(); }, - rotatePoint: function pageRotatePoint(x, y) { - var rotate = this.rotate; + rotatePoint: function pageRotatePoint(x, y, reverse) { + var rotate = reverse ? (360 - this.rotate) : this.rotate; switch (rotate) { case 180: return {x: this.width - x, y: y}; @@ -3643,6 +3643,7 @@ var Page = (function pagePage() { return {x: this.width - y, y: this.height - x}; case 270: return {x: y, y: x}; + case 360: case 0: default: return {x: x, y: this.height - y}; diff --git a/web/images/bookmark.svg b/web/images/bookmark.svg new file mode 100644 index 000000000..2c1fa130d --- /dev/null +++ b/web/images/bookmark.svg @@ -0,0 +1,661 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + New Bookmark + + + bookmark + remember + favorite + + + + + + Andreas Nilsson + + + + + + Jakub Steiner + + + create bookmark action + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/web/viewer.css b/web/viewer.css index e72bdc286..6c7b551e8 100644 --- a/web/viewer.css +++ b/web/viewer.css @@ -34,6 +34,10 @@ body { margin: 4px; } +#controls > a > img { + margin: 2px; +} + #controls > button { line-height: 32px; } diff --git a/web/viewer.html b/web/viewer.html index 160c5ce57..1f34fe01c 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -70,6 +70,10 @@
+ + Bookmark + + -- diff --git a/web/viewer.js b/web/viewer.js index 93f6acd31..6e43d6832 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -89,16 +89,23 @@ var PDFView = { var pages = this.pages; var input = document.getElementById('pageNumber'); if (!(0 < val && val <= pages.length)) { - input.value = this.page; + var event = document.createEvent('UIEvents'); + event.initUIEvent('pagechange', false, false, window, 0); + event.pageNumber = this.page; + window.dispatchEvent(event); return; } currentPageNumber = val; - document.getElementById('previous').disabled = (val == 1); - document.getElementById('next').disabled = (val == pages.length); - if (input.value != val) { - input.value = val; - } + var event = document.createEvent('UIEvents'); + event.initUIEvent('pagechange', false, false, window, 0); + event.pageNumber = val; + window.dispatchEvent(event); + + // checking if the this.page was called from the updateViewarea function: + // avoiding the creation of two "set page" method (internal and public) + if (updateViewarea.inProgress) + return; pages[val - 1].scrollIntoView(); }, @@ -147,12 +154,20 @@ var PDFView = { if (typeof dest === 'string') return '#' + escape(dest); if (dest instanceof Array) { - var destRef = dest[0]; // see nevigateTo method for dest format + var destRef = dest[0]; // see navigateTo method for dest format var pageNumber = destRef instanceof Object ? this.pagesRefMap[destRef.num + ' ' + destRef.gen + ' R'] : (destRef + 1); if (pageNumber) { - return '#page=' + pageNumber + '&dest=' + dest.slice(1).join(','); + var pdfOpenParams = '#page=' + pageNumber; + if (isName(dest[1], 'XYZ')) { + var scale = (dest[4] || this.currentScale); + pdfOpenParams += '&zoom=' + (scale * 100); + if (dest[2] || dest[3]) { + pdfOpenParams += ',' + (dest[2] || 0) + ',' + (dest[3] || 0); + } + } + return pdfOpenParams; } } return ''; @@ -226,10 +241,32 @@ var PDFView = { return; if (hash.indexOf('=') >= 0) { - // TODO more complex hashes, for now catching page=XX only - var m = /\bpage=(\d+)/.exec(hash); - if (m && m[1] > 0) - this.page = m[1]; + // parsing query string + var paramsPairs = hash.split('&'); + var params = {}; + for (var i = 0; i < paramsPairs.length; ++i) { + var paramPair = paramsPairs[i].split('='); + params[paramPair[0]] = paramPair[1]; + } + // borrowing syntax from "Parameters for Opening PDF Files" + if ('nameddest' in params) { + PDFView.navigateTo(params.nameddest); + return; + } + if ('page' in params) { + var pageNumber = (params.page | 0) || 1; + this.page = pageNumber; + if ('zoom' in params) { + var zoomArgs = params.zoom.split(','); // scale,left,top + // building destination array + var dest = [null, new Name('XYZ'), (zoomArgs[1] | 0), + (zoomArgs[2] | 0), (zoomArgs[0] | 0) / 100]; + var currentPage = this.pages[pageNumber - 1]; + currentPage.scrollIntoView(dest); + } else + this.page = page; // simple page + return; + } } else if (/^\d+$/.test(hash)) // page number this.page = hash; else // named destination @@ -339,6 +376,11 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight, } } + this.getPagePoint = function pageViewGetPagePoint(x, y) { + var scale = PDFView.currentScale; + return this.content.rotatePoint(x / scale, y / scale); + }; + this.scrollIntoView = function pageViewScrollIntoView(dest) { if (!dest) { div.scrollIntoView(true); @@ -388,7 +430,7 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight, this.content.rotatePoint(x + width, y + height) ]; - if (scale) + if (scale && scale !== PDFView.currentScale) PDFView.setScale(scale, true); setTimeout(function pageViewScrollIntoViewRelayout() { @@ -575,13 +617,21 @@ function updateViewarea() { if (!visiblePages.length) return; + updateViewarea.inProgress = true; // used in "set page" var currentId = PDFView.page; var firstPage = visiblePages[0]; - var lastPage = visiblePages[visiblePages.length - 1]; - if (currentId > lastPage.id && lastPage.y > window.pageYOffset) - PDFView.page = lastPage.id; - else if (currentId < firstPage.id) - PDFView.page = firstPage.id; + PDFView.page = firstPage.id; + updateViewarea.inProgress = false; + + var kViewerTopMargin = 52; + var pageNumber = firstPage.id; + var pdfOpenParams = '#page=' + pageNumber; + pdfOpenParams += '&zoom=' + Math.round(PDFView.currentScale * 100); + var currentPage = PDFView.pages[pageNumber - 1]; + var topLeft = currentPage.getPagePoint(window.pageXOffset, + window.pageYOffset - firstPage.y - kViewerTopMargin); + pdfOpenParams += ',' + Math.round(topLeft.x) + ',' + Math.round(topLeft.y); + document.getElementById('viewBookmark').href = pdfOpenParams; } window.addEventListener('scroll', function webViewerScroll(evt) { @@ -622,6 +672,9 @@ window.addEventListener('change', function webViewerChange(evt) { fileReader.readAsBinaryString(file); document.title = file.name; + + // URL does not reflect proper document location - hiding bookmark icon. + document.getElementById('viewBookmark').style.display = 'none'; }, true); window.addEventListener('transitionend', function webViewerTransitionend(evt) { @@ -672,10 +725,11 @@ window.addEventListener('scalechange', function scalechange(evt) { }, true); window.addEventListener('pagechange', function pagechange(evt) { - var page = evt.detail; - document.getElementById('pageNumber').value = page; - document.getElementById('previous').disabled = (page == 1); - document.getElementById('next').disabled = (page == PDFView.pages.length); + var page = evt.pageNumber; + if (document.getElementById('pageNumber').value != page) + document.getElementById('pageNumber').value = page; + document.getElementById('previous').disabled = (page <= 1); + document.getElementById('next').disabled = (page >= PDFView.pages.length); }, true); window.addEventListener('keydown', function keydown(evt) { From 5a3d85bf53341078186d7fda8688efab921e610f Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Sat, 15 Oct 2011 14:20:15 +0300 Subject: [PATCH 21/43] Fix small lint issues. --- charsets.js | 4 ++++ extensions/firefox/components/pdfContentHandler.js | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/charsets.js b/charsets.js index 59fcdf5cf..7f54ab327 100644 --- a/charsets.js +++ b/charsets.js @@ -1,3 +1,7 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ + +'use strict'; var ISOAdobeCharset = [ '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', diff --git a/extensions/firefox/components/pdfContentHandler.js b/extensions/firefox/components/pdfContentHandler.js index 879924047..9186bfd8a 100644 --- a/extensions/firefox/components/pdfContentHandler.js +++ b/extensions/firefox/components/pdfContentHandler.js @@ -131,8 +131,7 @@ pdfContentHandler.prototype = { throw Cr.NS_ERROR_WONT_HANDLE_CONTENT; let window = null; - let callbacks = aRequest.notificationCallbacks ? - aRequest.notificationCallbacks : + let callbacks = aRequest.notificationCallbacks || aRequest.loadGroup.notificationCallbacks; if (!callbacks) return; From 8cb7c218fdb614bf6406b092b9e163622aacc3c8 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Sat, 15 Oct 2011 14:27:14 +0300 Subject: [PATCH 22/43] Add use strict to metrics.js --- metrics.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/metrics.js b/metrics.js index 9cb8eb0e6..d4d07ec0d 100644 --- a/metrics.js +++ b/metrics.js @@ -1,6 +1,8 @@ /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ +'use strict'; + var Metrics = { 'Courier': 600, 'Courier-Bold': 600, From fb174290c7ed5b2297a5fb53c404cc390478d903 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Sat, 15 Oct 2011 22:03:57 +0300 Subject: [PATCH 23/43] Move function creation out of the loop. Also name the anonymous function. Jslint complains about this. --- pdf.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pdf.js b/pdf.js index 3ebddd119..ef8493001 100644 --- a/pdf.js +++ b/pdf.js @@ -4381,6 +4381,10 @@ var PartialEvaluator = (function partialEvaluator() { var patterns = xref.fetchIfRef(resources.get('Pattern')) || new Dict(); var parser = new Parser(new Lexer(stream), false); var args = [], argsArray = [], fnArray = [], obj; + var getObjBt = function getObjBt() { + parser = this.oldParser; + return { name: 'BT' }; + }; while (!isEOF(obj = parser.getObj())) { if (isCmd(obj)) { @@ -4392,10 +4396,7 @@ var PartialEvaluator = (function partialEvaluator() { fn = OP_MAP[cmd.substr(0, cmd.length - 2)]; // feeding 'BT' on next interation parser = { - getObj: function() { - parser = this.oldParser; - return { name: 'BT' }; - }, + getObj: getObjBt, oldParser: parser }; } From 3c53e34c7b9815b6ab5e82117e300045f6a8c2b1 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Sat, 15 Oct 2011 23:32:56 +0300 Subject: [PATCH 24/43] Refactor duplicate code in getBlackCode. --- pdf.js | 64 +++++++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/pdf.js b/pdf.js index 3ebddd119..0aaf68539 100644 --- a/pdf.js +++ b/pdf.js @@ -2089,45 +2089,35 @@ var CCITTFaxStream = (function ccittFaxStream() { return p[1]; } } else { - var n; - for (n = 2; n <= 6; ++n) { - code = this.lookBits(n); - if (code == EOF) - return 1; - if (n < 6) - code <<= 6 - n; - p = blackTable3[code]; - if (p[0] == n) { - this.eatBits(n); - return p[1]; - } - } - for (n = 7; n <= 12; ++n) { - code = this.lookBits(n); - if (code == EOF) - return 1; - if (n < 12) - code <<= 12 - n; - if (code >= 64) { - p = blackTable2[code - 64]; - if (p[0] == n) { - this.eatBits(n); - return p[1]; + var findBlackCode = function ccittFaxStreamFindBlackCode(start, end, table, limit) { + for (var i = start; i <= end; ++i) { + var code = this.lookBits(i); + if (code == EOF) + return [true, 1]; + if (i < end) + code <<= end - i; + if (code >= limit) { + var p = table[code]; + if (p[0] == i) { + this.eatBits(i); + return [true, p[1]]; + } } } - } - for (n = 10; n <= 13; ++n) { - code = this.lookBits(n); - if (code == EOF) - return 1; - if (n < 13) - code <<= 13 - n; - p = blackTable1[code]; - if (p[0] == n) { - this.eatBits(n); - return p[1]; - } - } + return [false, 0]; + }; + + var result = findBlackCode(2, 6, blackTable3, -1); + if (result[0]) + return result[1]; + + result = findBlackCode(7, 12, blackTable2, 64); + if (result[0]) + return result[1]; + + result = findBlackCode(10, 13, blackTable1, -1); + if (result[0]) + return result[1]; } warn('bad black code'); this.eatBits(1); From d39ea4dc5486911a8ce154f00d0d06b54b590386 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Sun, 16 Oct 2011 12:34:34 +0300 Subject: [PATCH 25/43] Adhere to 80 char line limit. --- pdf.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pdf.js b/pdf.js index 0aaf68539..60774808a 100644 --- a/pdf.js +++ b/pdf.js @@ -2089,7 +2089,8 @@ var CCITTFaxStream = (function ccittFaxStream() { return p[1]; } } else { - var findBlackCode = function ccittFaxStreamFindBlackCode(start, end, table, limit) { + var findBlackCode = function ccittFaxStreamFindBlackCode(start, end, + table, limit) { for (var i = start; i <= end; ++i) { var code = this.lookBits(i); if (code == EOF) From 674d6a7d18821fcea8570b70a2454d5a1ab2d4ec Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Mon, 17 Oct 2011 20:39:29 +0200 Subject: [PATCH 26/43] Fix warnings in strict mode --- fonts.js | 14 +++++++++++--- pdf.js | 12 ++++++++---- web/compatibility.js | 2 +- web/viewer.js | 7 +++++-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/fonts.js b/fonts.js index bbff14e89..bcec5d2ac 100644 --- a/fonts.js +++ b/fonts.js @@ -710,7 +710,13 @@ var Font = (function Font() { }; function createOS2Table(properties, override) { - var override = override || {}; + override = override || { + unitsPerEm: 0, + yMax: 0, + yMin: 0, + ascent: 0, + descent: 0 + }; var ulUnicodeRange1 = 0; var ulUnicodeRange2 = 0; @@ -1322,7 +1328,8 @@ var Font = (function Font() { 'OS/2': stringToArray(createOS2Table(properties)), // Character to glyphs mapping - 'cmap': createCMapTable(charstrings.slice(), font.glyphIds), + 'cmap': createCMapTable(charstrings.slice(), + ('glyphIds' in font) ? font.glyphIds: null), // Font header 'head': (function fontFieldsHead() { @@ -2612,7 +2619,8 @@ var Type2CFF = (function type2CFF() { if (unicode <= 0x1f || (unicode >= 127 && unicode <= 255)) unicode += kCmapGlyphOffset; - var width = isNum(mapping.width) ? mapping.width : defaultWidth; + var width = ('width' in mapping) && isNum(mapping.width) ? mapping.width + : defaultWidth; properties.encoding[code] = { unicode: unicode, width: width diff --git a/pdf.js b/pdf.js index ef8493001..2ee61ada6 100644 --- a/pdf.js +++ b/pdf.js @@ -5163,7 +5163,8 @@ var CanvasGraphics = (function canvasGraphics() { stroke: function canvasGraphicsStroke() { var ctx = this.ctx; var strokeColor = this.current.strokeColor; - if (strokeColor && strokeColor.type === 'Pattern') { + if (strokeColor && strokeColor.hasOwnProperty('type') && + strokeColor.type === 'Pattern') { // for patterns, we transform to pattern space, calculate // the pattern, call stroke, and restore to user space ctx.save(); @@ -5184,7 +5185,8 @@ var CanvasGraphics = (function canvasGraphics() { var ctx = this.ctx; var fillColor = this.current.fillColor; - if (fillColor && fillColor.type === 'Pattern') { + if (fillColor && fillColor.hasOwnProperty('type') && + fillColor.type === 'Pattern') { ctx.save(); ctx.fillStyle = fillColor.getPattern(ctx); ctx.fill(); @@ -5204,7 +5206,8 @@ var CanvasGraphics = (function canvasGraphics() { var ctx = this.ctx; var fillColor = this.current.fillColor; - if (fillColor && fillColor.type === 'Pattern') { + if (fillColor && fillColor.hasOwnProperty('type') && + fillColor.type === 'Pattern') { ctx.save(); ctx.fillStyle = fillColor.getPattern(ctx); ctx.fill(); @@ -5214,7 +5217,8 @@ var CanvasGraphics = (function canvasGraphics() { } var strokeColor = this.current.strokeColor; - if (strokeColor && strokeColor.type === 'Pattern') { + if (strokeColor && strokeColor.hasOwnProperty('type') && + strokeColor.type === 'Pattern') { ctx.save(); ctx.strokeStyle = strokeColor.getPattern(ctx); ctx.stroke(); diff --git a/web/compatibility.js b/web/compatibility.js index 36df0e2a5..ad4c8f8a9 100644 --- a/web/compatibility.js +++ b/web/compatibility.js @@ -163,7 +163,7 @@ // IE9 text/html data URI (function checkDocumentDocumentModeCompatibility() { - if (document.documentMode !== 9) + if (!('documentMode' in document) || document.documentMode !== 9) return; // overriding the src property var originalSrcDescriptor = Object.getOwnPropertyDescriptor( diff --git a/web/viewer.js b/web/viewer.js index 93f6acd31..91562baf4 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -178,7 +178,9 @@ var PDFView = { while (sidebar.hasChildNodes()) sidebar.removeChild(sidebar.lastChild); - clearInterval(sidebar._loadingInterval); + + if ('_loadingInterval' in sidebar) + clearInterval(sidebar._loadingInterval); var container = document.getElementById('viewer'); while (container.hasChildNodes()) @@ -544,7 +546,8 @@ window.addEventListener('load', function webViewerLoad(evt) { params[unescape(param[0])] = unescape(param[1]); } - PDFView.open(params.file || kDefaultURL, parseFloat(params.scale)); + var scale = ('scale' in params) ? params.scale : kDefaultScale; + PDFView.open(params.file || kDefaultURL, parseFloat(scale)); if (!window.File || !window.FileReader || !window.FileList || !window.Blob) document.getElementById('fileInput').style.display = 'none'; From e83c77148d4c64602ad3d88aba0c4b5c5e998186 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Mon, 17 Oct 2011 21:04:54 +0200 Subject: [PATCH 27/43] add oncontextmenu='return false;' to buttons --- web/viewer.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/web/viewer.html b/web/viewer.html index 160c5ce57..428171b9e 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -17,12 +17,12 @@
- - @@ -36,16 +36,16 @@
- -
- @@ -59,14 +59,14 @@
-
- +
From 6688c3a1f5c1ff8d0071bba8d76e60df9f99ec2f Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Mon, 17 Oct 2011 22:24:19 +0300 Subject: [PATCH 28/43] Handle blackTable2 array access correctly. --- pdf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdf.js b/pdf.js index 60774808a..f11d28c36 100644 --- a/pdf.js +++ b/pdf.js @@ -2098,7 +2098,7 @@ var CCITTFaxStream = (function ccittFaxStream() { if (i < end) code <<= end - i; if (code >= limit) { - var p = table[code]; + var p = table[code - ((limit == -1) ? 0 : limit)]; if (p[0] == i) { this.eatBits(i); return [true, p[1]]; From 31cb9b49d502c387477e6c7f42da127243e6021b Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Tue, 18 Oct 2011 00:00:44 +0300 Subject: [PATCH 29/43] Fix javascript strict warnings in driver.js. --- test/driver.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/driver.js b/test/driver.js index 7f5aef733..b453c5051 100644 --- a/test/driver.js +++ b/test/driver.js @@ -66,7 +66,8 @@ function nextTask() { cleanup(); if (currentTaskIdx == manifest.length) { - return done(); + done(); + return; } var task = manifest[currentTaskIdx]; task.round = 0; @@ -86,7 +87,7 @@ function nextTask() { } function isLastPage(task) { - return task.pageNum > task.pdfDoc.numPages || task.pageNum > task.pageLimit; + return task.pageNum > (task.pageLimit || task.pdfDoc.numPages); } function canvasToDataURL() { From 3ba167645fb75374e86aae30648fb385d76af970 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Tue, 18 Oct 2011 00:29:43 +0300 Subject: [PATCH 30/43] Refactor duplicate code in getWhiteCode. Reuse functionality from getBlackCode for this. --- pdf.js | 74 ++++++++++++++++++++++------------------------------------ 1 file changed, 28 insertions(+), 46 deletions(-) diff --git a/pdf.js b/pdf.js index 68c5dfad4..d4326b5ab 100644 --- a/pdf.js +++ b/pdf.js @@ -2021,6 +2021,25 @@ var CCITTFaxStream = (function ccittFaxStream() { return EOF; }; + var findTableCode = function ccittFaxStreamFindTableCode(start, end, table, + limit) { + for (var i = start; i <= end; ++i) { + var code = this.lookBits(i); + if (code == EOF) + return [true, 1]; + if (i < end) + code <<= end - i; + if (code >= limit) { + var p = table[code - ((limit == ccittEOL) ? 0 : limit)]; + if (p[0] == i) { + this.eatBits(i); + return [true, p[1]]; + } + } + } + return [false, 0]; + }; + constructor.prototype.getWhiteCode = function ccittFaxStreamGetWhiteCode() { var code = 0; var p; @@ -2040,31 +2059,13 @@ var CCITTFaxStream = (function ccittFaxStream() { return p[1]; } } else { - for (var n = 1; n <= 9; ++n) { - code = this.lookBits(n); - if (code == EOF) - return 1; + var result = findTableCode(1, 9, whiteTable2, ccittEOL); + if (result[0]) + return result[1]; - if (n < 9) - code <<= 9 - n; - p = whiteTable2[code]; - if (p[0] == n) { - this.eatBits(n); - return p[0]; - } - } - for (var n = 11; n <= 12; ++n) { - code = this.lookBits(n); - if (code == EOF) - return 1; - if (n < 12) - code <<= 12 - n; - p = whiteTable1[code]; - if (p[0] == n) { - this.eatBits(n); - return p[1]; - } - } + result = findTableCode(11, 12, whiteTable1, ccittEOL); + if (result[0]) + return result[1]; } warn('bad white code'); this.eatBits(1); @@ -2089,34 +2090,15 @@ var CCITTFaxStream = (function ccittFaxStream() { return p[1]; } } else { - var findBlackCode = function ccittFaxStreamFindBlackCode(start, end, - table, limit) { - for (var i = start; i <= end; ++i) { - var code = this.lookBits(i); - if (code == EOF) - return [true, 1]; - if (i < end) - code <<= end - i; - if (code >= limit) { - var p = table[code - ((limit == -1) ? 0 : limit)]; - if (p[0] == i) { - this.eatBits(i); - return [true, p[1]]; - } - } - } - return [false, 0]; - }; - - var result = findBlackCode(2, 6, blackTable3, -1); + var result = findTableCode(2, 6, blackTable3, ccittEOL); if (result[0]) return result[1]; - result = findBlackCode(7, 12, blackTable2, 64); + result = findTableCode(7, 12, blackTable2, 64); if (result[0]) return result[1]; - result = findBlackCode(10, 13, blackTable1, -1); + result = findTableCode(10, 13, blackTable1, ccittEOL); if (result[0]) return result[1]; } From f1444d6175794dd942c8a7d0f74b02508cb96bac Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Tue, 18 Oct 2011 00:18:12 +0200 Subject: [PATCH 31/43] Fix wrongs ids --- web/viewer.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/viewer.html b/web/viewer.html index 428171b9e..5da063b91 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -36,10 +36,10 @@
- - From 931192fb79d03746626ef35312d5fc925c02b8d8 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Tue, 18 Oct 2011 01:28:57 +0200 Subject: [PATCH 32/43] Remove useless code since the extension is loaded into a privileged chrome:// scope --- .../firefox/components/pdfContentHandler.js | 105 +----------------- web/viewer.js | 15 --- 2 files changed, 2 insertions(+), 118 deletions(-) diff --git a/extensions/firefox/components/pdfContentHandler.js b/extensions/firefox/components/pdfContentHandler.js index 9186bfd8a..eda0ec92c 100644 --- a/extensions/firefox/components/pdfContentHandler.js +++ b/extensions/firefox/components/pdfContentHandler.js @@ -20,105 +20,6 @@ function log(aMsg) { dump(msg + '\n'); } -function fireEventTo(aName, aData, aWindow) { - let window = aWindow.wrappedJSObject; - let evt = window.document.createEvent('CustomEvent'); - evt.initCustomEvent('pdf' + aName, false, false, aData); - window.document.dispatchEvent(evt); -} - -function loadDocument(aWindow, aDocumentUrl) { - let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1'] - .createInstance(Ci.nsIXMLHttpRequest); - xhr.onprogress = function updateProgress(evt) { - if (evt.lengthComputable) - fireEventTo(evt.type, evt.loaded / evt.total, aWindow); - }; - - xhr.onerror = function error(evt) { - fireEventTo(evt.type, false, aWindow); - }; - - xhr.onload = function load(evt) { - let data = (xhr.mozResponseArrayBuffer || xhr.mozResponse || - xhr.responseArrayBuffer || xhr.response); - try { - let view = new Uint8Array(data); - - let window = aWindow.wrappedJSObject; - let arrayBuffer = new window.ArrayBuffer(data.byteLength); - let view2 = new window.Uint8Array(arrayBuffer); - view2.set(view); - - fireEventTo(evt.type, arrayBuffer, aWindow); - } catch (e) { - log('Error - ' + e); - } - }; - - xhr.open('GET', aDocumentUrl); - xhr.responseType = 'arraybuffer'; - xhr.send(null); -} - -let WebProgressListener = { - init: function WebProgressListenerInit(aWindow, aUrl) { - this._locationHasChanged = false; - this._documentUrl = aUrl; - - let flags = Ci.nsIWebProgress.NOTIFY_LOCATION | - Ci.nsIWebProgress.NOTIFY_STATE_NETWORK | - Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT; - - let docShell = aWindow.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebNavigation) - .QueryInterface(Ci.nsIDocShell); - let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebProgress); - try { - webProgress.removeProgressListener(this); - } catch (e) {} - webProgress.addProgressListener(this, flags); - }, - - onStateChange: function onStateChange(aWebProgress, aRequest, aStateFlags, - aStatus) { - const complete = Ci.nsIWebProgressListener.STATE_IS_WINDOW + - Ci.nsIWebProgressListener.STATE_STOP; - if ((aStateFlags & complete) == complete && this._locationHasChanged) { - aWebProgress.removeProgressListener(this); - loadDocument(aWebProgress.DOMWindow, this._documentUrl); - } - }, - - onProgressChange: function onProgressChange(aWebProgress, aRequest, aCurSelf, - aMaxSelf, aCurTotal, aMaxTotal) { - }, - - onLocationChange: function onLocationChange(aWebProgress, aRequest, - aLocationURI) { - this._locationHasChanged = true; - }, - - onStatusChange: function onStatusChange(aWebProgress, aRequest, aStatus, - aMessage) { - }, - - onSecurityChange: function onSecurityChange(aWebProgress, aRequest, aState) { - }, - - QueryInterface: function QueryInterface(aIID) { - if (aIID.equals(Ci.nsIWebProgressListener) || - aIID.equals(Ci.nsISupportsWeakReference) || - aIID.equals(Ci.nsISupports)) { - return this; - } - - throw Components.results.NS_ERROR_NO_INTERFACE; - } -}; - - function pdfContentHandler() { } @@ -139,12 +40,11 @@ pdfContentHandler.prototype = { aRequest.cancel(Cr.NS_BINDING_ABORTED); let uri = aRequest.URI; - window = callbacks.getInterface(Ci.nsIDOMWindow); - WebProgressListener.init(window, uri.spec); - try { let url = Services.prefs.getCharPref('extensions.pdf.js.url'); url = url.replace('%s', uri.spec); + + window = callbacks.getInterface(Ci.nsIDOMWindow); window.location = url; } catch (e) { log('Error retrieving the pdf.js base url - ' + e); @@ -157,4 +57,3 @@ pdfContentHandler.prototype = { var NSGetFactory = XPCOMUtils.generateNSGetFactory([pdfContentHandler]); - diff --git a/web/viewer.js b/web/viewer.js index 91562baf4..4008d58e1 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -108,9 +108,6 @@ var PDFView = { }, open: function pdfViewOpen(url, scale) { - if (url.indexOf('http') == 0) - return; - document.title = url; getPdf( @@ -555,18 +552,6 @@ window.addEventListener('load', function webViewerLoad(evt) { document.getElementById('fileInput').value = null; }, true); -window.addEventListener('pdfload', function webViewerPdfload(evt) { - PDFView.load(evt.detail); -}, true); - -window.addEventListener('pdfprogress', function webViewerPdfProgress(evt) { - PDFView.progress(evt.detail); -}, true); - -window.addEventListener('pdferror', function webViewerPdfError(evt) { - PDFView.error(); -}, true); - function updateViewarea() { var visiblePages = PDFView.getVisiblePages(); for (var i = 0; i < visiblePages.length; i++) { From e347ad03d97599588aa9be0f134f665f4b7b46de Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Tue, 18 Oct 2011 01:34:44 +0200 Subject: [PATCH 33/43] Fix a small broking mistake in fonts.js --- fonts.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fonts.js b/fonts.js index bcec5d2ac..2bcfa5e6e 100644 --- a/fonts.js +++ b/fonts.js @@ -2613,14 +2613,13 @@ var Type2CFF = (function type2CFF() { var glyph = charsets[i]; var code = glyphMap[glyph] || 0; - var mapping = glyphs[code] || glyphs[glyph] || {}; + var mapping = glyphs[code] || glyphs[glyph] || { width: defaultWidth }; var unicode = mapping.unicode; if (unicode <= 0x1f || (unicode >= 127 && unicode <= 255)) unicode += kCmapGlyphOffset; - var width = ('width' in mapping) && isNum(mapping.width) ? mapping.width - : defaultWidth; + var width = isNum(mapping.width) ? mapping.width : defaultWidth; properties.encoding[code] = { unicode: unicode, width: width From b8a5b76db5cd20dfba5891e9f70de27fe46aa46f Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Tue, 18 Oct 2011 03:45:07 +0200 Subject: [PATCH 34/43] Fix a spacing issue --- fonts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fonts.js b/fonts.js index 2bcfa5e6e..2ba6e2f7a 100644 --- a/fonts.js +++ b/fonts.js @@ -1329,7 +1329,7 @@ var Font = (function Font() { // Character to glyphs mapping 'cmap': createCMapTable(charstrings.slice(), - ('glyphIds' in font) ? font.glyphIds: null), + ('glyphIds' in font) ? font.glyphIds : null), // Font header 'head': (function fontFieldsHead() { From ecf831b44bb712dca16dfb1616140cc1faf99202 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Tue, 18 Oct 2011 20:32:33 +0300 Subject: [PATCH 35/43] Use task.pageLimit properly. --- test/driver.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/driver.js b/test/driver.js index b453c5051..4b42c40b5 100644 --- a/test/driver.js +++ b/test/driver.js @@ -87,7 +87,11 @@ function nextTask() { } function isLastPage(task) { - return task.pageNum > (task.pageLimit || task.pdfDoc.numPages); + var limit = task.pageLimit || 0; + if (!limit || limit > task.pdfDoc.numPages) + limit = task.pdfDoc.numPages; + + return task.pageNum > limit; } function canvasToDataURL() { From 20efacb3a1e2c137e7f7ef934bd8590331b21ece Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Tue, 18 Oct 2011 21:40:59 +0200 Subject: [PATCH 36/43] Use 'hidden' instead of display: none --- web/viewer.css | 4 ++++ web/viewer.html | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/web/viewer.css b/web/viewer.css index 6c7b551e8..040b87bdf 100644 --- a/web/viewer.css +++ b/web/viewer.css @@ -8,6 +8,10 @@ body { padding: 0px; } +[hidden] { + display: none; +} + /* === Toolbar === */ #controls { background-color: #eee; diff --git a/web/viewer.html b/web/viewer.html index f761c94fe..4175d29fc 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -82,7 +82,7 @@
-