main
Matthew Butterick 5 years ago
parent cd4c5dca5d
commit 5cfdbb7ce5

@ -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)]

@ -1,4 +1,5 @@
#lang racket/base
(provide (all-defined-out))
(define test-mode (make-parameter #f))
(define compress-streams? (make-parameter #f))
(define compress-streams? (make-parameter #f))
(define current-doc-offset (make-parameter 'doc-offset-not-initialized))

@ -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)))

Loading…
Cancel
Save