diff --git a/pitfall/pitfall/document.rkt b/pitfall/pitfall/document.rkt index 53a52546..84cd6564 100644 --- a/pitfall/pitfall/document.rkt +++ b/pitfall/pitfall/document.rkt @@ -24,21 +24,20 @@ (init-field [(@options options) (mhasheq)]) (field [@pages null] [@refs null] - [ref-gen (generator () (let loop ([refid 1]) + [@ref-gen (generator () (let loop ([refid 1]) (yield refid) (loop (add1 refid))))] - [(@root _root) (ref (mhasheq 'Type "Catalog" - 'Pages (ref (mhasheq 'Type "Pages" - 'Count 0 - 'Kids empty))))] ; top object + [@root (ref (mhasheq 'Type "Catalog" + 'Pages (ref (mhasheq 'Type "Pages" + 'Count 0 + 'Kids empty))))] ; top object [(@x x) 0] [(@y y) 0] - [(@info info) (mhasheq - 'Producer "PITFALL" - 'Creator "PITFALL" - 'CreationDate (seconds->date (if (test-mode) - 0 - (current-seconds)) #f))]) ; Initialize the metadata + [@info (mhasheq 'Producer "PITFALL" + 'Creator "PITFALL" + 'CreationDate (seconds->date (if (test-mode) + 0 + (current-seconds)) #f))]) ; Initialize the metadata ;; Initialize mixins (send this initColor) @@ -56,8 +55,11 @@ (define/public (page) (first @pages)) + ;; for use by page.rkt rather than invading our fields + (define/public (page-parent) (hash-ref (get-field payload @root) 'Pages)) + (define/public (ref [payload (mhasheq)]) - (define refid (ref-gen)) + (define refid (@ref-gen)) (define new-ref (make-object PDFReference this refid payload)) (set! @refs (cons new-ref @refs)) new-ref) diff --git a/pitfall/pitfall/embedded.rkt b/pitfall/pitfall/embedded.rkt index 218bedb5..e7afeedd 100644 --- a/pitfall/pitfall/embedded.rkt +++ b/pitfall/pitfall/embedded.rkt @@ -92,7 +92,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee (when isCFF (hash-set! (· fontFile payload) 'Subtype "CIDFontType0C")) - (send fontFile end (get-output-bytes (encode-to-port (· this subset)))) + (send* fontFile [write (get-output-bytes (encode-to-port (· this subset)))] [end]) (define familyClass (let ([val (if (has-table? (· this font) 'OS/2) (· (get-OS/2-table (· this font)) sFamilyClass) @@ -199,7 +199,8 @@ end HERE ) - (send cmap end (format unicode-cmap-str (toHex (sub1 (length entries))) (string-join entries " "))) + (send* cmap [write (format unicode-cmap-str (toHex (sub1 (length entries))) (string-join entries " "))] + [end]) cmap) diff --git a/pitfall/pitfall/jpeg.rkt b/pitfall/pitfall/jpeg.rkt index 2564c154..4e19e36d 100644 --- a/pitfall/pitfall/jpeg.rkt +++ b/pitfall/pitfall/jpeg.rkt @@ -71,7 +71,8 @@ (hash-set! (· this obj payload) 'Decode '(1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0))) (port-position (· this data) 0) - (send (· this obj) end (· this data)))) + (send* (· this obj) [write (· this data)] + [end]))) (module+ test (require rackunit) diff --git a/pitfall/pitfall/page.rkt b/pitfall/pitfall/page.rkt index 3ead37c7..199d8cf7 100644 --- a/pitfall/pitfall/page.rkt +++ b/pitfall/pitfall/page.rkt @@ -36,7 +36,7 @@ [dictionary (send document ref (mhash 'Type "Page" - 'Parent (· document _root payload Pages) + 'Parent (send document page-parent) 'MediaBox (list 0 0 width height) 'Contents content 'Resources resources))]) diff --git a/pitfall/pitfall/png.rkt b/pitfall/pitfall/png.rkt index 74cd6d64..5cc1f8e2 100644 --- a/pitfall/pitfall/png.rkt +++ b/pitfall/pitfall/png.rkt @@ -54,7 +54,7 @@ [(hash-has-key? (· this image) 'palette) ;; embed the color palette in the PDF as an object stream (define palette-ref (· this document ref)) - (send palette-ref end (· this image palette)) + (send* palette-ref [write (· this image palette)] [end]) ;; build the color space array for the image (hash-set! (· this object payload) 'Colorspace @@ -90,11 +90,11 @@ 'Filter "FlateDecode" 'ColorSpace "DeviceGray" 'Decode '(0 1)))) - (send sMask end (· this alphaChannel)) + (send* sMask [write (· this alphaChannel)] [end]) (hash-set! (· this obj payload) 'SMask sMask)) ;; embed the actual image data - (send (· this obj) end (· this imgData))) + (send* (· this obj) [write (· this imgData)] [end])) (define (split-alpha-channel this)