From 107576d634ae39d8ee60ce9dd25e28a9c6112bc0 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Thu, 22 Sep 2011 18:04:50 -0500 Subject: [PATCH 01/10] Removing introduced by the test run DOM elements --- test/driver.js | 13 +++++++++++++ test/test_slave.html | 1 + 2 files changed, 14 insertions(+) diff --git a/test/driver.js b/test/driver.js index 7d6c54509..db6c9b501 100644 --- a/test/driver.js +++ b/test/driver.js @@ -50,7 +50,20 @@ function load() { r.send(null); } +function cleanup() { + var styleSheet = document.styleSheets[0]; + if (styleSheet) { + while (styleSheet.cssRules.length > 0) + styleSheet.deleteRule(0); + } + var guard = document.getElementById('content-end'); + while (document.body.lastChild != guard) + document.body.removeChild(document.body.lastChild); +} + function nextTask() { + cleanup(); + if (currentTaskIdx == manifest.length) { return done(); } diff --git a/test/test_slave.html b/test/test_slave.html index b46e29d6b..57d8d7a83 100644 --- a/test/test_slave.html +++ b/test/test_slave.html @@ -14,6 +14,7 @@

   

Inflight requests:

+
From f3e4cf20cc6d4173ec45669d26f05cf929da10a7 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Thu, 22 Sep 2011 20:18:43 -0500 Subject: [PATCH 02/10] intermediate variable for document.body --- test/driver.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/driver.js b/test/driver.js index db6c9b501..3e3097107 100644 --- a/test/driver.js +++ b/test/driver.js @@ -57,8 +57,9 @@ function cleanup() { styleSheet.deleteRule(0); } var guard = document.getElementById('content-end'); - while (document.body.lastChild != guard) - document.body.removeChild(document.body.lastChild); + var body = document.body; + while (body.lastChild != guard) + body.removeChild(body.lastChild); } function nextTask() { From ba74e56c35b7c74d7e65405dfcae082664962c1b Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Fri, 23 Sep 2011 06:58:54 -0500 Subject: [PATCH 03/10] Using !== for objects comparison --- test/driver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/driver.js b/test/driver.js index 3e3097107..e7c125347 100644 --- a/test/driver.js +++ b/test/driver.js @@ -58,7 +58,7 @@ function cleanup() { } var guard = document.getElementById('content-end'); var body = document.body; - while (body.lastChild != guard) + while (body.lastChild !== guard) body.removeChild(body.lastChild); } From 630c98052e15053e72884a5f5c45f84a496ec3ac Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 23 Sep 2011 14:37:44 -0700 Subject: [PATCH 04/10] Adds support for all the basic graphic state operators --- pdf.js | 74 ++++++++++++++++++++++++++-- test/pdfs/extgstate.pdf | 105 ++++++++++++++++++++++++++++++++++++++++ test/test_manifest.json | 6 +++ 3 files changed, 180 insertions(+), 5 deletions(-) create mode 100644 test/pdfs/extgstate.pdf diff --git a/pdf.js b/pdf.js index 1b80424d6..82a6a9bab 100644 --- a/pdf.js +++ b/pdf.js @@ -4791,7 +4791,65 @@ var CanvasGraphics = (function canvasGraphics() { TODO('set flatness: ' + flatness); }, setGState: function canvasGraphicsSetGState(dictName) { - TODO('set graphics state from dict: ' + dictName); + var extGState = this.xref.fetchIfRef(this.res.get('ExtGState')); + if (IsDict(extGState) && extGState.has(dictName.name)) { + var gsState = this.xref.fetchIfRef(extGState.get(dictName.name)); + var self = this; + gsState.forEach(function(key, value) { + switch (key) { + case 'Type': + break; + case 'LW': + self.setLineWidth(value); + break; + case 'LC': + self.setLineCap(value); + break; + case 'LJ': + self.setLineJoin(value); + break; + case 'ML': + self.setMiterLimit(value); + break; + case 'D': + self.setDash(value[0], value[1]); + break; + case 'RI': + self.setRenderingIntent(value); + break; + case 'FL': + self.setFlatness(value); + break; + case 'Font': + self.setFont(value[0], value[1]); + break; + case 'OP': + case 'op': + case 'OPM': + case 'BG': + case 'BG2': + case 'UCR': + case 'UCR2': + case 'TR': + case 'TR2': + case 'HT': + case 'SM': + case 'SA': + case 'BM': + case 'SMask': + case 'CA': + case 'ca': + case 'AIS': + case 'TK': + TODO('graphic state operator ' + key); + break; + default: + warn('Unknown graphic state operator ' + key); + break; + } + }); + } + }, save: function canvasGraphicsSave() { this.ctx.save(); @@ -4958,11 +5016,17 @@ var CanvasGraphics = (function canvasGraphics() { this.current.leading = -leading; }, setFont: function canvasGraphicsSetFont(fontRef, size) { - var font = this.xref.fetchIfRef(this.res.get('Font')); - if (!IsDict(font)) - return; + var font; + // the tf command uses a name, but graphics state uses a reference + if (IsName(fontRef)) { + font = this.xref.fetchIfRef(this.res.get('Font')); + if (!IsDict(font)) + return; - font = font.get(fontRef.name); + font = font.get(fontRef.name); + } else if (IsRef(fontRef)) { + font = fontRef; + } font = this.xref.fetchIfRef(font); if (!font) error('Referenced font is not found'); diff --git a/test/pdfs/extgstate.pdf b/test/pdfs/extgstate.pdf new file mode 100644 index 000000000..711c45147 --- /dev/null +++ b/test/pdfs/extgstate.pdf @@ -0,0 +1,105 @@ +%PDF-1.4 +%öäüß +1 0 obj +<< +/Type /Catalog +/Version /1.4 +/Pages 2 0 R +>> +endobj +2 0 obj +<< +/Type /Pages +/Kids [3 0 R] +/Count 1 +>> +endobj +3 0 obj +<< +/Type /Page +/MediaBox [0 0 612 792] +/Resources 4 0 R +/Parent 2 0 R +/Contents 5 0 R +>> +endobj +4 0 obj +<< +/ExtGState 6 0 R +/Font 7 0 R +/XObject << +>> +>> +endobj +5 0 obj +<< +/Length 8 0 R +>> +stream +/GS1 gs +/F0 12 Tf +BT +100 700 Td +(I should be courier!) Tj +ET +50 600 m +400 600 l +S + +endstream +endobj +6 0 obj +<< +/GS1 9 0 R +>> +endobj +7 0 obj +<< +/F0 10 0 R +>> +endobj +8 0 obj +82 +endobj +9 0 obj +<< +/Type /ExtGState +/LW 10 +/LC 1 +/LJ 2 +/ML 0.3000000119 +/D [[0.0917000026 183.3300018311] + 0] +/Font [10 0 R 36] +>> +endobj +10 0 obj +<< +/Type /Font +/Subtype /Type1 +/BaseFont /Courier +/Encoding /WinAnsiEncoding +>> +endobj +xref +0 11 +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 +trailer +<< +/Root 1 0 R +/ID [ ] +/Size 11 +>> +startxref +749 +%%EOF diff --git a/test/test_manifest.json b/test/test_manifest.json index edf13b7c5..5c1802deb 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -145,5 +145,11 @@ "link": true, "rounds": 1, "type": "load" + }, + { "id": "extgstate", + "file": "pdfs/extgstate.pdf", + "link": false, + "rounds": 1, + "type": "load" } ] From ced260c2ff6cf7bd54aee14d7c54b98b7dee5ace Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Fri, 23 Sep 2011 18:08:23 -0500 Subject: [PATCH 05/10] Reset invalid media box to letter size. --- pdf.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pdf.js b/pdf.js index 6c66b84c4..77ac4a29b 100644 --- a/pdf.js +++ b/pdf.js @@ -3321,8 +3321,10 @@ var Page = (function pagePage() { }, get mediaBox() { var obj = this.inheritPageProp('MediaBox'); - return shadow(this, 'mediaBox', - ((IsArray(obj) && obj.length == 4) ? obj : null)); + // Reset invalid media box to letter size. + if (!IsArray(obj) || obj.length === 4) + obj = [0, 0, 612, 792]; + return shadow(this, 'mediaBox', obj); }, get view() { var obj = this.inheritPageProp('CropBox'); From 2ad3a8bd1c3e237a310239de168709d8143d5d9c Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Fri, 23 Sep 2011 21:29:01 -0500 Subject: [PATCH 06/10] Fix mediaBox check (regr. of #519) --- pdf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdf.js b/pdf.js index 350aeb085..f7bde09f1 100644 --- a/pdf.js +++ b/pdf.js @@ -3322,7 +3322,7 @@ var Page = (function pagePage() { get mediaBox() { var obj = this.inheritPageProp('MediaBox'); // Reset invalid media box to letter size. - if (!IsArray(obj) || obj.length === 4) + if (!IsArray(obj) || obj.length !== 4) obj = [0, 0, 612, 792]; return shadow(this, 'mediaBox', obj); }, From c20b981f068a53f9e39dc926f6600a32771b1dbe Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sat, 24 Sep 2011 09:14:44 -0500 Subject: [PATCH 07/10] Changing the calculateMD5 function name (ref #523) --- crypto.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crypto.js b/crypto.js index 42eeeda51..4eb6bb581 100644 --- a/crypto.js +++ b/crypto.js @@ -45,7 +45,7 @@ var ARCFourCipher = (function aRCFourCipher() { return constructor; })(); -var md5 = (function md5Md5() { +var calculateMD5 = (function calculateMD5() { var r = new Uint8Array([ 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, @@ -452,11 +452,11 @@ var CipherTransformFactory = (function cipherTransformFactory() { hashData[i++] = 0xFF; hashData[i++] = 0xFF; } - var hash = md5(hashData, 0, i); + var hash = calculateMD5(hashData, 0, i); var keyLengthInBytes = keyLength >> 3; if (revision >= 3) { for (j = 0; j < 50; ++j) { - hash = md5(hash, 0, keyLengthInBytes); + hash = calculateMD5(hash, 0, keyLengthInBytes); } } var encryptionKey = hash.subarray(0, keyLengthInBytes); @@ -469,7 +469,7 @@ var CipherTransformFactory = (function cipherTransformFactory() { for (j = 0, n = fileId.length; j < n; ++j) hashData[i++] = fileId[j]; cipher = new ARCFourCipher(encryptionKey); - var checkData = cipher.encryptBlock(md5(hashData, 0, i)); + var checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i)); n = encryptionKey.length; var derrivedKey = new Uint8Array(n), k; for (j = 1; j <= 19; ++j) { @@ -544,7 +544,7 @@ var CipherTransformFactory = (function cipherTransformFactory() { key[i++] = 0x6C; key[i++] = 0x54; } - var hash = md5(key, 0, i); + var hash = calculateMD5(key, 0, i); return hash.subarray(0, Math.min(encryptionKey.length + 5, 16)); } From 7789af2f386661b81d7945c1547fc26e6ecd9db1 Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Sun, 25 Sep 2011 11:44:29 +0200 Subject: [PATCH 08/10] Add GettingTheCode section to Readme.md --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index c6cf92ede..cbde3e93b 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,32 @@ For an online demo, visit: This demo provides an interactive interface for displaying and browsing PDFs using the pdf.js API. +**Getting the code** + +To get a local copy of the current code, clone it using git: + +```bash + git clone git://github.com/andreasgal/pdf.js.git pdfjs + cd pdfjs +``` + +Next, you need to start a local web server as some browsers don't allow opening +PDF files for a file:// url: + +```bash + make server +``` + +If everything worked out, you can now serve + + http://localhost:8888/web/viewer.html + +You can also view all the test pdf files on the right side serving + + http://localhost:8888/test/pdfs/?frame + + + **Hello world** For a "hello world" example, take a look at: @@ -97,6 +123,7 @@ Join our mailing list: Subscribe either using lists.mozilla.org or Google Groups: https://lists.mozilla.org/listinfo/dev-pdf-js + https://groups.google.com/group/mozilla.dev.pdf-js/topics Talk to us on IRC: From 9aee0a2ad39971e19678aa2d897c1d5565f1c04b Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Sun, 25 Sep 2011 11:48:12 +0200 Subject: [PATCH 09/10] Move Contributing section one level up and add a you can just do tests section --- README.md | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index cbde3e93b..f341733f9 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,20 @@ in a custom project. +## Contributing + +pdf.js is a community-driver project, so contributors are always welcome. +Simply fork our repo and contribute away. A great place to start is our +open issues. For better consistency and long-term stability, please do look around the +code and try to follow our conventions. + +If you __don't want to hack__ on the project or have short spare times, you still +can help! Just open PDFs in the +[online demo](http://andreasgal.github.com/pdf.js/web/viewer.html) and report +any breakage in rendering. + + + ## Running the Tests pdf.js comes with browser-level regression tests that allow one to probe @@ -90,16 +104,6 @@ images. The test type `load` simply tests whether the file loads without raising any errors. -## Contributing - -pdf.js is a community-driver project, so contributors are always welcome. -Simply fork our repo and contribute away. A great place to start is our -open issues. - -For better consistency and long-term stability, please do look around the -code and try to follow our conventions. - - ## Additional resources Our demo site is here: From 4d7ddefc4f0a3c3a3b50a97dc470f9f650fae9bf Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Sun, 25 Sep 2011 12:04:35 +0200 Subject: [PATCH 10/10] Add some external files for reading to the Readme.md --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index f341733f9..f5d4eee9d 100644 --- a/README.md +++ b/README.md @@ -133,3 +133,22 @@ Subscribe either using lists.mozilla.org or Google Groups: Talk to us on IRC: #pdfjs on irc.mozilla.org + +## Additional resources to understand the structure of PDF + +A really basic overview of PDF is described here: + + http://partners.adobe.com/public/developer/en/livecycle/lc_pdf_overview_format.pdf + +A more detailed file example: + + http://gnupdf.org/Introduction_to_PDF + +The PDF specification itself is an ISO and not free available. However, there is +a "PDF Reference" from Adobe: + + http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/pdf_reference_1-7.pdf + +Recommanded chapters to read: "2. Overview", "3.4 File Structure", +"4.1 Graphics Objects" that lists the PDF commands. +