From 2c9ac3b6dcc8d2913ba923f3bdf1da3fba51829b Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 20 Dec 2018 16:28:12 -0800 Subject: [PATCH] renames --- pitfall/pitfall/document.rkt | 10 ++++------ pitfall/pitfall/param.rkt | 2 ++ pitfall/pitfall/reference.rkt | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pitfall/pitfall/document.rkt b/pitfall/pitfall/document.rkt index 376e5ed8..cd735df0 100644 --- a/pitfall/pitfall/document.rkt +++ b/pitfall/pitfall/document.rkt @@ -24,13 +24,11 @@ (define mixed% (annotation-mixin (image-mixin (text-mixin (fonts-mixin (color-mixin (vector-mixin object%))))))) -(define pdf-version 1.3) - (define-subclass mixed% (PDFDocument [options (mhash)]) (compress-streams? (hash-ref options 'compress #t)) (current-doc-offset 0) - (field [byte-strings empty] + (field [doc-byte-strings empty] [_pageBuffer null] [_offsets (mhash)] ; The PDF object store [_ended #f] @@ -73,7 +71,7 @@ (hash-set! info key val)) ;; Write the header - (write this (format "%PDF-~a" pdf-version)) ; PDF version + (write this (format "%PDF-~a" (current-pdf-version))) ; PDF version (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 @@ -128,7 +126,7 @@ (define bstr (if (not (isBuffer? x)) (newBuffer (string-append x "\n")) x)) - (push-field! byte-strings this bstr) + (push-field! doc-byte-strings this bstr) (current-doc-offset (+ (current-doc-offset) (buffer-length bstr)))) @@ -212,7 +210,7 @@ ;; here we'll do it manually (define this-output-port (· this output-port)) (copy-port (open-input-bytes - (apply bytes-append (reverse (· this byte-strings)))) this-output-port) + (apply bytes-append (reverse (· this doc-byte-strings)))) this-output-port) (close-output-port this-output-port)) diff --git a/pitfall/pitfall/param.rkt b/pitfall/pitfall/param.rkt index bb5c7992..6a8e8088 100644 --- a/pitfall/pitfall/param.rkt +++ b/pitfall/pitfall/param.rkt @@ -2,4 +2,6 @@ (provide (all-defined-out)) (define test-mode (make-parameter #f)) (define compress-streams? (make-parameter #f)) + +(define current-pdf-version (make-parameter 1.3)) (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 a1010019..be6b80d8 100644 --- a/pitfall/pitfall/reference.rkt +++ b/pitfall/pitfall/reference.rkt @@ -14,7 +14,7 @@ (provide PDFReference) (define-subclass object% (PDFReference document id [payload (mhash)]) - (field [byte-strings empty] + (field [ref-byte-strings empty] [offset #f]) (as-methods @@ -25,14 +25,14 @@ (define/contract (write this x) ((or/c string? isBuffer? input-port?) . ->m . void?) - (push-field! byte-strings this + (push-field! ref-byte-strings this (let loop ([x x]) (cond [(isBuffer? x) x] [(input-port? x) (loop (port->bytes x))] [else (bytes-append (newBuffer x) #"\n")])))) -(define got-byte-strings? pair?) +(define got-ref-byte-strings? pair?) (define/contract (end this [chunk #f]) (() ((or/c string? isBuffer? input-port?)) . ->*m . void?) @@ -40,16 +40,16 @@ #;(report* 'end! (· this id)) (define bstrs-to-write - (let ([current-bstrs (reverse (· this byte-strings))]) + (let ([current-bstrs (reverse (· this ref-byte-strings))]) (if (and (compress-streams?) (not (hash-ref (· this payload) 'Filter #f)) - (got-byte-strings? current-bstrs)) + (got-ref-byte-strings? current-bstrs)) (let ([deflated-chunk (deflate (apply bytes-append current-bstrs))]) (hash-set! (· this payload) 'Filter "FlateDecode") (list deflated-chunk)) current-bstrs))) - (when (got-byte-strings? bstrs-to-write) + (when (got-ref-byte-strings? bstrs-to-write) (hash-set! (· this payload) 'Length (apply + (map buffer-length bstrs-to-write)))) (define this-doc (· this document)) @@ -58,7 +58,7 @@ (with-method ([doc_write (this-doc write)]) (doc_write (format "~a 0 obj" (· this id))) (doc_write (convert (· this payload))) - (when (got-byte-strings? bstrs-to-write) + (when (got-ref-byte-strings? bstrs-to-write) (doc_write "stream") (for ([bstr (in-list bstrs-to-write)]) (doc_write bstr))