From e3b0af51c52914fb18098d94010840ece24b739d Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 19 May 2017 14:31:35 -0700 Subject: [PATCH] test6 & refac --- pitfall/pitfall/alltest.rkt | 1 + pitfall/pitfall/document.rkt | 26 +-- pitfall/pitfall/test/test.pdf | Bin 645078 -> 645078 bytes pitfall/pitfall/test/test6.coffee | 22 +- pitfall/pitfall/test/test6.pdf | 2 +- pitfall/pitfall/test/test6.rkt | 22 ++ pitfall/pitfall/test/test6c.pdf | Bin 0 -> 3034 bytes pitfall/pitfall/test/test6crkt copy.pdf | Bin 0 -> 3034 bytes pitfall/pitfall/test/test6crkt.pdf | Bin 0 -> 3034 bytes pitfall/pitfall/test/test6rkt copy.pdf | 268 ++++++++++++++++++++++++ pitfall/pitfall/test/test6rkt.pdf | 268 ++++++++++++++++++++++++ 11 files changed, 582 insertions(+), 27 deletions(-) create mode 100644 pitfall/pitfall/test/test6.rkt create mode 100644 pitfall/pitfall/test/test6c.pdf create mode 100644 pitfall/pitfall/test/test6crkt copy.pdf create mode 100644 pitfall/pitfall/test/test6crkt.pdf create mode 100644 pitfall/pitfall/test/test6rkt copy.pdf create mode 100644 pitfall/pitfall/test/test6rkt.pdf diff --git a/pitfall/pitfall/alltest.rkt b/pitfall/pitfall/alltest.rkt index f98f1e48..f4e33726 100644 --- a/pitfall/pitfall/alltest.rkt +++ b/pitfall/pitfall/alltest.rkt @@ -5,5 +5,6 @@ pitfall/test/test2 pitfall/test/test3 pitfall/test/test4 + pitfall/test/test6 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 1cc99125..3c3ae58f 100644 --- a/pitfall/pitfall/document.rkt +++ b/pitfall/pitfall/document.rkt @@ -13,7 +13,6 @@ (field [byte-strings empty] [pdf-version 1.3] [_pageBuffer null] - [_pageBufferStart 0] [_offsets (mhash)] ; The PDF object store [_offset 0] [_root (ref this @@ -52,7 +51,7 @@ end) (for ([(key val) (in-hash (hash-ref options 'info (hash)))]) ; if no 'info key, nothing will be copied from (hash) - (hash-set! info key val)) + (hash-set! info key val)) ;; Write the header (write this (format "%PDF-~a" pdf-version)) ; PDF version @@ -70,11 +69,13 @@ ;; create a page object (set-field! page this (make-object PDFPage this options-arg)) - (push-end-field! _pageBuffer this (· this page)) - ;; add the page to the object store + (push-field! _pageBuffer this (· this page)) + + ;; in Kids, store page dictionaries in correct order + ;; this determines order in document (define pages (· this _root payload Pages payload)) - (hash-update! pages 'Kids (curry cons (· this page dictionary))) - (hash-update! pages 'Count add1) + (hash-update! pages 'Kids (λ (val) (append val (list (· this page dictionary))))) + (hash-set! pages 'Count (length (hash-ref pages 'Kids))) ;; reset x and y coordinates (set-field! x this (· this page margins left)) @@ -83,18 +84,13 @@ ;; the top left rather than the bottom left (set-field! _ctm this default-ctm-value) (send this transform 1 0 0 -1 0 (· this page height)) - - #;(@emit "pageAdded") ; from eventemitter interface this) (define/contract (flushPages this) (->m void?) - ;; this local variable exists so we're future-proof against - ;; reentrant calls to flushPages. (define pb (· this _pageBuffer)) (for-each (λ (p) (· p end)) pb) - (increment-field! _pageBufferStart this (length pb)) (set-field! _pageBuffer this empty)) @@ -144,12 +140,12 @@ (flushPages this) (define _info (ref this)) (for ([(key val) (in-hash (· this info))]) - ;; upgrade string literal to String struct - (hash-set! (· _info payload) key (if (string? val) (String val) val))) + ;; upgrade string literal to String struct + (hash-set! (· _info payload) key (if (string? val) (String val) val))) (· _info end) (for ([font (in-hash-values (· this _fontFamilies))]) - (· font finalize)) + (· font finalize)) (· this _root end) (· this _root payload Pages end) @@ -162,7 +158,7 @@ (this-write (format "0 ~a" (add1 (length this-offsets)))) (this-write "0000000000 65535 f ") (for ([offset (in-list this-offsets)]) - (this-write @string-append{@(~r offset #:min-width 10 #:pad-string "0") 00000 n })) + (this-write @string-append{@(~r offset #:min-width 10 #:pad-string "0") 00000 n })) (this-write "trailer") ;; trailer (this-write (convert (mhash 'Size (add1 (length this-offsets)) diff --git a/pitfall/pitfall/test/test.pdf b/pitfall/pitfall/test/test.pdf index 9d5d36bc20963a4bf257a6d87c3129ac065e60d8..599405b183f1ff34a9d8d42ebca5c8dddd980d94 100644 GIT binary patch delta 84 zcmcb%Uj5p7^$jn+GMg9~Pk#M1gUvf2!qwYja^$zGQ08Wn@7at{cJtC7?Mr_!0x=U1 WGXpUT5VHa?8xXT^U;2Z?@IC;8mnd}r delta 84 zcmcb%Uj5p7^$jn+G8-D1PJaD0gUu_-E8Hu5a^$zGQ08Wn@7at{cJtC7?Mr_!0x=U1 WGXpUT5VHa?8xXT^U;2Z?@IC;OR4By& diff --git a/pitfall/pitfall/test/test6.coffee b/pitfall/pitfall/test/test6.coffee index 89ca4be2..897f77e0 100644 --- a/pitfall/pitfall/test/test6.coffee +++ b/pitfall/pitfall/test/test6.coffee @@ -2,17 +2,17 @@ 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.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() diff --git a/pitfall/pitfall/test/test6.pdf b/pitfall/pitfall/test/test6.pdf index 8452e982..3a20e660 100644 --- a/pitfall/pitfall/test/test6.pdf +++ b/pitfall/pitfall/test/test6.pdf @@ -208,7 +208,7 @@ endobj << /Producer (PDFKit) /Creator (PDFKit) -/CreationDate (D:20170519203858Z) +/CreationDate (D:20170519211427Z) >> endobj 6 0 obj diff --git a/pitfall/pitfall/test/test6.rkt b/pitfall/pitfall/test/test6.rkt new file mode 100644 index 00000000..2605a402 --- /dev/null +++ b/pitfall/pitfall/test/test6.rkt @@ -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) + diff --git a/pitfall/pitfall/test/test6c.pdf b/pitfall/pitfall/test/test6c.pdf new file mode 100644 index 0000000000000000000000000000000000000000..61c602c8a63c6189eb2510cb8a013486e4e7bacb GIT binary patch literal 3034 zcmc&$yKWOf6pd0vBhi_DC@duf%*;N#UKB;bb}X!bFl$FhL@74*#4K`l(RvJqFNmlp zDN-Wp03jbh1qzP{Q6ur}`2x5zYsZ@%cZtImw)XhWz30BpIA5<+FS1J}%KwE2*_h&J z<1SiUM5Ouf9>=8acQ}I2n1=#0_}N3`I&TMlDH`B43P6Dw*l~?@M9NVpz^sSO#LnZr zs2{g@4_gXYT0%T*OaJnH6sI0Xtp*o(jQ|%+ntUKIsck{r((t=H{H{TaD#XB&UX|g( z$m`g#n{s@D1RUj=j1wr1LJbp;?^8(tiaGXtf()2!4fJZ90!z9#u9X6&lf)^_5z_{V zWhY4i(@7%Tu#j7mR>ZfHe6eK-m|5H|j`P z?SMFHd#N!}c2ZyaAbtfzR)Tg9ugN9zuxboevf*KtU`)vsR?YX;Q(WXejgq~_!;ZLv zT}Y!EbOltDRJ%~G3WuDyJk%3V*ex{JF`IOzv|h%37(9EjbFliBZ(sPGn>}wespC<{ z`eN?Wn{)4eeSQFzmN!@X@pzxvyA8_fyUesq$FvPv*lW=3)ww_4<8$B8&)J#9r?~@p z9}J@mg*CkiXU_0thT-$vd!38NvAl7`6i;+FcCd^aKW}s8*kzv28suAARinaVWtE1&tRaB zS&Xs?7?moMIcpR_<}z5J2+DRGqox$93}#TBU(tdQ&e++y9kr+y!=MxzmpKdSuVJ>U z#WhS*=jT!#b6m}z!3tXa7u X)vf3yI_<|oje=phHp=IhZ&cAgnsi&} literal 0 HcmV?d00001 diff --git a/pitfall/pitfall/test/test6crkt copy.pdf b/pitfall/pitfall/test/test6crkt copy.pdf new file mode 100644 index 0000000000000000000000000000000000000000..3ba0511a577b1b8752d0acb54807723623739a75 GIT binary patch literal 3034 zcmc(h%Wl&^6o#v=s*%`*{ji8s7T_6Q6I4|qNh6|y2uUg=sxI7Q8jOOC>|J+GnsZ+IaC z6YOo@LMtmssoOqtIi?^rkkVj**Z12jzdeQtjECRao2W$ZP`cGy66g>}f5sP}(YE+jX8i z+B@2K&34cH%q^bQTf}M*OaG)Dl50zEetf(Kk$PjP_U+*zHTIi?*7vEVYnEoH#5`z{ z-HoMRU;R^G(D%iKmB+awalz3p(WMs?8BRi6kQkI9Vk`VU6=LBLlb9)DkxXnncf`+A zh@a-(W)VZ}jZ&P%m_~&?giJ-&~(3` z|I#p|OH5<7od0Xfc$VV)D);^b&dFzaVm(JqVpPvzGo7-YlTY_-Ig51SJ2>}xewpHY zocoaFtcsQpr#OkT8nuZLXVKB8?Hkf1-fFg-lLyS)IloA8{+v5LfpfAym*EKJj^|e3 zWX8*t3$$nvLg7!oZk$DmjPQKCT(7m(Yb{V|J+GnsZ+IaC z6YOo@LMtmssoOqtIi?^rkkVj**Z12jzdeQtjECRao2W$ZP`cGy66g>}f5sP}(YE+jX8i z+B@2K&34cH%q^bQTf}M*OaG)Dl50zEetf(Kk$PjP_U+*zHTIi?*7vEVYnEoH#5`z{ z-HoMRU;R^G(D%iKmB+awalz3p(WMs?8BRi6kQkI9Vk`VU6=LBLlb9)DkxXnncf`+A zh@a-(W)VZ}jZ&P%m_~&?giJ-&~(3` z|I#p|OH5<7od0Xfc$VV)D);^b&dFzaVm(JqVpPvzGo7-YlTY_-Ig51SJ2>}xewpHY zocoaFtcsQpr#OkT8nuZLXVKB8?Hkf1-fFg-lLyS)IloA8{+v5LfpfAym*EKJj^|e3 zWX8*t3$$nvLg7!oZk$DmjPQKCT(7m(Yb{V> +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 diff --git a/pitfall/pitfall/test/test6rkt.pdf b/pitfall/pitfall/test/test6rkt.pdf new file mode 100644 index 00000000..1822b0ed --- /dev/null +++ b/pitfall/pitfall/test/test6rkt.pdf @@ -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