ref → make-ref

main
Matthew Butterick 6 years ago
parent 9195f4218c
commit cc3960a806

@ -36,7 +36,7 @@
(for ([(k v) (in-hash options)]) (for ([(k v) (in-hash options)])
(hash-set! options (string->symbol (string-titlecase (symbol->string k))) v)) (hash-set! options (string->symbol (string-titlecase (symbol->string k))) v))
(define annots-ref (send this ref options)) (define annots-ref (send this make-ref options))
(send (· this page) annotations annots-ref) (send (· this page) annotations annots-ref)
(· annots-ref end) (· annots-ref end)
this) this)
@ -46,7 +46,7 @@
((number? number? number? number? string?) (hash?) . ->*m . object?) ((number? number? number? number? string?) (hash?) . ->*m . object?)
(hash-set*! options (hash-set*! options
'Subtype "Link" 'Subtype "Link"
'A (send this ref (mhash 'S "URI" 'A (send this make-ref (mhash 'S "URI"
'URI (String url)))) 'URI (String url))))
(send (· options A) end) (send (· options A) end)
(send this annotate x y w h options)) (send this annotate x y w h options))

@ -104,7 +104,7 @@
(hash-set! dictionary 'ca fill-opacity)) (hash-set! dictionary 'ca fill-opacity))
(when stroke-opacity (when stroke-opacity
(hash-set! dictionary 'CA stroke-opacity)) (hash-set! dictionary 'CA stroke-opacity))
(define ref-dict (send this ref dictionary)) (define ref-dict (send this make-ref dictionary))
(send ref-dict end) (send ref-dict end)
(set! @opacity-count (add1 @opacity-count)) (set! @opacity-count (add1 @opacity-count))
(list ref-dict (format "Gs~a" @opacity-count))))) (list ref-dict (format "Gs~a" @opacity-count)))))

@ -28,8 +28,8 @@
[@ref-gen (generator () (let loop ([refid 1]) [@ref-gen (generator () (let loop ([refid 1])
(yield refid) (yield refid)
(loop (add1 refid))))] (loop (add1 refid))))]
[@root (ref (mhasheq 'Type "Catalog" [@root (make-ref (mhasheq 'Type "Catalog"
'Pages (ref (mhasheq 'Type "Pages"))))] 'Pages (make-ref (mhasheq 'Type "Pages"))))]
[(@x x) 0] [(@x x) 0]
[(@y y) 0] [(@y y) 0]
;; initialize the metadata ;; initialize the metadata
@ -55,7 +55,7 @@
(define/public (page) (first @pages)) (define/public (page) (first @pages))
(define/public (ref [payload (mhasheq)]) (define/public (make-ref [payload (mhasheq)])
(define new-ref (make-object PDFReference (@ref-gen) payload)) (define new-ref (make-object PDFReference (@ref-gen) payload))
(set! @refs (cons new-ref @refs)) (set! @refs (cons new-ref @refs))
new-ref) new-ref)
@ -85,7 +85,7 @@
(for ([page (in-list @pages)]) (for ([page (in-list @pages)])
(send page end)) (send page end))
(define doc-info (ref)) (define doc-info (make-ref))
(for ([(key val) (in-hash @info)]) (for ([(key val) (in-hash @info)])
(dict-set! doc-info key (if (string? val) (String val) val))) (dict-set! doc-info key (if (string? val) (String val) val)))
(send doc-info end) (send doc-info end)

