main
Matthew Butterick 6 years ago
parent 1c30d5aee3
commit 3b7180a37e

@ -21,7 +21,7 @@
(define PDFDocument (define PDFDocument
(class (annotation-mixin (image-mixin (text-mixin (fonts-mixin (vector-mixin (color-mixin object%)))))) (class (annotation-mixin (image-mixin (text-mixin (fonts-mixin (vector-mixin (color-mixin object%))))))
(set-current-ref-id! 1) (set-current-ref-id! 1)
(register-ref-listener (λ (ref) (send this log-ref ref))) (register-ref-listener (λ (ref) (send this store-ref ref)))
(super-new) (super-new)
(init-field [(@options options) (mhasheq)]) (init-field [(@options options) (mhasheq)])
@ -52,7 +52,7 @@
(for ([(key val) (in-hash (hash-ref @options 'info (hasheq)))]) (for ([(key val) (in-hash (hash-ref @options 'info (hasheq)))])
(hash-set! @info key val)) (hash-set! @info key val))
(define/public (log-ref ref) (define/public (store-ref ref)
(set! @refs (cons ref @refs))) (set! @refs (cons ref @refs)))
(define/public (page) (first @pages)) (define/public (page) (first @pages))

@ -14,7 +14,7 @@
(abstract embed encode string-width) (abstract embed encode string-width)
(define/public (ref) (define/public (make-font-ref)
(unless @dictionary (unless @dictionary
(set! @dictionary (make-ref))) (set! @dictionary (make-ref)))
@dictionary) @dictionary)

@ -41,7 +41,7 @@
(field [(@offset offset) #f] (field [(@offset offset) #f]
[@port (open-output-bytes)]) [@port (open-output-bytes)])
(for-each (λ (proc) (proc this)) ref-listeners) (for-each (λ (listener-proc) (listener-proc this)) ref-listeners)
(define/public (write x) (define/public (write x)
(write-bytes (to-bytes x) @port)) (write-bytes (to-bytes x) @port))

@ -179,7 +179,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/mixins/text.coffee
(define y (- (· this page height) y-in (* (/ (· this current-font ascender) 1000) (· this current-font-size)))) (define y (- (· this page height) y-in (* (/ (· this current-font ascender) 1000) (· this current-font-size))))
;; add current font to page if necessary ;; add current font to page if necessary
(hash-ref! (· this page fonts) (· this current-font id) (λ () (· this current-font ref))) (hash-ref! (· this page fonts) (· this current-font id) (λ () (· this current-font make-font-ref)))
;; begin the text object ;; begin the text object
(send this addContent "BT") (send this addContent "BT")

Loading…
Cancel
Save