From c99c47a2edaf3023c2cd4730e53bec2c8c712d27 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 19 May 2017 14:11:56 -0700 Subject: [PATCH] consolidate test files --- pitfall/pitfall/alltest.rkt | 5 - pitfall/pitfall/document.rkt | 5 +- pitfall/pitfall/pdftest.rkt | 10 +- pitfall/pitfall/test/test.pdf | Bin 645078 -> 645078 bytes pitfall/pitfall/test/test0.coffee | 3 + pitfall/pitfall/test/test0.pdf | 2 +- pitfall/pitfall/test/test0.rkt | 12 +- pitfall/pitfall/test/test0c.coffee | 10 -- pitfall/pitfall/test/test0c.pdf | Bin 693 -> 693 bytes pitfall/pitfall/test/test0c.rkt | 11 -- pitfall/pitfall/test/test1.coffee | 30 ++-- pitfall/pitfall/test/test1.pdf | 2 +- pitfall/pitfall/test/test1.rkt | 32 ++-- pitfall/pitfall/test/test1c.coffee | 18 -- pitfall/pitfall/test/test1c.pdf | 2 +- pitfall/pitfall/test/test1c.rkt | 23 --- pitfall/pitfall/test/test2.coffee | 114 ++++++------ pitfall/pitfall/test/test2.pdf | 2 +- pitfall/pitfall/test/test2.rkt | 128 +++++++------- pitfall/pitfall/test/test2c.coffee | 66 ------- pitfall/pitfall/test/test2c.pdf | Bin 1235 -> 1235 bytes pitfall/pitfall/test/test2c.rkt | 78 --------- pitfall/pitfall/test/test3.coffee | 12 +- pitfall/pitfall/test/test3.pdf | 2 +- pitfall/pitfall/test/test3.rkt | 14 +- pitfall/pitfall/test/test3c.coffee | 10 -- pitfall/pitfall/test/test3c.pdf | Bin 914 -> 914 bytes pitfall/pitfall/test/test3c.rkt | 11 -- pitfall/pitfall/test/test4.coffee | 122 ++++++------- pitfall/pitfall/test/test4.rkt | 19 +- pitfall/pitfall/test/test4c.coffee | 65 ------- pitfall/pitfall/test/test4c.rkt | 69 -------- pitfall/pitfall/test/test5.coffee | 29 ++-- pitfall/pitfall/test/test5.rkt | 21 +-- pitfall/pitfall/test/test5c.rkt | 21 --- pitfall/pitfall/test/test6.coffee | 26 +++ pitfall/pitfall/test/test6.pdf | 268 +++++++++++++++++++++++++++++ 37 files changed, 588 insertions(+), 654 deletions(-) delete mode 100644 pitfall/pitfall/test/test0c.coffee delete mode 100644 pitfall/pitfall/test/test0c.rkt delete mode 100644 pitfall/pitfall/test/test1c.coffee delete mode 100644 pitfall/pitfall/test/test1c.rkt delete mode 100644 pitfall/pitfall/test/test2c.coffee delete mode 100644 pitfall/pitfall/test/test2c.rkt delete mode 100644 pitfall/pitfall/test/test3c.coffee delete mode 100644 pitfall/pitfall/test/test3c.rkt delete mode 100644 pitfall/pitfall/test/test4c.coffee delete mode 100644 pitfall/pitfall/test/test4c.rkt delete mode 100644 pitfall/pitfall/test/test5c.rkt create mode 100644 pitfall/pitfall/test/test6.coffee create mode 100644 pitfall/pitfall/test/test6.pdf 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 e26206f092583d73390c35f34133dda22633de4b..9d5d36bc20963a4bf257a6d87c3129ac065e60d8 100644 GIT binary patch delta 88 zcmcb%Uj5p7^$kzHvRfJ%8X6jzPJaD0gUu_-E8Hu5a^$zGQ08Wn@7at{cJtC7?Mr_! a0x=U1GXpUT5VHa?8xXT^U;2Z?@IC> 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 ea9f7a6a2354fcf564edc23e1ba502152fe1dc6a..836343dd8d95ae4af83e0d709c734c955a92a594 100644 GIT binary patch delta 20 bcmdnWx|MYU6C=B&k%5VksnKRm#x;xpIN=2W delta 20 bcmdnWx|MYU6C=BYp{1#zf!StG#x;xpIT{5A 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 8412d1db1aab4a81b85236b17cd3b844480e1e9b..4f6cc016a392c22e1cf49c516c06d7b5ede5aa28 100644 GIT binary patch delta 20 bcmcc2d6{#=E=G1sBSQlVW6RA48HJbuN{t33 delta 20 bcmcc2d6{#=E=G0>BLhQAL!-?H8HJbuN>BzI 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 4e8082263039ed63d2aed748d2960bee77088a95..f31e4c50102cefa7eade9ec5292126e6fd351dc8 100644 GIT binary patch delta 20 bcmbQlK8byU1S7kpk)eU5q0we}#$qM_H7W$N delta 20 bcmbQlK8byU1S7kJk%5t=iQ#5>#$qM_H8lja 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