@ -88,7 +88,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
(define/override (embed) (define/override (embed)
;; no CFF support ;; no CFF support
(define isCFF #false) #;(is-a? subset CFFSubset) (define isCFF #false) #;(is-a? subset CFFSubset)
(define font-file (send @document ref)) (define font-file (send @document make-ref))
(when isCFF (when isCFF
(dict-set! font-file 'Subtype "CIDFontType0C")) (dict-set! font-file 'Subtype "CIDFontType0C"))
@ -115,7 +115,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
(integer->char (random 65 (+ 65 26)))))) (integer->char (random 65 (+ 65 26))))))
(define name (string-append tag "+" (font-postscript-name font))) (define name (string-append tag "+" (font-postscript-name font)))
(define bbox (font-bbox font)) (define bbox (font-bbox font))
(define descriptor (send @document ref (define descriptor (send @document make-ref
(mhash (mhash
'Type "FontDescriptor" 'Type "FontDescriptor"
'FontName name 'FontName name
@ -132,7 +132,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
(dict-set! descriptor (if isCFF 'FontFile3 'FontFile2) font-file) (dict-set! descriptor (if isCFF 'FontFile3 'FontFile2) font-file)
(send descriptor end) (send descriptor end)
(define descendant-font (send @document ref (define descendant-font (send @document make-ref
(mhash (mhash
'Type "Font" 'Type "Font"
'Subtype (string-append "CIDFontType" (if isCFF "0" "2")) 'Subtype (string-append "CIDFontType" (if isCFF "0" "2"))
@ -159,7 +159,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
(define/public (toUnicodeCmap) (define/public (toUnicodeCmap)
(define cmap (send @document ref)) (define cmap (send @document make-ref))
(define entries (define entries
(for/list ([idx (in-range (length (hash-keys unicode)))]) (for/list ([idx (in-range (length (hash-keys unicode)))])
(define codepoints (hash-ref unicode idx)) (define codepoints (hash-ref unicode idx))

@ -17,7 +17,7 @@
(define/public (ref) (define/public (ref)
(unless @dictionary (unless @dictionary
(set! @dictionary (send @document ref))) (set! @dictionary (send @document make-ref)))
@dictionary) @dictionary)
(define/public (finalize) (define/public (finalize)

@ -48,7 +48,7 @@
(unless (· this obj) (unless (· this obj)
(set-field! obj this (set-field! obj this
(send doc-in ref (send doc-in make-ref
(mhash (mhash
'Type "XObject" 'Type "XObject"
'Subtype "Image" 'Subtype "Image"

@ -55,7 +55,7 @@
(unless (· this obj) (unless (· this obj)
(set-field! obj this (set-field! obj this
(send doc-in ref (send doc-in make-ref
(mhash (mhash
'Type "XObject" 'Type "XObject"
'Subtype "Image" 'Subtype "Image"

@ -18,8 +18,8 @@
(hash-ref page-sizes (string-upcase @size)))] (hash-ref page-sizes (string-upcase @size)))]
[(@width width) (list-ref @dimensions (if (equal? @layout "portrait") 0 1))] [(@width width) (list-ref @dimensions (if (equal? @layout "portrait") 0 1))]
[(@height height) (list-ref @dimensions (if (equal? @layout "portrait") 1 0))] [(@height height) (list-ref @dimensions (if (equal? @layout "portrait") 1 0))]
[@content (send @doc ref)] [@content (send @doc make-ref)]
[(@resources resources) (send @doc ref (mhash 'ProcSet '("PDF" "Text" "ImageB" "ImageC" "ImageI")))] [(@resources resources) (send @doc make-ref (mhash 'ProcSet '("PDF" "Text" "ImageB" "ImageC" "ImageI")))]
[(@margins margins) [(@margins margins)
(let ([margin-value (hash-ref @options 'margin #f)]) (let ([margin-value (hash-ref @options 'margin #f)])
(if (number? margin-value) (if (number? margin-value)
@ -27,7 +27,7 @@
(hash-ref @options 'margins (current-default-margins))))] (hash-ref @options 'margins (current-default-margins))))]
;; The page dictionary ;; The page dictionary
[(@dictionary dictionary) [(@dictionary dictionary)
(send @doc ref (send @doc make-ref
(mhash 'Type "Page" (mhash 'Type "Page"
'Parent @page-parent 'Parent @page-parent
'MediaBox (list 0 0 @width @height) 'MediaBox (list 0 0 @width @height)

@ -34,7 +34,7 @@
(unless (· this obj) (unless (· this obj)
(set-field! obj this (set-field! obj this
(send (· this document) ref (send (· this document) make-ref
(mhash 'Type "XObject" (mhash 'Type "XObject"
'Subtype "Image" 'Subtype "Image"
'BitsPerComponent (· this image bits) 'BitsPerComponent (· this image bits)
@ -43,7 +43,7 @@
'Filter "FlateDecode"))) 'Filter "FlateDecode")))
(unless (· this image hasAlphaChannel) (unless (· this image hasAlphaChannel)
(define params (send (· this document) ref (define params (send (· this document) make-ref
(mhash 'Predictor 15 (mhash 'Predictor 15
'Colors (· this image colors) 'Colors (· this image colors)
'BitsPerComponent (· this image bits) 'BitsPerComponent (· this image bits)
@ -82,7 +82,7 @@
(when (· this alphaChannel) (when (· this alphaChannel)
(define sMask (define sMask
(send (· this document) ref (send (· this document) make-ref
(mhash 'Type "XObject" (mhash 'Type "XObject"
'Subtype "Image" 'Subtype "Image"
'Height (· this height) 'Height (· this height)

Loading…
Cancel
Save