diff --git a/pitfall/pitfall/document.rkt b/pitfall/pitfall/document.rkt index 273be4f1..f234cac4 100644 --- a/pitfall/pitfall/document.rkt +++ b/pitfall/pitfall/document.rkt @@ -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]) diff --git a/pitfall/pitfall/embedded.rkt b/pitfall/pitfall/embedded.rkt index 98326ad4..6d0cf342 100644 --- a/pitfall/pitfall/embedded.rkt +++ b/pitfall/pitfall/embedded.rkt @@ -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 diff --git a/pitfall/pitfall/jpeg-structy.rkt b/pitfall/pitfall/jpeg-structy.rkt index 7ff07a69..e6c98fa1 100644 --- a/pitfall/pitfall/jpeg-structy.rkt +++ b/pitfall/pitfall/jpeg-structy.rkt @@ -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)))) diff --git a/pitfall/pitfall/jpeg.rkt b/pitfall/pitfall/jpeg.rkt index a7068807..beab92ec 100644 --- a/pitfall/pitfall/jpeg.rkt +++ b/pitfall/pitfall/jpeg.rkt @@ -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)] diff --git a/pitfall/pitfall/page.rkt b/pitfall/pitfall/page.rkt index 59170b3d..df995d80 100644 --- a/pitfall/pitfall/page.rkt +++ b/pitfall/pitfall/page.rkt @@ -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))) diff --git a/pitfall/pitfall/png.rkt b/pitfall/pitfall/png.rkt index eb36f2a6..1e9791b2 100644 --- a/pitfall/pitfall/png.rkt +++ b/pitfall/pitfall/png.rkt @@ -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])) diff --git a/pitfall/pitfall/reference.rkt b/pitfall/pitfall/reference.rkt index c002b7de..45166b5b 100644 --- a/pitfall/pitfall/reference.rkt +++ b/pitfall/pitfall/reference.rkt @@ -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<%>)