From 78f5ee8299fc4f4b7041f7b43171a971644f7954 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Wed, 11 Jan 2012 22:16:05 +0200 Subject: [PATCH 1/6] Add reference test directories to .gitignore. --- test/.gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/.gitignore b/test/.gitignore index e69de29bb..9fec7b584 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -0,0 +1,3 @@ +ref/ +tmp/ + From 6de2ca568d69e9c59b14bdf6e4dc50bf3d3e3ed3 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sat, 14 Jan 2012 13:47:14 -0600 Subject: [PATCH 2/6] Implements RunLengthDecode filter --- src/parser.js | 3 +++ src/stream.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/parser.js b/src/parser.js index e50b12b9b..047416027 100644 --- a/src/parser.js +++ b/src/parser.js @@ -249,6 +249,9 @@ var Parser = (function ParserClosure() { if (name == 'CCITTFaxDecode' || name == 'CCF') { return new CCITTFaxStream(stream, params); } + if (name == 'RunLengthDecode') { + return new RunLengthStream(stream); + } warn('filter "' + name + '" not supported yet'); return stream; } diff --git a/src/stream.js b/src/stream.js index 69748b5f2..ded6c37ef 100644 --- a/src/stream.js +++ b/src/stream.js @@ -1041,6 +1041,51 @@ var AsciiHexStream = (function AsciiHexStreamClosure() { return AsciiHexStream; })(); +var RunLengthStream = (function RunLengthStreamClosure() { + function RunLengthStream(str) { + this.str = str; + this.dict = str.dict; + + DecodeStream.call(this); + } + + RunLengthStream.prototype = Object.create(DecodeStream.prototype); + + RunLengthStream.prototype.readBlock = function runLengthStreamReadBlock() { + // The repeatHeader has following format. The first byte defines type of run + // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes + // (in addition to the second byte from the header), n = 129 through 255 - + // duplicate the second byte from the header (257 - n) times, n = 128 - end. + var repeatHeader = this.str.getBytes(2); + if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] == 128) { + this.eof = true; + return; + } + + var bufferLength = this.bufferLength; + var n = repeatHeader[0]; + if (n < 128) { + // copy n bytes + var buffer = this.ensureBuffer(bufferLength + n + 1); + buffer[bufferLength++] = repeatHeader[1]; + if (n > 0) { + var source = this.str.getBytes(n); + buffer.set(source, bufferLength); + bufferLength += n; + } + } else { + n = 257 - n; + var b = repeatHeader[1]; + var buffer = this.ensureBuffer(bufferLength + n + 1); + for (var i = 0; i < n; i++) + buffer[bufferLength++] = b; + } + this.bufferLength = bufferLength; + }; + + return RunLengthStream; +})(); + var CCITTFaxStream = (function CCITTFaxStreamClosure() { var ccittEOL = -2; From ce8be2170f6d3a2fd5d05025f7e5f4a0108994cd Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sat, 14 Jan 2012 13:48:34 -0600 Subject: [PATCH 3/6] Adds tests for RunLengthStream --- test/test_manifest.json | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_manifest.json b/test/test_manifest.json index 39586ef3c..ea7eb594e 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -176,7 +176,6 @@ "md5": "eb7b224107205db4fea9f7df0185f77d", "link": true, "rounds": 1, - "skipPages": [12,31], "type": "eq" }, { "id": "fips197", From 2927f5e7bd211ea3e19a7cc7047dd3d12869fa06 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Mon, 16 Jan 2012 14:13:38 -0600 Subject: [PATCH 4/6] Fixes type2 fonts conversion (#940) --- src/fonts.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/fonts.js b/src/fonts.js index 329d7ad77..571788545 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -3324,15 +3324,9 @@ var Type2CFF = (function Type2CFFClosure() { inverseEncoding[encoding[charcode]] = charcode | 0; for (var i = 0, ii = charsets.length; i < ii; i++) { var glyph = charsets[i]; - if (glyph == '.notdef') { - charstrings.push({ - unicode: 0, - code: 0, - gid: i, - glyph: glyph - }); + if (glyph == '.notdef') continue; - } + var code = inverseEncoding[i]; if (!code || isSpecialUnicode(code)) { unassignedUnicodeItems.push(i); From 8aac2256eda12b23c1d5fa237fc496f77ac5af1c Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Tue, 17 Jan 2012 20:50:49 -0800 Subject: [PATCH 5/6] Fix zero width lines. --- src/canvas.js | 19 +++++++++++++++++-- test/pdfs/.gitignore | 1 + test/pdfs/zerowidthline.pdf | Bin 0 -> 6569 bytes test/test_manifest.json | 7 +++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 test/pdfs/zerowidthline.pdf diff --git a/src/canvas.js b/src/canvas.js index 4feac4efe..5ef900861 100644 --- a/src/canvas.js +++ b/src/canvas.js @@ -48,6 +48,7 @@ var CanvasExtraState = (function CanvasExtraStateClosure() { // Note: fill alpha applies to all non-stroking operations this.fillAlpha = 1; this.strokeAlpha = 1; + this.lineWidth = 1; this.old = old; } @@ -329,6 +330,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { // Graphics state setLineWidth: function canvasGraphicsSetLineWidth(width) { + this.current.lineWidth = width; this.ctx.lineWidth = width; }, setLineCap: function canvasGraphicsSetLineCap(style) { @@ -442,6 +444,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { consumePath = typeof consumePath !== 'undefined' ? consumePath : true; var ctx = this.ctx; var strokeColor = this.current.strokeColor; + if (this.current.lineWidth === 0) + ctx.lineWidth = this.getSinglePixelWidth(); // For stroke we want to temporarily change the global alpha to the // stroking alpha. ctx.globalAlpha = this.current.strokeAlpha; @@ -640,7 +644,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { ctx.translate(current.x, current.y); ctx.scale(textHScale, 1); - ctx.lineWidth /= current.textMatrix[0]; if (textSelection) { this.save(); @@ -677,7 +680,15 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { } else { ctx.save(); this.applyTextTransforms(); - ctx.lineWidth /= current.textMatrix[0] * fontMatrix[0]; + + var lineWidth = current.lineWidth; + var scale = Math.abs(current.textMatrix[0] * fontMatrix[0]); + if (scale == 0 || lineWidth == 0) + lineWidth = this.getSinglePixelWidth(); + else + lineWidth /= scale; + + ctx.lineWidth = lineWidth; if (textSelection) text.geom = this.getTextGeometry(); @@ -1142,6 +1153,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { }, restoreFillRule: function canvasGraphicsRestoreFillRule(rule) { this.ctx.mozFillRule = rule; + }, + getSinglePixelWidth: function getSinglePixelWidth(scale) { + var inverse = this.ctx.mozCurrentTransformInverse; + return Math.abs(inverse[0] + inverse[2]); } }; diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 956980782..1aae82800 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -22,3 +22,4 @@ !issue918.pdf !smaskdim.pdf !type4psfunc.pdf +!zerowidthline.pdf diff --git a/test/pdfs/zerowidthline.pdf b/test/pdfs/zerowidthline.pdf new file mode 100644 index 0000000000000000000000000000000000000000..379f18049e93e41061057f67d6fc22c780828d85 GIT binary patch literal 6569 zcmdT}du$v>8DFUgniEx9P}I;uHC*DLfk0=kMR%%2=DkxQ=fsX&B65*0!Ts8U->znR^= z+dDh)sR@77m#lARzQ=su_xrw?`P@~^_lLxABGC2cGbc|4Vn{&7U*loi2>iQYBn(u->-q%Jdq6rVlhbcvOR?&(HMxcY?I(h zp#I2X!zax9?zrI>7nkn*-Rf6fyYJd97oT6fVWl~8{d12WzHu$SZsoSUuYPj;yZiq2 zqwPN^{p<_-_uTp!?L!~y{$To1@zL|wzx2XOPek>dr~kcdS=YCZZTr*F#Mx&)8WnQ6 zTll&sKQr2@TIwjqXSmp-fyfaf8v;VZgBd?4<0-7)}gPT zfARIqWNPe|{nOtZdgI}BzdnBOo-g0?tN7N*Q<0fHe|zow_^umI?4CLLIz2(6JpSy7W_o+WVviB>8AJ6Z3_DQ>NYW33V&J3;?f8p(=@4WKQUmp1T$-`ee z`1unztr+^w?$Tpt6Mave-ud6RpFaNSqc6XBga*a+u^S$m1M^eFLj0YoL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I=+GPmc(Z&JxDF^h1fBDA;c zOz?Ttgx(tCAC#P49qrf;;yLITKvM_SUgjDg~Wg zZ_GBasu7d@9b`n^LBKZXVj6~xXe7ZE1CUn;7RA2jq3xUTE=BZCM6X2jM&!Q`Wji6+ YO1%m@hiNmP#^KK?fv&E#8~Ow90!C8humAu6 literal 0 HcmV?d00001 diff --git a/test/test_manifest.json b/test/test_manifest.json index 6d04597d8..ebbcad7c5 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -417,5 +417,12 @@ "rounds": 1, "link": true, "type": "eq" + }, + { "id": "zerowidthline", + "file": "pdfs/zerowidthline.pdf", + "md5": "295d26e61a85635433f8e4b768953f60", + "rounds": 1, + "link": false, + "type": "eq" } ] From ac5d1a7253adeb32ce1b3a6e7ab61c3e9cf0c59f Mon Sep 17 00:00:00 2001 From: Artur Adib Date: Thu, 19 Jan 2012 09:56:08 -0500 Subject: [PATCH 6/6] Update README.md --- README.md | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 97db68d36..f12fce934 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ -# pdf.js +# PDF.JS - -## Overview - pdf.js is an HTML5 technology experiment that explores building a faithful and efficient Portable Document Format (PDF) renderer without native code assistance. @@ -16,7 +13,7 @@ successful. -## Getting started +# Getting started ### Online demo @@ -29,11 +26,12 @@ using the pdf.js API. ### Extension -An up-to-date Firefox extension is also available: +A Firefox extension is also available: + http://mozilla.github.com/pdf.js/extensions/firefox/pdf.js.xpi -(The above link is updated upon every merge to our master branch). +Note that this extension is self-updating, and by default Firefox will auto-update extensions on a +daily basis (you can change this through the `extensions.update.interval` option in `about:config`). For an experimental Chrome extension, get the code as explained below and issue `make extension`. Then open Chrome with the flag `--enable-experimental-extension-apis`, go to `Tools > Extension` @@ -68,12 +66,12 @@ In order to bundle all `src/` files into a final `pdf.js`, issue: This will generate the file `build/pdf.js` that can be included in your final project. (WARNING: That's a large file! Consider minifying it). -## Learning +# Learning Here are some initial pointers to help contributors get off the ground. Additional resources are available in a separate section below. -#### Hello world +### Hello world For a "hello world" example, take a look at: @@ -82,7 +80,7 @@ For a "hello world" example, take a look at: This example illustrates the bare minimum ingredients for integrating pdf.js in a custom project. -#### Introductory video +### Introductory video Check out the presentation by our contributor Julian Viereck on the inner workings of PDF and pdf.js: @@ -92,7 +90,7 @@ workings of PDF and pdf.js: -## Contributing +# Contributing pdf.js is a community-driven project, so contributors are always welcome. Simply fork our repo and contribute away. Good starting places for picking @@ -122,7 +120,7 @@ You can add your name to it! :) -## Running the tests +# Running the tests pdf.js comes with browser-level regression tests that allow one to probe whether it's able to successfully parse PDFs, as well as compare its output @@ -148,7 +146,7 @@ images. The test type `load` simply tests whether the file loads without raising any errors. -## Running tests through our bot +### Running tests through our bot If you are a reviewer, you can use our remote bot to issue comprehensive tests against reference images before merging pull requests. @@ -158,7 +156,7 @@ See the bot repo for details: + https://github.com/mozilla/pdf.js-bot -## Additional resources +# Additional resources Gallery of user projects and modifications: @@ -188,7 +186,7 @@ Follow us on twitter: @pdfjs -## PDF-related resources +### PDF-related resources A really basic overview of PDF is described here: