From 7870e8aad39311ec9a882c8820348df3520c5ddb Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 20 Dec 2018 22:31:44 -0800 Subject: [PATCH] more params --- pitfall/pitfall/document.rkt | 6 +++--- pitfall/pitfall/page.rkt | 3 +-- pitfall/pitfall/param.rkt | 3 ++- pitfall/pitfall/reference.rkt | 5 ++--- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pitfall/pitfall/document.rkt b/pitfall/pitfall/document.rkt index b86bf448..021abf53 100644 --- a/pitfall/pitfall/document.rkt +++ b/pitfall/pitfall/document.rkt @@ -1,6 +1,5 @@ #lang debug at-exp racket/base (require - "helper.rkt" "param.rkt" "struct.rkt" racket/class @@ -25,7 +24,8 @@ (define mixed% (annotation-mixin (image-mixin (text-mixin (fonts-mixin (color-mixin (vector-mixin object%))))))) (define-subclass mixed% (PDFDocument [options (mhash)]) - (compress-streams? (hash-ref options 'compress #t)) + (current-compress-streams? (hash-ref options 'compress #t)) + (current-auto-first-page (hash-ref options 'autoFirstPage #t)) (current-doc-offset 0) (field [doc-byte-strings empty] @@ -75,7 +75,7 @@ (write this (string-append "%" (list->string (map integer->char (make-list 4 #xFF))))) ; 4 binary chars, as recommended by the spec ;; Add the first page - (when (hash-ref options 'autoFirstPage #t) (addPage this))) + (when (current-auto-first-page) (addPage this))) (define/contract (addPage this [options-arg (· this options)]) diff --git a/pitfall/pitfall/page.rkt b/pitfall/pitfall/page.rkt index eddb3b7c..89c89e37 100644 --- a/pitfall/pitfall/page.rkt +++ b/pitfall/pitfall/page.rkt @@ -79,8 +79,7 @@ (->m number?) (- (· this height) (· this margins bottom))) -(define/contract (write this chunk) - (any/c . ->m . void?) +(define (write this chunk) (send (· this content) write chunk)) ; resume here (define/contract (end this) diff --git a/pitfall/pitfall/param.rkt b/pitfall/pitfall/param.rkt index 6a8e8088..5333f36a 100644 --- a/pitfall/pitfall/param.rkt +++ b/pitfall/pitfall/param.rkt @@ -1,7 +1,8 @@ #lang racket/base (provide (all-defined-out)) (define test-mode (make-parameter #f)) -(define compress-streams? (make-parameter #f)) +(define current-compress-streams? (make-parameter #f)) (define current-pdf-version (make-parameter 1.3)) +(define current-auto-first-page (make-parameter #t)) (define current-doc-offset (make-parameter 'doc-offset-not-initialized)) \ No newline at end of file diff --git a/pitfall/pitfall/reference.rkt b/pitfall/pitfall/reference.rkt index ad3802dc..66e2b6e9 100644 --- a/pitfall/pitfall/reference.rkt +++ b/pitfall/pitfall/reference.rkt @@ -21,8 +21,7 @@ [(? bytes?) x] [(? input-port?) (port->bytes x)] [_ (string->bytes/latin-1 (format "~a\n" x))])) - (write-bytes bstr @portal) - (void)) + (write-bytes bstr @portal)) (define/public (end [chunk #f]) (when chunk @@ -36,7 +35,7 @@ (let ([bstr (get-output-bytes @portal)]) (cond [(zero? (bytes-length bstr)) #false] - [(and (compress-streams?) (not (hash-ref @payload 'Filter #f))) + [(and (current-compress-streams?) (not (hash-ref @payload 'Filter #f))) (hash-set! @payload 'Filter "FlateDecode") (deflate bstr)] [else bstr])))