don't use end method for writing

main
Matthew Butterick 6 years ago
parent 8902a4721f
commit a70d20e6cd

@ -24,21 +24,20 @@
(init-field [(@options options) (mhasheq)]) (init-field [(@options options) (mhasheq)])
(field [@pages null] (field [@pages null]
[@refs null] [@refs null]
[ref-gen (generator () (let loop ([refid 1]) [@ref-gen (generator () (let loop ([refid 1])
(yield refid) (yield refid)
(loop (add1 refid))))] (loop (add1 refid))))]
[(@root _root) (ref (mhasheq 'Type "Catalog" [@root (ref (mhasheq 'Type "Catalog"
'Pages (ref (mhasheq 'Type "Pages" 'Pages (ref (mhasheq 'Type "Pages"
'Count 0 'Count 0
'Kids empty))))] ; top object 'Kids empty))))] ; top object
[(@x x) 0] [(@x x) 0]
[(@y y) 0] [(@y y) 0]
[(@info info) (mhasheq [@info (mhasheq 'Producer "PITFALL"
'Producer "PITFALL" 'Creator "PITFALL"
'Creator "PITFALL" 'CreationDate (seconds->date (if (test-mode)
'CreationDate (seconds->date (if (test-mode) 0
0 (current-seconds)) #f))]) ; Initialize the metadata
(current-seconds)) #f))]) ; Initialize the metadata
;; Initialize mixins ;; Initialize mixins
(send this initColor) (send this initColor)
@ -56,8 +55,11 @@
(define/public (page) (first @pages)) (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/public (ref [payload (mhasheq)])
(define refid (ref-gen)) (define refid (@ref-gen))
(define new-ref (make-object PDFReference this refid payload)) (define new-ref (make-object PDFReference this refid payload))
(set! @refs (cons new-ref @refs)) (set! @refs (cons new-ref @refs))
new-ref) new-ref)

@ -92,7 +92,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
(when isCFF (when isCFF
(hash-set! (· fontFile payload) 'Subtype "CIDFontType0C")) (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) (define familyClass (let ([val (if (has-table? (· this font) 'OS/2)
(· (get-OS/2-table (· this font)) sFamilyClass) (· (get-OS/2-table (· this font)) sFamilyClass)
@ -199,7 +199,8 @@ end
HERE 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) cmap)

@ -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))) (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) (port-position (· this data) 0)
(send (· this obj) end (· this data)))) (send* (· this obj) [write (· this data)]
[end])))
(module+ test (module+ test
(require rackunit) (require rackunit)

@ -36,7 +36,7 @@
[dictionary [dictionary
(send document ref (send document ref
(mhash 'Type "Page" (mhash 'Type "Page"
'Parent (· document _root payload Pages) 'Parent (send document page-parent)
'MediaBox (list 0 0 width height) 'MediaBox (list 0 0 width height)
'Contents content 'Contents content
'Resources resources))]) 'Resources resources))])

@ -54,7 +54,7 @@
[(hash-has-key? (· this image) 'palette) [(hash-has-key? (· this image) 'palette)
;; embed the color palette in the PDF as an object stream ;; embed the color palette in the PDF as an object stream
(define palette-ref (· this document ref)) (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 ;; build the color space array for the image
(hash-set! (· this object payload) 'Colorspace (hash-set! (· this object payload) 'Colorspace
@ -90,11 +90,11 @@
'Filter "FlateDecode" 'Filter "FlateDecode"
'ColorSpace "DeviceGray" 'ColorSpace "DeviceGray"
'Decode '(0 1)))) 'Decode '(0 1))))
(send sMask end (· this alphaChannel)) (send* sMask [write (· this alphaChannel)] [end])
(hash-set! (· this obj payload) 'SMask sMask)) (hash-set! (· this obj payload) 'SMask sMask))
;; embed the actual image data ;; embed the actual image data
(send (· this obj) end (· this imgData))) (send* (· this obj) [write (· this imgData)] [end]))
(define (split-alpha-channel this) (define (split-alpha-channel this)

Loading…
Cancel
Save