From 47331124f44cebff3eb2425092bb1c852fc7b9c3 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 23 May 2017 12:39:40 -1000 Subject: [PATCH] test09 works --- pitfall/pitfall/path.rkt | 55 +++++++++------- pitfall/pitfall/test/test09.coffee | 5 -- pitfall/pitfall/test/test09.rkt | 5 +- pitfall/pitfall/test/test09c.pdf | 2 +- pitfall/pitfall/test/test09crkt copy.pdf | 64 +++++++++++++++++++ pitfall/pitfall/test/test09crkt.pdf | 64 +++++++++++++++++++ .../test/{test09.pdf => test09rkt copy.pdf} | 36 ++++++++--- pitfall/pitfall/test/test09rkt.pdf | 0 pitfall/pitfall/vector.rkt | 2 +- 9 files changed, 189 insertions(+), 44 deletions(-) create mode 100644 pitfall/pitfall/test/test09crkt copy.pdf create mode 100644 pitfall/pitfall/test/test09crkt.pdf rename pitfall/pitfall/test/{test09.pdf => test09rkt copy.pdf} (65%) delete mode 100644 pitfall/pitfall/test/test09rkt.pdf diff --git a/pitfall/pitfall/path.rkt b/pitfall/pitfall/path.rkt index 0c3dc39b..81c4d1d2 100644 --- a/pitfall/pitfall/path.rkt +++ b/pitfall/pitfall/path.rkt @@ -6,29 +6,36 @@ (apply-commands commands doc)) (define (parse path) - empty) + (for/list ([str (in-list (string-split (string-replace path "," " ") #px"(?=[A-Za-z])"))] + #:when (not (string=? str ""))) + (read (open-input-string (string-append "(" str ")"))))) -(define (apply-commands command doc) - (void)) +(module+ test + (require rackunit) + (check-equal? + (parse "M 0,20 L 100,160 Q 130,200 150,120 C 190,-40 200,200 300,150 L 400,90") + '((M 0 20) + (L 100 160) + (Q 130 200 150 120) + (C 190 -40 200 200 300 150) + (L 400 90)))) -(define parameters - (hash "A" 7 - "a" 7 - "C" 6 - "c" 6 - "H" 1 - "h" 1 - "L" 2 - "l" 2 - "M" 2 - "m" 2 - "Q" 4 - "q" 4 - "S" 4 - "s" 4 - "T" 2 - "t" 2 - "V" 1 - "v" 1 - "Z" 0 - "z" 0)) \ No newline at end of file +(define (apply-commands commands doc) + (for/fold ([cx 0][cy 0][px 0][py 0][sx 0][sy 0]) + ([cmd (in-list commands)]) + (match-define (cons cmd-name cmd-args) cmd) + (let loop ([cmd-name cmd-name][cmd-args cmd-args]) + (case cmd-name + [(M) (send doc moveTo . cmd-args) + (match-define (list a0 a1) cmd-args) + (values a0 a1 #f #f a0 a1)] + [(C) (send doc bezierCurveTo . cmd-args) + (match-define (list a0 a1 a2 a3 a4 a5) cmd-args) + (values a4 a5 a2 a3 sx sy)] + [(L) (send doc lineTo . cmd-args) + (match-define (list a0 a1) cmd-args) + (values a0 a1 #f #f sx sy)] + [(Q) (send doc quadraticCurveTo . cmd-args) + (match-define (list a0 a1 a2 a3) cmd-args) + (values a2 a3 a0 a1 sx sy)] + [else (values cx cy px py sx sy)])))) \ No newline at end of file diff --git a/pitfall/pitfall/test/test09.coffee b/pitfall/pitfall/test/test09.coffee index 05837cb4..054ffac0 100644 --- a/pitfall/pitfall/test/test09.coffee +++ b/pitfall/pitfall/test/test09.coffee @@ -16,11 +16,6 @@ make = (doc) -> doc.end() - -doc = new PDFDocument({compress: no}) -doc.pipe(fs.createWriteStream('test09.pdf')) -make doc - doc = new PDFDocument({compress: yes}) doc.pipe(fs.createWriteStream('test09c.pdf')) make doc \ No newline at end of file diff --git a/pitfall/pitfall/test/test09.rkt b/pitfall/pitfall/test/test09.rkt index e3d7d5fc..8d23ffca 100644 --- a/pitfall/pitfall/test/test09.rkt +++ b/pitfall/pitfall/test/test09.rkt @@ -15,8 +15,5 @@ [path "M 0,20 L 100,160 Q 130,200 150,120 C 190,-40 200,200 300,150 L 400,90"] [stroke])) -(define-runtime-path this "test09rkt.pdf") -(make-doc this #f proc #:test #f) ; node's zlib.deflate makes smaller files, for some reason - (define-runtime-path that "test09crkt.pdf") -(make-doc that #t proc #:test #f) +(make-doc that #t proc) diff --git a/pitfall/pitfall/test/test09c.pdf b/pitfall/pitfall/test/test09c.pdf index ecdee311..6559f581 100644 --- a/pitfall/pitfall/test/test09c.pdf +++ b/pitfall/pitfall/test/test09c.pdf @@ -18,7 +18,7 @@ endobj << /Producer (PDFKit) /Creator (PDFKit) -/CreationDate (D:20170523041028Z) +/CreationDate (D:20170523223743Z) >> endobj 2 0 obj diff --git a/pitfall/pitfall/test/test09crkt copy.pdf b/pitfall/pitfall/test/test09crkt copy.pdf new file mode 100644 index 00000000..c5ddbe95 --- /dev/null +++ b/pitfall/pitfall/test/test09crkt copy.pdf @@ -0,0 +1,64 @@ +%PDF-1.3 +%ÿÿÿÿ +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 +<< +/ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +>> +endobj +3 0 obj +<< +/Length 81 +/Filter /FlateDecode +>> +stream +xœ­LA€0 ºó +>`R¶©Ù;|®îêû¥êLi¡ †g‘iï…c"X‚Š ¶à Õ”|­†½ ꎴWMÔÏhÞz†èiNΗ‹o‹L Ð +endstream +endobj +6 0 obj +<< +/CreationDate (D:19700101000000Z) +/Creator (PITKIT) +/Producer (PITKIT) +>> +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 7 +0000000000 65535 f +0000000479 00000 n +0000000430 00000 n +0000000186 00000 n +0000000119 00000 n +0000000015 00000 n +0000000338 00000 n +trailer +<< +/Info 6 0 R +/Root 2 0 R +/Size 7 +>> +startxref +536 +%%EOF diff --git a/pitfall/pitfall/test/test09crkt.pdf b/pitfall/pitfall/test/test09crkt.pdf new file mode 100644 index 00000000..c5ddbe95 --- /dev/null +++ b/pitfall/pitfall/test/test09crkt.pdf @@ -0,0 +1,64 @@ +%PDF-1.3 +%ÿÿÿÿ +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 +<< +/ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +>> +endobj +3 0 obj +<< +/Length 81 +/Filter /FlateDecode +>> +stream +xœ­LA€0 ºó +>`R¶©Ù;|®îêû¥êLi¡ †g‘iï…c"X‚Š ¶à Õ”|­†½ ꎴWMÔÏhÞz†èiNΗ‹o‹L Ð +endstream +endobj +6 0 obj +<< +/CreationDate (D:19700101000000Z) +/Creator (PITKIT) +/Producer (PITKIT) +>> +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 7 +0000000000 65535 f +0000000479 00000 n +0000000430 00000 n +0000000186 00000 n +0000000119 00000 n +0000000015 00000 n +0000000338 00000 n +trailer +<< +/Info 6 0 R +/Root 2 0 R +/Size 7 +>> +startxref +536 +%%EOF diff --git a/pitfall/pitfall/test/test09.pdf b/pitfall/pitfall/test/test09rkt copy.pdf similarity index 65% rename from pitfall/pitfall/test/test09.pdf rename to pitfall/pitfall/test/test09rkt copy.pdf index 15798190..d349c053 100644 --- a/pitfall/pitfall/test/test09.pdf +++ b/pitfall/pitfall/test/test09rkt copy.pdf @@ -2,11 +2,11 @@ %ÿÿÿÿ 5 0 obj << -/Type /Page /Parent 1 0 R -/MediaBox [0 0 612 792] -/Contents 3 0 R /Resources 4 0 R +/Contents 3 0 R +/MediaBox [0 0 612 792] +/Type /Page >> endobj 4 0 obj @@ -38,21 +38,39 @@ endstream endobj 6 0 obj << -/Producer (PDFKit) -/Creator (PDFKit) -/CreationDate (D:20170523041028Z) +/CreationDate (D:19700101000000Z) +/Creator (PITKIT) +/Producer (PITKIT) >> endobj 2 0 obj << -/Type /Catalog /Pages 1 0 R +/Type /Catalog >> endobj 1 0 obj << -/Type /Pages -/Count 1 /Kids [5 0 R] +/Count 1 +/Type /Pages >> endobj +xref +0 7 +0000000000 65535 f +0000000557 00000 n +0000000508 00000 n +0000000186 00000 n +0000000119 00000 n +0000000015 00000 n +0000000416 00000 n +trailer +<< +/Info 6 0 R +/Root 2 0 R +/Size 7 +>> +startxref +614 +%%EOF diff --git a/pitfall/pitfall/test/test09rkt.pdf b/pitfall/pitfall/test/test09rkt.pdf deleted file mode 100644 index e69de29b..00000000 diff --git a/pitfall/pitfall/vector.rkt b/pitfall/pitfall/vector.rkt index d4c1d70c..4aeccfdf 100644 --- a/pitfall/pitfall/vector.rkt +++ b/pitfall/pitfall/vector.rkt @@ -24,7 +24,7 @@ ellipse circle polygon - ;path + path _windingRule fill stroke