test6 & refac

main
Matthew Butterick 7 years ago
parent c99c47a2ed
commit e3b0af51c5

@ -5,5 +5,6 @@
pitfall/test/test2 pitfall/test/test2
pitfall/test/test3 pitfall/test/test3
pitfall/test/test4 pitfall/test/test4
pitfall/test/test6
pitfall/page-test pitfall/page-test
(submod pitfall/zlib test))) (submod pitfall/zlib test)))

@ -13,7 +13,6 @@
(field [byte-strings empty] (field [byte-strings empty]
[pdf-version 1.3] [pdf-version 1.3]
[_pageBuffer null] [_pageBuffer null]
[_pageBufferStart 0]
[_offsets (mhash)] ; The PDF object store [_offsets (mhash)] ; The PDF object store
[_offset 0] [_offset 0]
[_root (ref this [_root (ref this
@ -70,11 +69,13 @@
;; create a page object ;; create a page object
(set-field! page this (make-object PDFPage this options-arg)) (set-field! page this (make-object PDFPage this options-arg))
(push-end-field! _pageBuffer this (· this page)) (push-field! _pageBuffer this (· this page))
;; add the page to the object store
;; in Kids, store page dictionaries in correct order
;; this determines order in document
(define pages (· this _root payload Pages payload)) (define pages (· this _root payload Pages payload))
(hash-update! pages 'Kids (curry cons (· this page dictionary))) (hash-update! pages 'Kids (λ (val) (append val (list (· this page dictionary)))))
(hash-update! pages 'Count add1) (hash-set! pages 'Count (length (hash-ref pages 'Kids)))
;; reset x and y coordinates ;; reset x and y coordinates
(set-field! x this (· this page margins left)) (set-field! x this (· this page margins left))
@ -83,18 +84,13 @@
;; the top left rather than the bottom left ;; the top left rather than the bottom left
(set-field! _ctm this default-ctm-value) (set-field! _ctm this default-ctm-value)
(send this transform 1 0 0 -1 0 (· this page height)) (send this transform 1 0 0 -1 0 (· this page height))
#;(@emit "pageAdded") ; from eventemitter interface
this) this)
(define/contract (flushPages this) (define/contract (flushPages this)
(->m void?) (->m void?)
;; this local variable exists so we're future-proof against
;; reentrant calls to flushPages.
(define pb (· this _pageBuffer)) (define pb (· this _pageBuffer))
(for-each (λ (p) (· p end)) pb) (for-each (λ (p) (· p end)) pb)
(increment-field! _pageBufferStart this (length pb))
(set-field! _pageBuffer this empty)) (set-field! _pageBuffer this empty))

Binary file not shown.

@ -208,7 +208,7 @@ endobj
<< <<
/Producer (PDFKit) /Producer (PDFKit)
/Creator (PDFKit) /Creator (PDFKit)
/CreationDate (D:20170519203858Z) /CreationDate (D:20170519211427Z)
>> >>
endobj endobj
6 0 obj 6 0 obj

@ -0,0 +1,22 @@
#lang pitfall/pdftest
(define (proc doc)
(send* doc
[text "Page 1"]
[addPage]
[text "Page 2"]
[addPage]
[text "Page 3"]
[addPage]
[text "Page 4"]
[addPage]
[text "Page 5"]
[addPage]
[text "Page 6"]))
(define-runtime-path this "test6rkt.pdf")
(make-doc this #f proc)
(define-runtime-path that "test6crkt.pdf")
(make-doc that #t proc)

Binary file not shown.

@ -0,0 +1,268 @@
%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
<<
/Font <<
/F1 6 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
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
<<
/Parent 1 0 R
/Resources 8 0 R
/Contents 7 0 R
/MediaBox [0 0 612 792]
/Type /Page
>>
endobj
8 0 obj
<<
/Font <<
/F1 6 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
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
<<
/Parent 1 0 R
/Resources 11 0 R
/Contents 10 0 R
/MediaBox [0 0 612 792]
/Type /Page
>>
endobj
11 0 obj
<<
/Font <<
/F1 6 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
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
<<
/Parent 1 0 R
/Resources 14 0 R
/Contents 13 0 R
/MediaBox [0 0 612 792]
/Type /Page
>>
endobj
14 0 obj
<<
/Font <<
/F1 6 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
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
<<
/Parent 1 0 R
/Resources 17 0 R
/Contents 16 0 R
/MediaBox [0 0 612 792]
/Type /Page
>>
endobj
17 0 obj
<<
/Font <<
/F1 6 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
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
<<
/Parent 1 0 R
/Resources 20 0 R
/Contents 19 0 R
/MediaBox [0 0 612 792]
/Type /Page
>>
endobj
20 0 obj
<<
/Font <<
/F1 6 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
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
<<
/CreationDate (D:19700101000000Z)
/Creator (PITKIT)
/Producer (PITKIT)
>>
endobj
6 0 obj
<<
/BaseFont /Helvetica
/Encoding /WinAnsiEncoding
/Subtype /Type1
/Type /Font
>>
endobj
2 0 obj
<<
/Pages 1 0 R
/Type /Catalog
>>
endobj
1 0 obj
<<
/Kids [5 0 R 9 0 R 12 0 R 15 0 R 18 0 R 21 0 R]
/Count 6
/Type /Pages
>>
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
<<
/Info 22 0 R
/Root 2 0 R
/Size 23
>>
startxref
2465
%%EOF

@ -0,0 +1,268 @@
%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
<<
/Font <<
/F1 6 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
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
<<
/Parent 1 0 R
/Resources 8 0 R
/Contents 7 0 R
/MediaBox [0 0 612 792]
/Type /Page
>>
endobj
8 0 obj
<<
/Font <<
/F1 6 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
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
<<
/Parent 1 0 R
/Resources 11 0 R
/Contents 10 0 R
/MediaBox [0 0 612 792]
/Type /Page
>>
endobj
11 0 obj
<<
/Font <<
/F1 6 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
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
<<
/Parent 1 0 R
/Resources 14 0 R
/Contents 13 0 R
/MediaBox [0 0 612 792]
/Type /Page
>>
endobj
14 0 obj
<<
/Font <<
/F1 6 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
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
<<
/Parent 1 0 R
/Resources 17 0 R
/Contents 16 0 R
/MediaBox [0 0 612 792]
/Type /Page
>>
endobj
17 0 obj
<<
/Font <<
/F1 6 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
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
<<
/Parent 1 0 R
/Resources 20 0 R
/Contents 19 0 R
/MediaBox [0 0 612 792]
/Type /Page
>>
endobj
20 0 obj
<<
/Font <<
/F1 6 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
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
<<
/CreationDate (D:19700101000000Z)
/Creator (PITKIT)
/Producer (PITKIT)
>>
endobj
6 0 obj
<<
/BaseFont /Helvetica
/Encoding /WinAnsiEncoding
/Subtype /Type1
/Type /Font
>>
endobj
2 0 obj
<<
/Pages 1 0 R
/Type /Catalog
>>
endobj
1 0 obj
<<
/Kids [5 0 R 9 0 R 12 0 R 15 0 R 18 0 R 21 0 R]
/Count 6
/Type /Pages
>>
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
<<
/Info 22 0 R
/Root 2 0 R
/Size 23
>>
startxref
2465
%%EOF
Loading…
Cancel
Save