From f11dbfb02a9114faea10995063b4a9b5b28b3021 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 21 Dec 2018 08:17:09 -0800 Subject: [PATCH] portier --- pitfall/pitfall/document.rkt | 19 ++++--------------- pitfall/pitfall/pdftest.rkt | 12 +++++++----- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/pitfall/pitfall/document.rkt b/pitfall/pitfall/document.rkt index 322556a0..dca71eff 100644 --- a/pitfall/pitfall/document.rkt +++ b/pitfall/pitfall/document.rkt @@ -30,8 +30,7 @@ (current-auto-first-page (hash-ref options 'autoFirstPage #t)) (current-doc-offset 0) - (field [doc-portal (open-output-bytes)] - [_pageBuffer null] + (field [_pageBuffer null] [_offsets (mhasheqv)] ; The PDF object store [_ended #f] [ref-gen (generator () @@ -52,7 +51,7 @@ 'CreationDate (seconds->date (if (test-mode) 0 (current-seconds)) #f))] ; Initialize the metadata - [output-port #f]) ; for `pipe` + ) ; for `pipe` ;; Initialize mixins @@ -70,7 +69,7 @@ (define bstr (if (not (bytes? x)) (string->bytes/latin-1 (string-append x "\n")) x)) - (write-bytes bstr doc-portal) + (write-bytes bstr) (current-doc-offset (+ (current-doc-offset) (bytes-length bstr)))) (define/public (addPage [options-arg options]) @@ -107,9 +106,6 @@ (define/public (_refEnd aref) (hash-set! _offsets (· aref id) (· aref offset))) - - (define/public (pipe port) - (set! output-port port)) (define/public (end) ; called from source file to finish doc (flushPages) @@ -150,14 +146,7 @@ 'Info _info))) (write "startxref") (write (number xref-offset)) - (write "%%EOF") - - ;; end the stream - ;; in node you (@push null) which signals to the stream - ;; to copy to its output port - ;; here we'll do it manually - (write-bytes (get-output-bytes doc-portal) output-port) - (close-output-port output-port)) + (write "%%EOF")) ; if no 'info key, nothing will be copied from (hash) (for ([(key val) (in-hash (hash-ref options 'info (hash)))]) diff --git a/pitfall/pitfall/pdftest.rkt b/pitfall/pitfall/pdftest.rkt index 62b177ba..ad19c189 100644 --- a/pitfall/pitfall/pdftest.rkt +++ b/pitfall/pitfall/pdftest.rkt @@ -27,7 +27,7 @@ (define-macro (check-copy-equal? THIS) (syntax/loc caller-stx (check-true (for/and ([b1 (in-input-port-bytes (open-input-file THIS))] [b2 (in-input-port-bytes (open-input-file (this->control THIS)))]) - (equal? b1 b2))))) + (equal? b1 b2))))) (define-syntax-rule (check-pdfkit? this) @@ -36,10 +36,12 @@ (define (make-doc ps [compress? #false] [proc (λ (doc) doc)] #:test [test? #t] #:pdfkit [pdfkit? #t]) (time (let () - (define doc (make-object PDFDocument (hash 'compress compress?))) - (send doc pipe (open-output-file ps #:exists 'replace)) - (proc doc) - (send doc end))) + (define f (open-output-file ps #:exists 'replace)) + (parameterize ([current-output-port f]) + (define doc (make-object PDFDocument (hash 'compress compress?))) + (proc doc) + (send doc end)) + (close-output-port f))) (when test? (check-pdfs-equal? ps (this->control ps)) (when pdfkit?