From ac0827d1716e78710c57e1f1fd1fa630ddd6738e Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 15 May 2017 11:53:15 -0700 Subject: [PATCH] test2 finished --- pitfall/pitfall/alltest.rkt | 1 + pitfall/pitfall/test/test2.coffee | 4 - pitfall/pitfall/test/test2.pdf | 19 +-- pitfall/pitfall/test/test2.rkt | 15 +-- pitfall/pitfall/test/test2rkt copy.pdf | 158 +++++++++++++++++++++++++ pitfall/pitfall/test/test2rkt.pdf | 41 +++++-- pitfall/pitfall/vector.rkt | 27 ++++- 7 files changed, 226 insertions(+), 39 deletions(-) create mode 100644 pitfall/pitfall/test/test2rkt copy.pdf diff --git a/pitfall/pitfall/alltest.rkt b/pitfall/pitfall/alltest.rkt index a744e552..d446ee67 100644 --- a/pitfall/pitfall/alltest.rkt +++ b/pitfall/pitfall/alltest.rkt @@ -2,4 +2,5 @@ (module+ test (require pitfall/test/test0 pitfall/test/test1 + pitfall/test/test2 pitfall/page-test)) \ No newline at end of file diff --git a/pitfall/pitfall/test/test2.coffee b/pitfall/pitfall/test/test2.coffee index b30d8338..8e2e5b16 100644 --- a/pitfall/pitfall/test/test2.coffee +++ b/pitfall/pitfall/test/test2.coffee @@ -14,10 +14,6 @@ doc.moveTo(0, 20) doc.translate(0, 200) -doc.path('M 0,20 L 100,160 Q 130,200 150,120 C 190,-40 200,200 300,150 L 400,90').stroke() - -doc.translate(0, 200) - doc.polygon [100, 0], [50, 100], [150, 100] doc.stroke() diff --git a/pitfall/pitfall/test/test2.pdf b/pitfall/pitfall/test/test2.pdf index 724076a9..605820f4 100644 --- a/pitfall/pitfall/test/test2.pdf +++ b/pitfall/pitfall/test/test2.pdf @@ -39,7 +39,7 @@ endobj endobj 3 0 obj << -/Length 979 +/Length 890 >> stream 1 0 0 -1 0 792 cm @@ -50,13 +50,6 @@ stream 400 90 l S 1 0 0 1 0 200 cm -0 20 m -100 160 l -130 200 150 120 v -190 -40 200 200 300 150 c -400 90 l -S -1 0 0 1 0 200 cm 100 0 m 50 100 l 150 100 l @@ -126,7 +119,7 @@ endobj << /Producer (PDFKit) /Creator (PDFKit) -/CreationDate (D:20170515173303Z) +/CreationDate (D:20170515185139Z) >> endobj 2 0 obj @@ -145,15 +138,15 @@ endobj xref 0 10 0000000000 65535 f -0000001541 00000 n -0000001492 00000 n +0000001452 00000 n +0000001403 00000 n 0000000370 00000 n 0000000253 00000 n 0000000149 00000 n 0000000015 00000 n 0000000061 00000 n 0000000105 00000 n -0000001400 00000 n +0000001311 00000 n trailer << /Size 10 @@ -161,5 +154,5 @@ trailer /Info 9 0 R >> startxref -1598 +1509 %%EOF diff --git a/pitfall/pitfall/test/test2.rkt b/pitfall/pitfall/test/test2.rkt index fe6ebf64..50dab79b 100644 --- a/pitfall/pitfall/test/test2.rkt +++ b/pitfall/pitfall/test/test2.rkt @@ -16,16 +16,6 @@ (send* doc [translate 0 200]) -#| - ;; curved path as svg path - (send* doc - [path "M 0,20 L 100,160 Q 130,200 150,120 C 190,-40 200,200 300,150 L 400,90"] - [stroke]) -|# - - (send* doc - [translate 0 200]) - ;; triangle (send* doc [polygon '(100 0) '(50 100) '(150 100)] @@ -50,8 +40,6 @@ [fillAndStroke "red" "#900"] [restore]) - #| - (send* doc [translate 0 200]) ;; these examples are easier to see with a large line width @@ -83,8 +71,7 @@ [lineJoin 'bevel] [rect 250 100 50 50] [stroke]) - |# (send doc end))) -;(check-copy-equal? this) \ No newline at end of file +(check-copy-equal? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test2rkt copy.pdf b/pitfall/pitfall/test/test2rkt copy.pdf new file mode 100644 index 00000000..eaf0bac0 --- /dev/null +++ b/pitfall/pitfall/test/test2rkt copy.pdf @@ -0,0 +1,158 @@ +%PDF-1.3 +%ÿÿÿÿ +6 0 obj +<< +/ca 0.8 +/Type /ExtGState +>> +endobj +7 0 obj +<< +/ca 1 +/Type /ExtGState +>> +endobj +8 0 obj +<< +/CA 1 +/Type /ExtGState +>> +endobj +5 0 obj +<< +/Parent 1 0 R +/Resources 4 0 R +/Contents 3 0 R +/MediaBox [0 0 612 792] +/Type /Page +>> +endobj +4 0 obj +<< +/ExtGState << +/Gs2 7 0 R +/Gs1 6 0 R +/Gs3 8 0 R +>> +/ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +>> +endobj +3 0 obj +<< +/Length 890 +>> +stream +1 0 0 -1 0 792 cm +0 20 m +100 160 l +130 200 150 120 v +190 -40 200 200 300 150 c +400 90 l +S +1 0 0 1 0 200 cm +100 0 m +50 100 l +150 100 l +h +S +q +1 0 0 1 200 0 cm +50 50 m +50 22.385763 72.385763 0 100 0 c +127.614237 0 150 22.385763 150 50 c +150 77.614237 127.614237 100 100 100 c +72.385763 100 50 77.614237 50 50 c +h +[5 10] 0 d +S +Q +q +1 0 0 1 400 0 cm +50 50 m +50 22.385763 72.385763 0 100 0 c +127.614237 0 150 22.385763 150 50 c +150 77.614237 127.614237 100 100 100 c +72.385763 100 50 77.614237 50 50 c +h +3 w +/Gs1 gs +/DeviceRGB cs +1 0 0 scn +/Gs2 gs +/DeviceRGB CS +0.6 0 0 SCN +/Gs3 gs +B +Q +1 0 0 1 0 200 cm +25 w +0 J +50 20 m +100 20 l +S +1 J +150 20 m +200 20 l +S +2 J +250 20 m +260 30 m +260 21.715729 266.715729 15 275 15 c +283.284271 15 290 21.715729 290 30 c +290 38.284271 283.284271 45 275 45 c +266.715729 45 260 38.284271 260 30 c +h +S +0 j +50 100 50 50 re +S +1 j +150 100 50 50 re +S +2 j +250 100 50 50 re +S + +endstream +endobj +9 0 obj +<< +/CreationDate (D:19700101000000Z) +/Creator (PitfallKit) +/Producer (PitfallKit) +>> +endobj +2 0 obj +<< +/Pages 1 0 R +/Type /Catalog +>> +endobj +1 0 obj +<< +/Kids [5 0 R] +/Count 1 +/Type /Pages +>> +endobj +xref +0 10 +0000000000 65535 f +0000001460 00000 n +0000001411 00000 n +0000000370 00000 n +0000000253 00000 n +0000000149 00000 n +0000000015 00000 n +0000000061 00000 n +0000000105 00000 n +0000001311 00000 n +trailer +<< +/Info 9 0 R +/Root 2 0 R +/Size 10 +>> +startxref +1517 +%%EOF diff --git a/pitfall/pitfall/test/test2rkt.pdf b/pitfall/pitfall/test/test2rkt.pdf index 711ed54c..eaf0bac0 100644 --- a/pitfall/pitfall/test/test2rkt.pdf +++ b/pitfall/pitfall/test/test2rkt.pdf @@ -39,7 +39,7 @@ endobj endobj 3 0 obj << -/Length 595 +/Length 890 >> stream 1 0 0 -1 0 792 cm @@ -50,7 +50,6 @@ stream 400 90 l S 1 0 0 1 0 200 cm -1 0 0 1 0 200 cm 100 0 m 50 100 l 150 100 l @@ -75,7 +74,7 @@ q 150 77.614237 127.614237 100 100 100 c 72.385763 100 50 77.614237 50 50 c h -#3 +3 w /Gs1 gs /DeviceRGB cs 1 0 0 scn @@ -85,6 +84,34 @@ h /Gs3 gs B Q +1 0 0 1 0 200 cm +25 w +0 J +50 20 m +100 20 l +S +1 J +150 20 m +200 20 l +S +2 J +250 20 m +260 30 m +260 21.715729 266.715729 15 275 15 c +283.284271 15 290 21.715729 290 30 c +290 38.284271 283.284271 45 275 45 c +266.715729 45 260 38.284271 260 30 c +h +S +0 j +50 100 50 50 re +S +1 j +150 100 50 50 re +S +2 j +250 100 50 50 re +S endstream endobj @@ -111,15 +138,15 @@ endobj xref 0 10 0000000000 65535 f -0000001165 00000 n -0000001116 00000 n +0000001460 00000 n +0000001411 00000 n 0000000370 00000 n 0000000253 00000 n 0000000149 00000 n 0000000015 00000 n 0000000061 00000 n 0000000105 00000 n -0000001016 00000 n +0000001311 00000 n trailer << /Info 9 0 R @@ -127,5 +154,5 @@ trailer /Size 10 >> startxref -1222 +1517 %%EOF diff --git a/pitfall/pitfall/vector.rkt b/pitfall/pitfall/vector.rkt index 5d29d29d..49d67ddc 100644 --- a/pitfall/pitfall/vector.rkt +++ b/pitfall/pitfall/vector.rkt @@ -12,12 +12,15 @@ save restore closePath + lineCap + lineJoin lineWidth dash moveTo lineTo bezierCurveTo quadraticCurveTo + rect ellipse circle polygon @@ -58,10 +61,27 @@ (->m object?) (send this addContent "h")) +(define/contract (lineCap this [c #f]) + ((or/c 'butt 'round 'square #f) . ->m . object?) + (define cap-styles (hasheq 'butt 0 'round 1 'square 2)) + (send this addContent + (format "~a J" (if (symbol? c) + (hash-ref cap-styles c) + "")))) + + +(define/contract (lineJoin this [j #f]) + ((or/c 'miter 'round 'bevel #f) . ->m . object?) + (define cap-styles (hasheq 'miter 0 'round 1 'bevel 2)) + (send this addContent + (format "~a j" (if (symbol? j) + (hash-ref cap-styles j) + "")))) + (define/contract (lineWidth this w) (number? . ->m . object?) - (send this addContent (format "#~a" (number w)))) + (send this addContent (format "~a w" (number w)))) (define/contract (dash this length [options (mhash)]) @@ -101,6 +121,11 @@ (send this addContent (format "~a v" (string-join (map number (list cpx cpy x y)) " ")))) +(define/contract (rect this x y w h) + (number? number? number? number? . ->m . object?) + (send this addContent (format "~a re" (string-join (map number (list x y w h)) " ")))) + + (define/contract (ellipse this x y r1 [r2 r1]) ((number? number? number?) (number?) . ->*m . object?) ;; based on http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas/2173084#2173084