test09 works

main
Matthew Butterick 8 years ago
parent 4aec7c7a3b
commit 47331124f4

@ -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))
(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)]))))

@ -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

@ -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)

@ -18,7 +18,7 @@ endobj
<<
/Producer (PDFKit)
/Creator (PDFKit)
/CreationDate (D:20170523041028Z)
/CreationDate (D:20170523223743Z)
>>
endobj
2 0 obj

@ -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
­LA€0 ºó
>`R¶©Ù;|®îêû¥êLi¡ †giï…c"XŠ ¶à Õ”|­†½ ꎴWMÔÏhÞz†èiNΗoL Ð
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

@ -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
­LA€0 ºó
>`R¶©Ù;|®îêû¥êLi¡ †giï…c"XŠ ¶à Õ”|­†½ ꎴWMÔÏhÞz†èiNΗoL Ð
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

@ -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

@ -24,7 +24,7 @@
ellipse
circle
polygon
;path
path
_windingRule
fill
stroke

Loading…
Cancel
Save