diff --git a/pitfall/pitfall/alltest.rkt b/pitfall/pitfall/alltest.rkt index 547149e6..f98f1e48 100644 --- a/pitfall/pitfall/alltest.rkt +++ b/pitfall/pitfall/alltest.rkt @@ -5,10 +5,5 @@ pitfall/test/test2 pitfall/test/test3 pitfall/test/test4 - pitfall/test/test0c - pitfall/test/test1c - pitfall/test/test2c - pitfall/test/test3c - pitfall/test/test4c pitfall/page-test (submod pitfall/zlib test))) \ No newline at end of file diff --git a/pitfall/pitfall/document.rkt b/pitfall/pitfall/document.rkt index 9af13d4c..1cc99125 100644 --- a/pitfall/pitfall/document.rkt +++ b/pitfall/pitfall/document.rkt @@ -140,7 +140,7 @@ (define/contract (end this) ; called from source file to finish doc - (->m boolean?) + (->m void?) (flushPages this) (define _info (ref this)) (for ([(key val) (in-hash (· this info))]) @@ -179,8 +179,7 @@ (define this-output-port (· this output-port)) (copy-port (open-input-bytes (apply bytes-append (reverse (· this byte-strings)))) this-output-port) - (close-output-port this-output-port) - #t) + (close-output-port this-output-port)) diff --git a/pitfall/pitfall/pdftest.rkt b/pitfall/pitfall/pdftest.rkt index ac030689..79d67cfd 100644 --- a/pitfall/pitfall/pdftest.rkt +++ b/pitfall/pitfall/pdftest.rkt @@ -1,6 +1,6 @@ #lang pitfall/racket (provide (all-from-out pitfall/racket)) -(provide check-copy-equal? check-pdfkit?) +(provide check-copy-equal? check-pdfkit? make-doc) (test-mode #t) @@ -24,6 +24,14 @@ (check-equal? (bytes-length (file->bytes this)) (bytes-length (file->bytes (this->pdfkit-control this))))) +(define (make-doc ps compress? [proc (λ (doc) doc)]) + (define doc (make-object PDFDocument (hash 'compress compress?))) + (send doc pipe (open-output-file ps #:exists 'replace)) + (proc doc) + (send doc end) + (check-copy-equal? ps) + (check-pdfkit? ps)) + (module reader syntax/module-reader #:language 'pitfall/pdftest diff --git a/pitfall/pitfall/test/test.pdf b/pitfall/pitfall/test/test.pdf index e26206f0..9d5d36bc 100644 Binary files a/pitfall/pitfall/test/test.pdf and b/pitfall/pitfall/test/test.pdf differ diff --git a/pitfall/pitfall/test/test0.coffee b/pitfall/pitfall/test/test0.coffee index 44ac70db..10b13cd7 100644 --- a/pitfall/pitfall/test/test0.coffee +++ b/pitfall/pitfall/test/test0.coffee @@ -4,5 +4,8 @@ fs = require 'fs' # Create a new PDFDocument doc = new PDFDocument({compress: no}) doc.pipe(fs.createWriteStream('test0.pdf')) +doc.end() +doc = new PDFDocument({compress: yes}) +doc.pipe(fs.createWriteStream('test0c.pdf')) doc.end() \ No newline at end of file diff --git a/pitfall/pitfall/test/test0.pdf b/pitfall/pitfall/test/test0.pdf index 50affe87..11e86b83 100644 --- a/pitfall/pitfall/test/test0.pdf +++ b/pitfall/pitfall/test/test0.pdf @@ -27,7 +27,7 @@ endobj << /Producer (PDFKit) /Creator (PDFKit) -/CreationDate (D:20170519174643Z) +/CreationDate (D:20170519204252Z) >> endobj 2 0 obj diff --git a/pitfall/pitfall/test/test0.rkt b/pitfall/pitfall/test/test0.rkt index 9dda3950..76d7b431 100644 --- a/pitfall/pitfall/test/test0.rkt +++ b/pitfall/pitfall/test/test0.rkt @@ -1,11 +1,7 @@ #lang pitfall/pdftest -(define-runtime-path this "test0rkt.pdf") -(check-true - (let () - (define doc (make-object PDFDocument (hash 'compress #f))) - (send doc pipe (open-output-file this #:exists 'replace)) - (send doc end))) +(define-runtime-path this "test0rkt.pdf") +(make-doc this #f) -(check-copy-equal? this) -(check-pdfkit? this) \ No newline at end of file +(define-runtime-path that "test0crkt.pdf") +(make-doc that #t) diff --git a/pitfall/pitfall/test/test0c.coffee b/pitfall/pitfall/test/test0c.coffee deleted file mode 100644 index 8b03a710..00000000 --- a/pitfall/pitfall/test/test0c.coffee +++ /dev/null @@ -1,10 +0,0 @@ -PDFDocument = require 'pdfkit' -fs = require 'fs' - -# Create a new PDFDocument -# uncompressed obj order: 5 4 3 6 2 1 -# compressed obj order: 5 4 6 2 1 3 -doc = new PDFDocument({compress: yes}) -doc.pipe(fs.createWriteStream('test0c.pdf')) - -doc.end() \ No newline at end of file diff --git a/pitfall/pitfall/test/test0c.pdf b/pitfall/pitfall/test/test0c.pdf index ea9f7a6a..836343dd 100644 Binary files a/pitfall/pitfall/test/test0c.pdf and b/pitfall/pitfall/test/test0c.pdf differ diff --git a/pitfall/pitfall/test/test0c.rkt b/pitfall/pitfall/test/test0c.rkt deleted file mode 100644 index 42fcd4ae..00000000 --- a/pitfall/pitfall/test/test0c.rkt +++ /dev/null @@ -1,11 +0,0 @@ -#lang pitfall/pdftest -(define-runtime-path this "test0crkt.pdf") - -(check-true - (let () - (define doc (make-object PDFDocument (hash 'compress #t))) - (send doc pipe (open-output-file this #:exists 'replace)) - (send doc end))) - -(check-copy-equal? this) -(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test1.coffee b/pitfall/pitfall/test/test1.coffee index dd54a40d..1d1e9154 100644 --- a/pitfall/pitfall/test/test1.coffee +++ b/pitfall/pitfall/test/test1.coffee @@ -1,18 +1,24 @@ PDFDocument = require 'pdfkit' fs = require 'fs' -# Create a new PDFDocument +make = (doc) -> + # Draw a triangle and a circle + doc.save() + .moveTo(100, 150) + .lineTo(100, 250) + .lineTo(200, 250) + .fill("#FF3300") + + doc.circle(280, 200, 50) + .fill("#6600FF") + + doc.end() + + doc = new PDFDocument({compress: no}) doc.pipe(fs.createWriteStream('test1.pdf')) +make doc -# Draw a triangle and a circle -doc.save() - .moveTo(100, 150) - .lineTo(100, 250) - .lineTo(200, 250) - .fill("#FF3300") - -doc.circle(280, 200, 50) - .fill("#6600FF") - -doc.end() \ No newline at end of file +doc = new PDFDocument({compress: yes}) +doc.pipe(fs.createWriteStream('test1c.pdf')) +make doc diff --git a/pitfall/pitfall/test/test1.pdf b/pitfall/pitfall/test/test1.pdf index 8496d23c..9e4c9159 100644 --- a/pitfall/pitfall/test/test1.pdf +++ b/pitfall/pitfall/test/test1.pdf @@ -54,7 +54,7 @@ endobj << /Producer (PDFKit) /Creator (PDFKit) -/CreationDate (D:20170519175138Z) +/CreationDate (D:20170519210746Z) >> endobj 2 0 obj diff --git a/pitfall/pitfall/test/test1.rkt b/pitfall/pitfall/test/test1.rkt index 484e0ea7..3b3d4779 100644 --- a/pitfall/pitfall/test/test1.rkt +++ b/pitfall/pitfall/test/test1.rkt @@ -1,23 +1,21 @@ #lang pitfall/pdftest -(define-runtime-path this "test1rkt.pdf") -(check-true - (let ([doc (make-object PDFDocument (hash 'compress #f))]) - (send doc pipe (open-output-file this #:exists 'replace)) +(define (proc doc) + ;; Draw a triangle and a circle + (send* doc + [save] + [moveTo 100 150] + [lineTo 100 250] + [lineTo 200 250] + [fill "#FF3300"]) - ;; Draw a triangle and a circle - (send* doc - [save] - [moveTo 100 150] - [lineTo 100 250] - [lineTo 200 250] - [fill "#FF3300"]) + (send* doc + [circle 280 200 50] + [fill "#6600FF"])) - (send* doc - [circle 280 200 50] - [fill "#6600FF"]) +(define-runtime-path this "test1rkt.pdf") +(make-doc this #f proc) - (send doc end))) +(define-runtime-path that "test1crkt.pdf") +(make-doc that #t proc) -(check-copy-equal? this) -(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test1c.coffee b/pitfall/pitfall/test/test1c.coffee deleted file mode 100644 index 54405e4b..00000000 --- a/pitfall/pitfall/test/test1c.coffee +++ /dev/null @@ -1,18 +0,0 @@ -PDFDocument = require 'pdfkit' -fs = require 'fs' - -# Create a new PDFDocument -doc = new PDFDocument({compress: no}) -doc.pipe(fs.createWriteStream('test1c.pdf')) - -# Draw a triangle and a circle -doc.save() - .moveTo(100, 150) - .lineTo(100, 250) - .lineTo(200, 250) - .fill("#FF3300") - -doc.circle(280, 200, 50) - .fill("#6600FF") - -doc.end() \ No newline at end of file diff --git a/pitfall/pitfall/test/test1c.pdf b/pitfall/pitfall/test/test1c.pdf index e9008427..ffcab08e 100644 --- a/pitfall/pitfall/test/test1c.pdf +++ b/pitfall/pitfall/test/test1c.pdf @@ -27,7 +27,7 @@ endobj << /Producer (PDFKit) /Creator (PDFKit) -/CreationDate (D:20170518193351Z) +/CreationDate (D:20170519210746Z) >> endobj 2 0 obj diff --git a/pitfall/pitfall/test/test1c.rkt b/pitfall/pitfall/test/test1c.rkt deleted file mode 100644 index 0ed8b757..00000000 --- a/pitfall/pitfall/test/test1c.rkt +++ /dev/null @@ -1,23 +0,0 @@ -#lang pitfall/pdftest -(define-runtime-path this "test1crkt.pdf") - -(check-true - (let ([doc (make-object PDFDocument (hash 'compress #t))]) - (send doc pipe (open-output-file this #:exists 'replace)) - - ;; Draw a triangle and a circle - (send* doc - [save] - [moveTo 100 150] - [lineTo 100 250] - [lineTo 200 250] - [fill "#FF3300"]) - - (send* doc - [circle 280 200 50] - [fill "#6600FF"]) - - (send doc end))) - -(check-copy-equal? this) -(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test2.coffee b/pitfall/pitfall/test/test2.coffee index 8e2e5b16..4338b3da 100644 --- a/pitfall/pitfall/test/test2.coffee +++ b/pitfall/pitfall/test/test2.coffee @@ -1,66 +1,74 @@ PDFDocument = require 'pdfkit' fs = require 'fs' -# Create a new PDFDocument -doc = new PDFDocument({compress: no}) -doc.pipe(fs.createWriteStream('test2.pdf')) +make = (doc) -> + doc.moveTo(0, 20) + .lineTo(100, 160) + .quadraticCurveTo(130, 200, 150, 120) + .bezierCurveTo(190, -40, 200, 200, 300, 150) # draw a bezier curve + .lineTo(400, 90) # draw another line + .stroke() # stroke the path + + doc.translate(0, 200) + + doc.polygon [100, 0], [50, 100], [150, 100] + doc.stroke() -doc.moveTo(0, 20) - .lineTo(100, 160) - .quadraticCurveTo(130, 200, 150, 120) - .bezierCurveTo(190, -40, 200, 200, 300, 150) # draw a bezier curve - .lineTo(400, 90) # draw another line - .stroke() # stroke the path + doc.save() + doc.translate(200, 0) + doc.circle(100, 50, 50) + .dash(5, space: 10) + .stroke() + doc.restore() -doc.translate(0, 200) + doc.save() + doc.translate(400, 0) + doc.circle(100, 50, 50) + .lineWidth(3) + .fillOpacity(0.8) + .fillAndStroke("red", "#900") + doc.restore() -doc.polygon [100, 0], [50, 100], [150, 100] -doc.stroke() + doc.translate(0, 200) -doc.save() -doc.translate(200, 0) -doc.circle(100, 50, 50) - .dash(5, space: 10) - .stroke() -doc.restore() -doc.save() -doc.translate(400, 0) -doc.circle(100, 50, 50) - .lineWidth(3) - .fillOpacity(0.8) - .fillAndStroke("red", "#900") -doc.restore() + # these examples are easier to see with a large line width + doc.lineWidth(25) + # line cap settings + doc.lineCap('butt') + .moveTo(50, 20) + .lineTo(100, 20) + .stroke() + doc.lineCap('round') + .moveTo(150, 20) + .lineTo(200, 20) + .stroke() + # square line cap shown with a circle instead of a line so you can see it + doc.lineCap('square') + .moveTo(250, 20) + .circle(275, 30, 15) + .stroke() + # line join settings + doc.lineJoin('miter') + .rect(50, 100, 50, 50) + .stroke() + doc.lineJoin('round') + .rect(150, 100, 50, 50) + .stroke() + doc.lineJoin('bevel') + .rect(250, 100, 50, 50) + .stroke() -doc.translate(0, 200) + doc.end() + + +doc = new PDFDocument({compress: no}) +doc.pipe(fs.createWriteStream('test2.pdf')) +make doc -# these examples are easier to see with a large line width -doc.lineWidth(25) -# line cap settings -doc.lineCap('butt') - .moveTo(50, 20) - .lineTo(100, 20) - .stroke() -doc.lineCap('round') - .moveTo(150, 20) - .lineTo(200, 20) - .stroke() -# square line cap shown with a circle instead of a line so you can see it -doc.lineCap('square') - .moveTo(250, 20) - .circle(275, 30, 15) - .stroke() -# line join settings -doc.lineJoin('miter') - .rect(50, 100, 50, 50) - .stroke() -doc.lineJoin('round') - .rect(150, 100, 50, 50) - .stroke() -doc.lineJoin('bevel') - .rect(250, 100, 50, 50) - .stroke() +doc = new PDFDocument({compress: yes}) +doc.pipe(fs.createWriteStream('test2c.pdf')) +make doc -doc.end() \ No newline at end of file diff --git a/pitfall/pitfall/test/test2.pdf b/pitfall/pitfall/test/test2.pdf index 605820f4..25c859c0 100644 --- a/pitfall/pitfall/test/test2.pdf +++ b/pitfall/pitfall/test/test2.pdf @@ -119,7 +119,7 @@ endobj << /Producer (PDFKit) /Creator (PDFKit) -/CreationDate (D:20170515185139Z) +/CreationDate (D:20170519210839Z) >> endobj 2 0 obj diff --git a/pitfall/pitfall/test/test2.rkt b/pitfall/pitfall/test/test2.rkt index cfd6c4d4..b094e81e 100644 --- a/pitfall/pitfall/test/test2.rkt +++ b/pitfall/pitfall/test/test2.rkt @@ -1,78 +1,78 @@ #lang pitfall/pdftest -(define-runtime-path this "test2rkt.pdf") -(check-true - (let ([doc (make-object PDFDocument (hash 'compress #f))]) - (send doc pipe (open-output-file this #:exists 'replace)) +(define (proc doc) + + ;; curved path as bezier + (send* doc + [moveTo 0 20] + [lineTo 100 160] + [quadraticCurveTo 130 200 150 120] + [bezierCurveTo 190 -40 200 200 300 150] + [lineTo 400 90] + [stroke]) - ;; curved path as bezier - (send* doc - [moveTo 0 20] - [lineTo 100 160] - [quadraticCurveTo 130 200 150 120] - [bezierCurveTo 190 -40 200 200 300 150] - [lineTo 400 90] - [stroke]) + (send* doc [translate 0 200]) - (send* doc [translate 0 200]) + ;; triangle + (send* doc + [polygon '(100 0) '(50 100) '(150 100)] + [stroke]) - ;; triangle - (send* doc - [polygon '(100 0) '(50 100) '(150 100)] - [stroke]) + ;; dashed circle + (send* doc + [save] + [translate 200 0] + [circle 100 50 50] + [dash 5 (hash 'space 10)] + [stroke] + [restore]) - ;; dashed circle - (send* doc - [save] - [translate 200 0] - [circle 100 50 50] - [dash 5 (hash 'space 10)] - [stroke] - [restore]) + ;; filled circle + (send* doc + [save] + [translate 400 0] + [circle 100 50 50] + [lineWidth 3] + [fillOpacity 0.8] + [fillAndStroke "red" "#900"] + [restore]) - ;; filled circle - (send* doc - [save] - [translate 400 0] - [circle 100 50 50] - [lineWidth 3] - [fillOpacity 0.8] - [fillAndStroke "red" "#900"] - [restore]) + (send* doc [translate 0 200]) - (send* doc [translate 0 200]) + ;; these examples are easier to see with a large line width + (send* doc [lineWidth 25]) - ;; these examples are easier to see with a large line width - (send* doc [lineWidth 25]) + ;; line cap settings + (send* doc [lineCap 'butt] + [moveTo 50 20] + [lineTo 100 20] + [stroke] + [lineCap 'round] + [moveTo 150 20] + [lineTo 200 20] + [stroke]) - ;; line cap settings - (send* doc [lineCap 'butt] - [moveTo 50 20] - [lineTo 100 20] - [stroke] - [lineCap 'round] - [moveTo 150 20] - [lineTo 200 20] - [stroke]) + ;; square line cap shown with a circle instead of a line so you can see it + (send* doc [lineCap 'square] + [moveTo 250 20] + [circle 275 30 15] + [stroke]) - ;; square line cap shown with a circle instead of a line so you can see it - (send* doc [lineCap 'square] - [moveTo 250 20] - [circle 275 30 15] - [stroke]) + ;; line join settings + (send* doc [lineJoin 'miter] + [rect 50 100 50 50] + [stroke] + [lineJoin 'round] + [rect 150 100 50 50] + [stroke] + [lineJoin 'bevel] + [rect 250 100 50 50] + [stroke])) - ;; line join settings - (send* doc [lineJoin 'miter] - [rect 50 100 50 50] - [stroke] - [lineJoin 'round] - [rect 150 100 50 50] - [stroke] - [lineJoin 'bevel] - [rect 250 100 50 50] - [stroke]) - (send doc end))) -(check-copy-equal? this) -(check-pdfkit? this) \ No newline at end of file +(define-runtime-path this "test2rkt.pdf") +(make-doc this #f proc) + +(define-runtime-path that "test2crkt.pdf") +(make-doc that #t proc) diff --git a/pitfall/pitfall/test/test2c.coffee b/pitfall/pitfall/test/test2c.coffee deleted file mode 100644 index 85fdf4d9..00000000 --- a/pitfall/pitfall/test/test2c.coffee +++ /dev/null @@ -1,66 +0,0 @@ -PDFDocument = require 'pdfkit' -fs = require 'fs' - -# Create a new PDFDocument -doc = new PDFDocument({compress: yes}) -doc.pipe(fs.createWriteStream('test2c.pdf')) - -doc.moveTo(0, 20) - .lineTo(100, 160) - .quadraticCurveTo(130, 200, 150, 120) - .bezierCurveTo(190, -40, 200, 200, 300, 150) # draw a bezier curve - .lineTo(400, 90) # draw another line - .stroke() # stroke the path - -doc.translate(0, 200) - -doc.polygon [100, 0], [50, 100], [150, 100] -doc.stroke() - -doc.save() -doc.translate(200, 0) -doc.circle(100, 50, 50) - .dash(5, space: 10) - .stroke() -doc.restore() - -doc.save() -doc.translate(400, 0) -doc.circle(100, 50, 50) - .lineWidth(3) - .fillOpacity(0.8) - .fillAndStroke("red", "#900") -doc.restore() - -doc.translate(0, 200) - - -# these examples are easier to see with a large line width -doc.lineWidth(25) -# line cap settings -doc.lineCap('butt') - .moveTo(50, 20) - .lineTo(100, 20) - .stroke() -doc.lineCap('round') - .moveTo(150, 20) - .lineTo(200, 20) - .stroke() -# square line cap shown with a circle instead of a line so you can see it -doc.lineCap('square') - .moveTo(250, 20) - .circle(275, 30, 15) - .stroke() -# line join settings -doc.lineJoin('miter') - .rect(50, 100, 50, 50) - .stroke() -doc.lineJoin('round') - .rect(150, 100, 50, 50) - .stroke() -doc.lineJoin('bevel') - .rect(250, 100, 50, 50) - .stroke() - - -doc.end() \ No newline at end of file diff --git a/pitfall/pitfall/test/test2c.pdf b/pitfall/pitfall/test/test2c.pdf index 8412d1db..4f6cc016 100644 Binary files a/pitfall/pitfall/test/test2c.pdf and b/pitfall/pitfall/test/test2c.pdf differ diff --git a/pitfall/pitfall/test/test2c.rkt b/pitfall/pitfall/test/test2c.rkt deleted file mode 100644 index 48656a70..00000000 --- a/pitfall/pitfall/test/test2c.rkt +++ /dev/null @@ -1,78 +0,0 @@ -#lang pitfall/pdftest -(define-runtime-path this "test2crkt.pdf") - -(check-true - (let ([doc (make-object PDFDocument (hash 'compress #t))]) - (send doc pipe (open-output-file this #:exists 'replace)) - - ;; curved path as bezier - (send* doc - [moveTo 0 20] - [lineTo 100 160] - [quadraticCurveTo 130 200 150 120] - [bezierCurveTo 190 -40 200 200 300 150] - [lineTo 400 90] - [stroke]) - - (send* doc [translate 0 200]) - - ;; triangle - (send* doc - [polygon '(100 0) '(50 100) '(150 100)] - [stroke]) - - ;; dashed circle - (send* doc - [save] - [translate 200 0] - [circle 100 50 50] - [dash 5 (hash 'space 10)] - [stroke] - [restore]) - - ;; filled circle - (send* doc - [save] - [translate 400 0] - [circle 100 50 50] - [lineWidth 3] - [fillOpacity 0.8] - [fillAndStroke "red" "#900"] - [restore]) - - (send* doc [translate 0 200]) - - ;; these examples are easier to see with a large line width - (send* doc [lineWidth 25]) - - ;; line cap settings - (send* doc [lineCap 'butt] - [moveTo 50 20] - [lineTo 100 20] - [stroke] - [lineCap 'round] - [moveTo 150 20] - [lineTo 200 20] - [stroke]) - - ;; square line cap shown with a circle instead of a line so you can see it - (send* doc [lineCap 'square] - [moveTo 250 20] - [circle 275 30 15] - [stroke]) - - ;; line join settings - (send* doc [lineJoin 'miter] - [rect 50 100 50 50] - [stroke] - [lineJoin 'round] - [rect 150 100 50 50] - [stroke] - [lineJoin 'bevel] - [rect 250 100 50 50] - [stroke]) - - (send doc end))) - -(check-copy-equal? this) -(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test3.coffee b/pitfall/pitfall/test/test3.coffee index 83430697..be283857 100644 --- a/pitfall/pitfall/test/test3.coffee +++ b/pitfall/pitfall/test/test3.coffee @@ -1,10 +1,16 @@ PDFDocument = require 'pdfkit' fs = require 'fs' -# Create a new PDFDocument +make = (doc) -> + doc.text("Hello world") + doc.end() + + doc = new PDFDocument({compress: no}) doc.pipe(fs.createWriteStream('test3.pdf')) +make doc -doc.text("Hello world") +doc = new PDFDocument({compress: yes}) +doc.pipe(fs.createWriteStream('test3c.pdf')) +make doc -doc.end() \ No newline at end of file diff --git a/pitfall/pitfall/test/test3.pdf b/pitfall/pitfall/test/test3.pdf index f1b9def6..d0cedb21 100644 --- a/pitfall/pitfall/test/test3.pdf +++ b/pitfall/pitfall/test/test3.pdf @@ -38,7 +38,7 @@ endobj << /Producer (PDFKit) /Creator (PDFKit) -/CreationDate (D:20170517035131Z) +/CreationDate (D:20170519210912Z) >> endobj 6 0 obj diff --git a/pitfall/pitfall/test/test3.rkt b/pitfall/pitfall/test/test3.rkt index ba72a7c3..2e155637 100644 --- a/pitfall/pitfall/test/test3.rkt +++ b/pitfall/pitfall/test/test3.rkt @@ -1,11 +1,11 @@ #lang pitfall/pdftest + +(define (proc doc) + (send doc text "Hello world")) + (define-runtime-path this "test3rkt.pdf") +(make-doc this #f proc) -(check-true - (let ([doc (make-object PDFDocument (hash 'compress #f))]) - (send doc pipe (open-output-file this #:exists 'replace)) - (send doc text "Hello world") - (send doc end))) +(define-runtime-path that "test3crkt.pdf") +(make-doc that #t proc) -(check-copy-equal? this) -(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test3c.coffee b/pitfall/pitfall/test/test3c.coffee deleted file mode 100644 index 3b18b589..00000000 --- a/pitfall/pitfall/test/test3c.coffee +++ /dev/null @@ -1,10 +0,0 @@ -PDFDocument = require 'pdfkit' -fs = require 'fs' - -# Create a new PDFDocument -doc = new PDFDocument({compress: yes}) -doc.pipe(fs.createWriteStream('test3c.pdf')) - -doc.text("Hello world") - -doc.end() \ No newline at end of file diff --git a/pitfall/pitfall/test/test3c.pdf b/pitfall/pitfall/test/test3c.pdf index 4e808226..f31e4c50 100644 Binary files a/pitfall/pitfall/test/test3c.pdf and b/pitfall/pitfall/test/test3c.pdf differ diff --git a/pitfall/pitfall/test/test3c.rkt b/pitfall/pitfall/test/test3c.rkt deleted file mode 100644 index 1366d815..00000000 --- a/pitfall/pitfall/test/test3c.rkt +++ /dev/null @@ -1,11 +0,0 @@ -#lang pitfall/pdftest -(define-runtime-path this "test3crkt.pdf") - -(check-true - (let ([doc (make-object PDFDocument (hash 'compress #t))]) - (send doc pipe (open-output-file this #:exists 'replace)) - (send doc text "Hello world") - (send doc end))) - -(check-copy-equal? this) -(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test4.coffee b/pitfall/pitfall/test/test4.coffee index b04679fa..478f58c9 100644 --- a/pitfall/pitfall/test/test4.coffee +++ b/pitfall/pitfall/test/test4.coffee @@ -1,65 +1,71 @@ PDFDocument = require 'pdfkit' fs = require 'fs' -# Create a new PDFDocument +make = (doc) -> + doc.font("Courier-Bold") + .fontSize(10) + .text("Hello", lineBreak: no) + .translate(-30,30) + .font("Courier-BoldOblique") + .fontSize(11) + .text("Hello", lineBreak: no) + .translate(-30,30) + .font("Courier-Oblique") + .fontSize(12) + .text("Hello", lineBreak: no) + .translate(-30,30) + .font("Courier") + .fontSize(14) + .text("Hello", lineBreak: no) + .translate(-30,30) + .font("Helvetica-Bold") + .fontSize(16) + .text("Hello", lineBreak: no) + .translate(-30,30) + .font("Helvetica-BoldOblique") + .fontSize(18) + .text("Hello", lineBreak: no) + .translate(-30,30) + .font("Helvetica-Oblique") + .fontSize(20) + .text("Hello", lineBreak: no) + .translate(-30,30) + .font("Helvetica") + .fontSize(22) + .text("Hello", lineBreak: no) + .translate(-30,30) + .font("Symbol") + .fontSize(24) + .text("Hello", lineBreak: no) + .translate(-30,30) + .font("Times-Bold") + .fontSize(26) + .text("Hello", lineBreak: no) + .translate(-30,30) + .font("Times-BoldItalic") + .fontSize(28) + .text("Hello", lineBreak: no) + .translate(-30,30) + .font("Times-Italic") + .fontSize(30) + .text("Hello", lineBreak: no) + .translate(-30,30) + .font("Times-Roman") + .fontSize(32) + .text("Hello", lineBreak: no) + .translate(-30,30) + .font("ZapfDingbats") + .fontSize(34) + .text("Hello", lineBreak: no) + + doc.end() + + doc = new PDFDocument({compress: no}) doc.pipe(fs.createWriteStream('test4.pdf')) +make doc +doc = new PDFDocument({compress: yes}) +doc.pipe(fs.createWriteStream('test4c.pdf')) +make doc -doc.font("Courier-Bold") -.fontSize(10) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Courier-BoldOblique") -.fontSize(11) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Courier-Oblique") -.fontSize(12) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Courier") -.fontSize(14) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Helvetica-Bold") -.fontSize(16) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Helvetica-BoldOblique") -.fontSize(18) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Helvetica-Oblique") -.fontSize(20) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Helvetica") -.fontSize(22) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Symbol") -.fontSize(24) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Times-Bold") -.fontSize(26) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Times-BoldItalic") -.fontSize(28) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Times-Italic") -.fontSize(30) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Times-Roman") -.fontSize(32) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("ZapfDingbats") -.fontSize(34) -.text("Hello", lineBreak: no) - -doc.end() \ No newline at end of file diff --git a/pitfall/pitfall/test/test4.rkt b/pitfall/pitfall/test/test4.rkt index 86952713..d0705565 100644 --- a/pitfall/pitfall/test/test4.rkt +++ b/pitfall/pitfall/test/test4.rkt @@ -1,11 +1,7 @@ #lang pitfall/pdftest -(define-runtime-path this "test4rkt.pdf") - -(check-true - (let ([doc (make-object PDFDocument (hash 'compress #f))]) - (send doc pipe (open-output-file this #:exists 'replace)) - (send* doc +(define (proc doc) + (send* doc [font "Courier-Bold"] [fontSize 10] [text "Hello"] @@ -60,10 +56,11 @@ [translate -30 30] [font "ZapfDingbats"] [fontSize 34] - [text "Hello"]) + [text "Hello"])) + +(define-runtime-path this "test4rkt.pdf") +(make-doc this #f proc) - - (send doc end))) +(define-runtime-path that "test4crkt.pdf") +(make-doc that #t proc) -(check-copy-equal? this) -(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test4c.coffee b/pitfall/pitfall/test/test4c.coffee deleted file mode 100644 index 9d2f08a9..00000000 --- a/pitfall/pitfall/test/test4c.coffee +++ /dev/null @@ -1,65 +0,0 @@ -PDFDocument = require 'pdfkit' -fs = require 'fs' - -# Create a new PDFDocument -doc = new PDFDocument({compress: yes}) -doc.pipe(fs.createWriteStream('test4c.pdf')) - - -doc.font("Courier-Bold") -.fontSize(10) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Courier-BoldOblique") -.fontSize(11) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Courier-Oblique") -.fontSize(12) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Courier") -.fontSize(14) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Helvetica-Bold") -.fontSize(16) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Helvetica-BoldOblique") -.fontSize(18) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Helvetica-Oblique") -.fontSize(20) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Helvetica") -.fontSize(22) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Symbol") -.fontSize(24) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Times-Bold") -.fontSize(26) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Times-BoldItalic") -.fontSize(28) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Times-Italic") -.fontSize(30) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("Times-Roman") -.fontSize(32) -.text("Hello", lineBreak: no) -.translate(-30,30) -.font("ZapfDingbats") -.fontSize(34) -.text("Hello", lineBreak: no) - -doc.end() \ No newline at end of file diff --git a/pitfall/pitfall/test/test4c.rkt b/pitfall/pitfall/test/test4c.rkt deleted file mode 100644 index 5267673e..00000000 --- a/pitfall/pitfall/test/test4c.rkt +++ /dev/null @@ -1,69 +0,0 @@ -#lang pitfall/pdftest -(define-runtime-path this "test4crkt.pdf") - -(check-true - (let ([doc (make-object PDFDocument (hash 'compress #t))]) - (send doc pipe (open-output-file this #:exists 'replace)) - - (send* doc - [font "Courier-Bold"] - [fontSize 10] - [text "Hello"] - [translate -30 30] - [font "Courier-BoldOblique"] - [fontSize 11] - [text "Hello"] - [translate -30 30] - [font "Courier-Oblique"] - [fontSize 12] - [text "Hello"] - [translate -30 30] - [font "Courier"] - [fontSize 14] - [text "Hello"] - [translate -30 30] - [font "Helvetica-Bold"] - [fontSize 16] - [text "Hello"] - [translate -30 30] - [font "Helvetica-BoldOblique"] - [fontSize 18] - [text "Hello"] - [translate -30 30] - [font "Helvetica-Oblique"] - [fontSize 20] - [text "Hello"] - [translate -30 30] - [font "Helvetica"] - [fontSize 22] - [text "Hello"] - [translate -30 30] - [font "Symbol"] - [fontSize 24] - [text "Hello"] - [translate -30 30] - [font "Times-Bold"] - [fontSize 26] - [text "Hello"] - [translate -30 30] - [font "Times-BoldItalic"] - [fontSize 28] - [text "Hello"] - [translate -30 30] - [font "Times-Italic"] - [fontSize 30] - [text "Hello"] - [translate -30 30] - [font "Times-Roman"] - [fontSize 32] - [text "Hello"] - [translate -30 30] - [font "ZapfDingbats"] - [fontSize 34] - [text "Hello"]) - - - (send doc end))) - -(check-copy-equal? this) -(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test5.coffee b/pitfall/pitfall/test/test5.coffee index fc8d97cd..494cfea0 100644 --- a/pitfall/pitfall/test/test5.coffee +++ b/pitfall/pitfall/test/test5.coffee @@ -1,16 +1,21 @@ PDFDocument = require 'pdfkit' -tiger = require './assets/tiger' fs = require 'fs' -# Create a new PDFDocument -doc = new PDFDocument -doc.pipe fs.createWriteStream('test5.pdf') +make = (doc) -> + # Set the font, draw some text, and embed an image + doc.font('Times-Italic') + .fontSize(25) + .text('Some text with an embedded font!', 100, 100, lineBreak: no) + .image('assets/test.png', 100, 160, width: 412) + .image('assets/test.jpeg', 190, 400, height: 300) + + doc.end() + +doc = new PDFDocument({compress: no}) +doc.pipe(fs.createWriteStream('test5.pdf')) +make doc + +doc = new PDFDocument({compress: yes}) +doc.pipe(fs.createWriteStream('test5c.pdf')) +make doc -# Set the font, draw some text, and embed an image -doc.font('Times-Italic') - .fontSize(25) - .text('Some text with an embedded font!', 100, 100, lineBreak: no) - .image('assets/test.png', 100, 160, width: 412) - .image('assets/test.jpeg', 190, 400, height: 300) - -doc.end() \ No newline at end of file diff --git a/pitfall/pitfall/test/test5.rkt b/pitfall/pitfall/test/test5.rkt index 803c8349..b25d9076 100644 --- a/pitfall/pitfall/test/test5.rkt +++ b/pitfall/pitfall/test/test5.rkt @@ -1,21 +1,16 @@ #lang pitfall/pdftest -(define-runtime-path this "test5rkt.pdf") - -(check-true - (let ([doc (new PDFDocument)]) - (send doc pipe (open-output-file this #:exists 'replace)) - ;; # Set the font, draw some text, and embed an image -(send* doc +(define (proc doc) + (send* doc [font "Times-Italic"] [fontSize 25] [text "Some text with an embedded font!" 100 100 (hash 'lineBreak #f)] [image "assets/test.png" 100 160 (hash 'width 412)] - [image "assets/test.jpeg" 190 400 (hash 'height 300)] - ) + [image "assets/test.jpeg" 190 400 (hash 'height 300)])) + +(define-runtime-path this "test5rkt.pdf") +(make-doc this #f proc) - - (send doc end))) +(define-runtime-path that "test5crkt.pdf") +(make-doc that #t proc) -;(check-copy-equal? this) -;(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test5c.rkt b/pitfall/pitfall/test/test5c.rkt deleted file mode 100644 index 4eb89ee4..00000000 --- a/pitfall/pitfall/test/test5c.rkt +++ /dev/null @@ -1,21 +0,0 @@ -#lang pitfall/pdftest -(define-runtime-path this "test5crkt.pdf") - -(check-true - (let ([doc (make-object PDFDocument (hash 'compress #t))]) - (send doc pipe (open-output-file this #:exists 'replace)) - - ;; # Set the font, draw some text, and embed an image -(send* doc - [font "Times-Italic"] - [fontSize 25] - [text "Some text with an embedded font!" 100 100 (hash 'lineBreak #f)] - [image "assets/test.png" 100 160 (hash 'width 412)] - [image "assets/test.jpeg" 190 400 (hash 'height 300)] - ) - - - (send doc end))) - -;(check-copy-equal? this) -;(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test6.coffee b/pitfall/pitfall/test/test6.coffee new file mode 100644 index 00000000..89ca4be2 --- /dev/null +++ b/pitfall/pitfall/test/test6.coffee @@ -0,0 +1,26 @@ +PDFDocument = require 'pdfkit' +fs = require 'fs' + +make = (doc) -> + doc.text('Page 1') + .addPage() + .text('Page 2') + .addPage() + .text('Page 3') + .addPage() + .text('Page 4') + .addPage() + .text('Page 5') + .addPage() + .text('Page 6') + + doc.end() + +doc = new PDFDocument({compress: no}) +doc.pipe(fs.createWriteStream('test6.pdf')) +make doc + +doc = new PDFDocument({compress: yes}) +doc.pipe(fs.createWriteStream('test6c.pdf')) +make doc + diff --git a/pitfall/pitfall/test/test6.pdf b/pitfall/pitfall/test/test6.pdf new file mode 100644 index 00000000..8452e982 --- /dev/null +++ b/pitfall/pitfall/test/test6.pdf @@ -0,0 +1,268 @@ +%PDF-1.3 +%ÿÿÿÿ +5 0 obj +<< +/Type /Page +/Parent 1 0 R +/MediaBox [0 0 612 792] +/Contents 3 0 R +/Resources 4 0 R +>> +endobj +4 0 obj +<< +/ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +/Font << +/F1 6 0 R +>> +>> +endobj +3 0 obj +<< +/Length 106 +>> +stream +1 0 0 -1 0 792 cm +q +1 0 0 -1 0 792 cm +BT +1 0 0 1 72 711.384 Tm +/F1 12 Tf +[<50> 40 <6167652031> 0] TJ +ET +Q + +endstream +endobj +9 0 obj +<< +/Type /Page +/Parent 1 0 R +/MediaBox [0 0 612 792] +/Contents 7 0 R +/Resources 8 0 R +>> +endobj +8 0 obj +<< +/ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +/Font << +/F1 6 0 R +>> +>> +endobj +7 0 obj +<< +/Length 106 +>> +stream +1 0 0 -1 0 792 cm +q +1 0 0 -1 0 792 cm +BT +1 0 0 1 72 711.384 Tm +/F1 12 Tf +[<50> 40 <6167652032> 0] TJ +ET +Q + +endstream +endobj +12 0 obj +<< +/Type /Page +/Parent 1 0 R +/MediaBox [0 0 612 792] +/Contents 10 0 R +/Resources 11 0 R +>> +endobj +11 0 obj +<< +/ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +/Font << +/F1 6 0 R +>> +>> +endobj +10 0 obj +<< +/Length 106 +>> +stream +1 0 0 -1 0 792 cm +q +1 0 0 -1 0 792 cm +BT +1 0 0 1 72 711.384 Tm +/F1 12 Tf +[<50> 40 <6167652033> 0] TJ +ET +Q + +endstream +endobj +15 0 obj +<< +/Type /Page +/Parent 1 0 R +/MediaBox [0 0 612 792] +/Contents 13 0 R +/Resources 14 0 R +>> +endobj +14 0 obj +<< +/ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +/Font << +/F1 6 0 R +>> +>> +endobj +13 0 obj +<< +/Length 106 +>> +stream +1 0 0 -1 0 792 cm +q +1 0 0 -1 0 792 cm +BT +1 0 0 1 72 711.384 Tm +/F1 12 Tf +[<50> 40 <6167652034> 0] TJ +ET +Q + +endstream +endobj +18 0 obj +<< +/Type /Page +/Parent 1 0 R +/MediaBox [0 0 612 792] +/Contents 16 0 R +/Resources 17 0 R +>> +endobj +17 0 obj +<< +/ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +/Font << +/F1 6 0 R +>> +>> +endobj +16 0 obj +<< +/Length 106 +>> +stream +1 0 0 -1 0 792 cm +q +1 0 0 -1 0 792 cm +BT +1 0 0 1 72 711.384 Tm +/F1 12 Tf +[<50> 40 <6167652035> 0] TJ +ET +Q + +endstream +endobj +21 0 obj +<< +/Type /Page +/Parent 1 0 R +/MediaBox [0 0 612 792] +/Contents 19 0 R +/Resources 20 0 R +>> +endobj +20 0 obj +<< +/ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +/Font << +/F1 6 0 R +>> +>> +endobj +19 0 obj +<< +/Length 106 +>> +stream +1 0 0 -1 0 792 cm +q +1 0 0 -1 0 792 cm +BT +1 0 0 1 72 711.384 Tm +/F1 12 Tf +[<50> 40 <6167652036> 0] TJ +ET +Q + +endstream +endobj +22 0 obj +<< +/Producer (PDFKit) +/Creator (PDFKit) +/CreationDate (D:20170519203858Z) +>> +endobj +6 0 obj +<< +/Type /Font +/BaseFont /Helvetica +/Subtype /Type1 +/Encoding /WinAnsiEncoding +>> +endobj +2 0 obj +<< +/Type /Catalog +/Pages 1 0 R +>> +endobj +1 0 obj +<< +/Type /Pages +/Count 6 +/Kids [5 0 R 9 0 R 12 0 R 15 0 R 18 0 R 21 0 R] +>> +endobj +xref +0 23 +0000000000 65535 f +0000002374 00000 n +0000002325 00000 n +0000000208 00000 n +0000000119 00000 n +0000000015 00000 n +0000002228 00000 n +0000000558 00000 n +0000000469 00000 n +0000000365 00000 n +0000000912 00000 n +0000000822 00000 n +0000000715 00000 n +0000001267 00000 n +0000001177 00000 n +0000001070 00000 n +0000001622 00000 n +0000001532 00000 n +0000001425 00000 n +0000001977 00000 n +0000001887 00000 n +0000001780 00000 n +0000002135 00000 n +trailer +<< +/Size 23 +/Root 2 0 R +/Info 22 0 R +>> +startxref +2465 +%%EOF