consequences

main
Matthew Butterick 6 years ago
parent 268c5dacc8
commit 8a2730d259

@ -5,6 +5,7 @@
racket/format
racket/generator
racket/match
racket/dict
racket/list
sugar/unstable/dict
"reference.rkt"
@ -61,7 +62,7 @@
(define/public (add-page [options-arg @options])
;; create a page object
(define page-parent (send @root get-key 'Pages))
(define page-parent (dict-ref @root 'Pages))
(set! @pages (cons (make-object PDFPage this page-parent options-arg) @pages))
;; reset x and y coordinates
@ -86,13 +87,13 @@
(define doc-info (ref))
(for ([(key val) (in-hash @info)])
(send doc-info set-key! key (if (string? val) (String val) val)))
(dict-set! doc-info key (if (string? val) (String val) val)))
(send doc-info end)
(for ([font (in-hash-values @font-families)])
(send font finalize))
(send* (send @root get-key 'Pages)
(send* (dict-ref @root 'Pages)
[set-key! 'Count (length @pages)]
[set-key! 'Kids (map (λ (page) (get-field dictionary page)) (reverse @pages))]
[end])

@ -7,6 +7,7 @@
racket/string
racket/format
racket/list
racket/dict
sugar/unstable/dict
"font.rkt"
fontland)
@ -90,7 +91,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
(define font-file (send @document ref))
(when isCFF
(send font-file set-key! 'Subtype "CIDFontType0C"))
(dict-set! font-file 'Subtype "CIDFontType0C"))
(send* font-file [write (get-output-bytes (encode-to-port subset))] [end])
@ -128,7 +129,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
'XHeight (* (or (font-x-height font) 0) scale)
'StemV 0)))
(send descriptor set-key! (if isCFF 'FontFile3 'FontFile2) font-file)
(dict-set! descriptor (if isCFF 'FontFile3 'FontFile2) font-file)
(send descriptor end)
(define descendant-font (send @document ref

@ -61,7 +61,7 @@
;; min and max values from the default, we invert the colors. See
;; section 4.8.4 of the spec.
(when (equal? (· this colorSpace) "DeviceCMYK")
(send (· this obj) set-key! 'Decode '(1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0)))
(dict-set! (· this obj) 'Decode '(1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0)))
(port-position (· this data) 0)
(send (· this obj) end (· this data))))

@ -2,6 +2,7 @@
(require
racket/class
racket/contract
racket/dict
sugar/unstable/class
sugar/unstable/js
sugar/unstable/dict
@ -68,7 +69,7 @@
;; min and max values from the default, we invert the colors. See
;; section 4.8.4 of the spec.
(when (equal? (· this colorSpace) "DeviceCMYK")
(send (· this obj) set-key! 'Decode '(1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0)))
(dict-set! (· this obj) 'Decode '(1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0)))
(port-position (· this data) 0)
(send* (· this obj) [write (· this data)]

@ -1,6 +1,7 @@
#lang debug racket/base
(require
racket/class
racket/dict
sugar/unstable/dict
"core.rkt")
@ -35,21 +36,21 @@
;; Lazily create these dictionaries
(define/public (fonts)
(send @resources get-key! 'Font (make-hasheq)))
(dict-ref! @resources 'Font (make-hasheq)))
(define/public (xobjects)
(send @resources get-key! 'XObject (make-hasheq)))
(dict-ref! @resources 'XObject (make-hasheq)))
(define/public (ext_gstates)
(send @resources get-key! 'ExtGState (make-hasheq)))
(dict-ref! @resources 'ExtGState (make-hasheq)))
(define/public (patterns)
(send @resources get-key! 'Pattern (make-hasheq)))
(dict-ref! @resources 'Pattern (make-hasheq)))
(define/public (annotations [annot #f])
(if annot
(send @dictionary update-key! 'Annots (λ (val) (cons annot val)) null)
(send @dictionary get-key! 'Annots null)))
(dict-update! @dictionary 'Annots (λ (val) (cons annot val)) null)
(dict-ref! @dictionary 'Annots null)))
(define/public (maxY)
(- @height (margin-bottom @margins)))

@ -2,6 +2,7 @@
(require
racket/class
racket/contract
racket/dict
racket/draw
sugar/unstable/class
sugar/unstable/js
@ -47,7 +48,7 @@
'Colors (· this image colors)
'BitsPerComponent (· this image bits)
'Columns (· this width))))
(send (· this obj) set-key! 'DecodeParms params)
(dict-set! (· this obj) 'DecodeParms params)
(send params end))
(cond
@ -57,9 +58,9 @@
(send* palette-ref [write (· this image palette)] [end])
;; build the color space array for the image
(send (· this object) set-key! 'Colorspace
(dict-set! (· this object) 'Colorspace
(list "Indexed" "DeviceRGB" (sub1 (bytes-length (· this image palette))) palette-ref))]
[else (send (· this obj) set-key! 'ColorSpace "DeviceRGB")])
[else (dict-set! (· this obj) 'ColorSpace "DeviceRGB")])
(cond
@ -91,7 +92,7 @@
'ColorSpace "DeviceGray"
'Decode '(0 1))))
(send* sMask [write (· this alphaChannel)] [end])
(send (· this obj) set-key! 'SMask sMask))
(dict-set! (· this obj) 'SMask sMask))
;; embed the actual image data
(send* (· this obj) [write (· this imgData)] [end]))

@ -13,9 +13,12 @@
(interface* ()
([(generic-property gen:dict)
(generic-method-table gen:dict
(define (dict-ref refobj key [thunk #f]) (send refobj get-key key))
(define (dict-set! refobj key val) (send refobj set-key! key))
(define (dict-update! refobj key updater [failure-result #f]) (send refobj update-key! key updater)))])))
(define (dict-ref refobj key [thunk (λ () (error 'dict-ref-key-not-found))])
(send refobj get-key key))
(define (dict-ref! refobj key thunk)
(send refobj get-key! key thunk))
(define (dict-set! refobj key val) (send refobj set-key! key val))
(define (dict-update! refobj key updater [failure-result (λ () (error 'update-no-key))]) (send refobj update-key! key updater failure-result)))])))
(define PDFReference
(class* object% (dictable<%>)

Loading…
Cancel
Save