From 5cfdbb7ce5511c667b2e0adedb93349252c749b5 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 20 Dec 2018 16:20:40 -0800 Subject: [PATCH] moves --- pitfall/pitfall/document.rkt | 11 ++++++----- pitfall/pitfall/param.rkt | 3 ++- pitfall/pitfall/reference.rkt | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pitfall/pitfall/document.rkt b/pitfall/pitfall/document.rkt index 18d6c526..376e5ed8 100644 --- a/pitfall/pitfall/document.rkt +++ b/pitfall/pitfall/document.rkt @@ -24,15 +24,16 @@ (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] - [pdf-version 1.3] [_pageBuffer null] [_offsets (mhash)] ; The PDF object store [_ended #f] - [_offset 0] [_root (ref this (mhash 'Type "Catalog" 'Pages (ref this @@ -128,7 +129,7 @@ (newBuffer (string-append x "\n")) x)) (push-field! byte-strings this bstr) - (increment-field! _offset this (buffer-length bstr))) + (current-doc-offset (+ (current-doc-offset) (buffer-length bstr)))) (define/contract (addContent this data) @@ -179,7 +180,7 @@ #;(report* (· this _offsets)) ;; generate xref - (define xref-offset (· this _offset)) + (define xref-offset (current-doc-offset)) (with-method ([this-write (this write)]) (define sorted-offset-records (sort (hash->list (· this _offsets)) < #:key car)) ; sort by refid (define this-offsets (map cdr sorted-offset-records)) @@ -190,7 +191,7 @@ (let ([missing-offsets (for/list ([offset (in-list this-offsets)] [idx (in-list this-idxs)] #:unless (number? offset)) - idx)]) + idx)]) (unless (empty? missing-offsets) (raise-argument-error 'document:end "numerical offsets" missing-offsets))) (for ([offset (in-list this-offsets)] diff --git a/pitfall/pitfall/param.rkt b/pitfall/pitfall/param.rkt index b8f3943a..bb5c7992 100644 --- a/pitfall/pitfall/param.rkt +++ b/pitfall/pitfall/param.rkt @@ -1,4 +1,5 @@ #lang racket/base (provide (all-defined-out)) (define test-mode (make-parameter #f)) -(define compress-streams? (make-parameter #f)) \ No newline at end of file +(define compress-streams? (make-parameter #f)) +(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 c8a0c879..a1010019 100644 --- a/pitfall/pitfall/reference.rkt +++ b/pitfall/pitfall/reference.rkt @@ -53,7 +53,7 @@ (hash-set! (· this payload) 'Length (apply + (map buffer-length bstrs-to-write)))) (define this-doc (· this document)) - (set-field! offset this (· this-doc _offset)) + (set-field! offset this (current-doc-offset)) (with-method ([doc_write (this-doc write)]) (doc_write (format "~a 0 obj" (· this id)))