From ef2f3cdc24e727df30bc19f6ff44707a99c86195 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Sun, 4 Sep 2011 14:37:30 +0300 Subject: [PATCH 1/3] Fix some jslint warnings. --- pdf.js | 84 +++++++++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/pdf.js b/pdf.js index 8303bb650..a934afb91 100644 --- a/pdf.js +++ b/pdf.js @@ -276,11 +276,11 @@ var FakeStream = (function() { }; constructor.prototype.getBytes = function(length) { - var pos = this.pos; + var end, pos = this.pos; if (length) { this.ensureBuffer(pos + length); - var end = pos + length; + end = pos + length; while (!this.eof && this.bufferLength < end) this.readBlock(); @@ -290,7 +290,7 @@ var FakeStream = (function() { end = bufEnd; } else { this.eof = true; - var end = this.bufferLength; + end = this.bufferLength; } this.pos = end; @@ -2056,7 +2056,7 @@ var CCITTFaxStream = (function() { constructor.prototype.eatBits = function(n) { if ((this.inputBits -= n) < 0) this.inputBits = 0; - } + }; return constructor; })(); @@ -2359,7 +2359,7 @@ var Lexer = (function() { constructor.isSpace = function(ch) { return ch == ' ' || ch == '\t'; - } + }; // A '1' in this array means the character is white space. A '1' or // '2' means the character ends a name or command. @@ -2432,7 +2432,8 @@ var Lexer = (function() { var stream = this.stream; var ch; do { - switch (ch = stream.getChar()) { + ch = stream.getChar(); + switch (ch) { case undefined: warn('Unterminated string'); done = true; @@ -2449,7 +2450,8 @@ var Lexer = (function() { } break; case '\\': - switch (ch = stream.getChar()) { + ch = stream.getChar(); + switch (ch) { case undefined: warn('Unterminated string'); done = true; @@ -2802,7 +2804,7 @@ var Parser = (function() { if (xref) length = xref.fetchIfRef(length); if (!IsInt(length)) { - error('Bad ' + Length + ' attribute in stream'); + error('Bad ' + length + ' attribute in stream'); length = 0; } @@ -3160,7 +3162,7 @@ var XRef = (function() { if (!IsCmd(obj3, 'obj')) { // some bad pdfs use "obj1234" and really mean 1234 if (obj3.cmd.indexOf('obj') == 0) { - var num = parseInt(obj3.cmd.substring(3)); + num = parseInt(obj3.cmd.substring(3)); if (!isNaN(num)) return num; } @@ -3190,7 +3192,7 @@ var XRef = (function() { var i, entries = [], nums = []; // read the object numbers to populate cache for (i = 0; i < n; ++i) { - var num = parser.getObj(); + num = parser.getObj(); if (!IsInt(num)) { error('invalid object number in the ObjStm stream: ' + num); } @@ -4175,7 +4177,7 @@ var PartialEvaluator = (function() { return function(gfx) { for (var i = 0, length = argsArray.length; i < length; i++) gfx[fnArray[i]].apply(gfx, argsArray[i]); - } + }; }, translateFont: function(fontDict, xref, resources) { @@ -5221,7 +5223,7 @@ var CanvasGraphics = (function() { })(); var Util = (function() { - function constructor() {}; + function constructor() {} constructor.makeCssRgb = function makergb(r, g, b) { var ri = (255 * r) | 0, gi = (255 * g) | 0, bi = (255 * b) | 0; return 'rgb(' + ri + ',' + gi + ',' + bi + ')'; @@ -5244,7 +5246,7 @@ var ColorSpace = (function() { // Constructor should define this.numComps, this.defaultColor, this.name function constructor() { error('should not call ColorSpace constructor'); - }; + } constructor.prototype = { // Input: array of size numComps representing color component values @@ -5279,18 +5281,14 @@ var ColorSpace = (function() { case 'DeviceGray': case 'G': return new DeviceGrayCS(); - break; case 'DeviceRGB': case 'RGB': return new DeviceRgbCS(); - break; case 'DeviceCMYK': case 'CMYK': return new DeviceCmykCS(); - break; case 'Pattern': return new PatternCS(null); - break; default: error('unrecognized colorspace ' + mode); } @@ -5302,30 +5300,25 @@ var ColorSpace = (function() { case 'DeviceGray': case 'G': return new DeviceGrayCS(); - break; case 'DeviceRGB': case 'RGB': return new DeviceRgbCS(); - break; case 'DeviceCMYK': case 'CMYK': return new DeviceCmykCS(); - break; case 'CalGray': return new DeviceGrayCS(); - break; case 'CalRGB': return new DeviceRgbCS(); - break; case 'ICCBased': var stream = xref.fetchIfRef(cs[1]); var dict = stream.dict; var numComps = dict.get('N'); if (numComps == 1) return new DeviceGrayCS(); - else if (numComps == 3) + if (numComps == 3) return new DeviceRgbCS(); - else if (numComps == 4) + if (numComps == 4) return new DeviceCmykCS(); break; case 'Pattern': @@ -5333,19 +5326,16 @@ var ColorSpace = (function() { if (baseCS) baseCS = ColorSpace.parse(baseCS, xref, res); return new PatternCS(baseCS); - break; case 'Indexed': var base = ColorSpace.parse(cs[1], xref, res); var hiVal = cs[2] + 1; var lookup = xref.fetchIfRef(cs[3]); return new IndexedCS(base, hiVal, lookup); - break; case 'Separation': var name = cs[1]; var alt = ColorSpace.parse(cs[2], xref, res); var tintFn = new PDFFunction(xref, xref.fetchIfRef(cs[3])); return new SeparationCS(alt, tintFn); - break; case 'Lab': case 'DeviceN': default: @@ -5435,7 +5425,7 @@ var IndexedCS = (function() { constructor.prototype = { getRgb: function indexcs_getRgb(color) { - var numComps = base.numComps; + var numComps = this.base.numComps; var start = color[0] * numComps; var c = []; @@ -5471,7 +5461,7 @@ var DeviceGrayCS = (function() { this.name = 'DeviceGray'; this.numComps = 1; this.defaultColor = [0]; - }; + } constructor.prototype = { getRgb: function graycs_getRgb(color) { @@ -5606,7 +5596,7 @@ var Pattern = (function() { // Constructor should define this.getPattern function constructor() { error('should not call Pattern constructor'); - }; + } constructor.prototype = { // Input: current Canvas context @@ -5670,14 +5660,14 @@ var Pattern = (function() { default: return new DummyShading(); } - } + }; return constructor; })(); var DummyShading = (function() { function constructor() { this.type = 'Pattern'; - }; + } constructor.prototype = { getPattern: function dummy_getpattern() { return 'hotpink'; @@ -5707,13 +5697,15 @@ var RadialAxialShading = (function() { var t0 = 0.0, t1 = 1.0; if (dict.has('Domain')) { var domainArr = dict.get('Domain'); - t0 = domainArr[0], t1 = domainArr[1]; + t0 = domainArr[0]; + t1 = domainArr[1]; } var extendStart = false, extendEnd = false; if (dict.has('Extend')) { var extendArr = dict.get('Extend'); - extendStart = extendArr[0], extendEnd = extendArr[1]; + extendStart = extendArr[0]; + extendEnd = extendArr[1]; TODO('Support extend'); } @@ -5742,7 +5734,7 @@ var RadialAxialShading = (function() { } this.colorStops = colorStops; - }; + } constructor.prototype = { getPattern: function() { @@ -5807,7 +5799,7 @@ var TilingPattern = (function() { var e = m[4] * tm[0] + m[5] * tm[2] + tm[4]; var f = m[4] * tm[1] + m[5] * tm[3] + tm[5]; return [a, b, c, d, e, f]; - }; + } TODO('TilingType'); @@ -5879,7 +5871,7 @@ var TilingPattern = (function() { graphics.execute(code, xref, res); this.canvas = tmpCanvas; - }; + } constructor.prototype = { getPattern: function tiling_getPattern() { @@ -5958,7 +5950,7 @@ var PDFImage = (function() { } else if (smask) { this.smask = new PDFImage(xref, res, smask); } - }; + } constructor.prototype = { getComponents: function getComponents(buffer, decodeMap) { @@ -6133,7 +6125,7 @@ var PDFFunction = (function() { error('Unknown type of function'); typeFn.call(this, fn, dict, xref); - }; + } constructor.prototype = { constructSampled: function(str, dict) { @@ -6179,7 +6171,7 @@ var PDFFunction = (function() { else if (v < min) v = min; return v; - } + }; if (inputSize != args.length) error('Incorrect number of arguments: ' + inputSize + ' != ' + @@ -6229,7 +6221,7 @@ var PDFFunction = (function() { } return output; - } + }; }, getSampleArray: function(size, outputSize, bps, str) { var length = 1; @@ -6277,7 +6269,7 @@ var PDFFunction = (function() { out.push(c0[j] + (x^n * diff[i])); return out; - } + }; }, constructStiched: function(fn, dict, xref) { var domain = dict.get('Domain'); @@ -6305,7 +6297,7 @@ var PDFFunction = (function() { else if (v < min) v = min; return v; - } + }; // clip to domain var v = clip(args[0], domain[0], domain[1]); @@ -6330,11 +6322,13 @@ var PDFFunction = (function() { // call the appropropriate function return fns[i].func([v2]); - } + }; }, constructPostScript: function() { TODO('unhandled type of function'); - this.func = function() { return [255, 105, 180]; } + this.func = function() { + return [255, 105, 180]; + }; } }; From b1a5ab6d0f24ab26a06bd37fbd0b37fbf2f19c3a Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Mon, 5 Sep 2011 14:35:03 +0200 Subject: [PATCH 2/3] Fix regression on i9.pdf --- fonts.js | 37 ++++++++++++++++++++++--------------- pdf.js | 1 - 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/fonts.js b/fonts.js index 90e70a302..95f136395 100755 --- a/fonts.js +++ b/fonts.js @@ -9,6 +9,10 @@ var isWorker = (typeof window == 'undefined'); */ var kMaxWaitForFontFace = 1000; +// Unicode Private Use Area +var kCmapGlyphOffset = 0xE000; + + /** * Hold a map of decoded fonts and of the standard fourteen Type1 * fonts and their acronyms. @@ -797,9 +801,6 @@ var Font = (function Font() { encoding: null, checkAndRepair: function font_checkAndRepair(name, font, properties) { - // offset glyphs to the Unicode Private Use Area - var kCmapGlyphOffset = 0xE000; - function readTableEntry(file) { var tag = file.getBytes(4); tag = String.fromCharCode(tag[0]) + @@ -879,16 +880,23 @@ var Font = (function Font() { var index = font.getByte(); if (index) { deltas.push(index); - glyphs.push({ unicode: j }); + + var code = encoding[index]; + for (var glyph in properties.glyphs) { + if (properties.glyphs[glyph] == code) + break; + } + + glyphs.push({ glyph: glyph, unicode: j }); } } if (properties.firstChar < 0x20) { - var code = 0; for (var j = 0; j < glyphs.length; j++) { var glyph = glyphs[j]; - glyphs[j].unicode += 0x1F; - properties.glyphs[glyph.glyph] = encoding[++code] = glyph.unicode; + var code = glyph.unicode + kCmapGlyphOffset; + properties.glyphs[glyph.glyph] = encoding[glyph.unicode] = code; + glyph.unicode = code; } } @@ -1406,7 +1414,7 @@ var Type1Parser = function() { // Type1 only command with command not (yet) built-in ,throw an error '6': -1, // seac - '7': -1, //sbw + '7': -1, // sbw '11': 'sub', '12': 'div', @@ -1422,8 +1430,8 @@ var Type1Parser = function() { // moveto (this is a one shot positionning command). This is used only // with the return of an OtherSubrs call. // TODO Implement the OtherSubrs charstring embedding and replace this - // call by a no-op, like 2 'pop' commands for example. - '33': null //setcurrentpoint + // call by a no-op, like 2 'pop' commands for example. + '33': null // setcurrentpoint }, '13': 'hsbw', '14': 'endchar', @@ -1458,7 +1466,7 @@ var Type1Parser = function() { charstring.push('drop'); // If the flex mechanism is not used in a font program, Adobe - // state that that entries 0, 1 and 2 can simply be replace by + // states that entries 0, 1 and 2 can simply be replaced by // {}, which means that we can simply ignore them. if (index < 3) { continue; @@ -1477,7 +1485,7 @@ var Type1Parser = function() { command = charStringDictionary['12'][escape]; } else { // TODO Clean this code - if (value == 13) { //hsbw + if (value == 13) { // hsbw if (charstring.length == 2) { lsb = charstring[0]; width = charstring[1]; @@ -1646,9 +1654,9 @@ var Type1Parser = function() { var encoded = decrypt(data, kCharStringsEncryptionKey, lenIV); var str = decodeCharString(encoded); i = i + 1 + length; - t = getToken(); //read in 'NP' + t = getToken(); // read in 'NP' if (t == 'noaccess') - getToken(); //read in 'put' + getToken(); // read in 'put' program.subrs[index] = str.charstring; } break; @@ -2235,7 +2243,6 @@ var Type2CFF = (function() { var nominalWidth = privDict['nominalWidthX']; var charstrings = []; - var kCmapGlyphOffset = 0xE000; var differences = properties.differences; var index = 0; for (var i = 1; i < charsets.length; i++) { diff --git a/pdf.js b/pdf.js index 631496481..dcc9f8887 100644 --- a/pdf.js +++ b/pdf.js @@ -4304,7 +4304,6 @@ var PartialEvaluator = (function() { var index = GlyphsUnicode[glyph] || i; glyphsMap[glyph] = encodingMap[i] = index; - var kCmapGlyphOffset = 0xE000; if (index <= 0x1f || (index >= 127 && index <= 255)) glyphsMap[glyph] = encodingMap[i] += kCmapGlyphOffset; From 865a6e663af155eeac34ae575559ab1593c62a5b Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Mon, 5 Sep 2011 09:07:18 -0500 Subject: [PATCH 3/3] Fixing #426 comment; add '0' key as a scale reset --- web/images/{list-add.svg => zoom-in.svg} | 0 web/images/{list-remove.svg => zoom-out.svg} | 0 web/viewer.html | 6 ++++-- web/viewer.js | 22 ++++++++++++-------- 4 files changed, 17 insertions(+), 11 deletions(-) rename web/images/{list-add.svg => zoom-in.svg} (100%) rename web/images/{list-remove.svg => zoom-out.svg} (100%) diff --git a/web/images/list-add.svg b/web/images/zoom-in.svg similarity index 100% rename from web/images/list-add.svg rename to web/images/zoom-in.svg diff --git a/web/images/list-remove.svg b/web/images/zoom-out.svg similarity index 100% rename from web/images/list-remove.svg rename to web/images/zoom-out.svg diff --git a/web/viewer.html b/web/viewer.html index a86891796..d37270661 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -34,12 +34,14 @@
+
+