From 268c5dacc8f2d6530485f72d8396afa87ad8c3a5 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 22 Dec 2018 21:30:46 -0800 Subject: [PATCH] dictify reference --- pitfall/pitfall/page-test.rkt | 12 ++++++------ pitfall/pitfall/reference.rkt | 11 ++++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pitfall/pitfall/page-test.rkt b/pitfall/pitfall/page-test.rkt index e50f057b..d4390a0c 100644 --- a/pitfall/pitfall/page-test.rkt +++ b/pitfall/pitfall/page-test.rkt @@ -12,10 +12,10 @@ (check-equal? (· p margins) (margin 72 72 72 72)) (check-equal? (· p height) 792.0) (check-equal? (· p width) 612.0) -(check-equal? (· p resources payload ProcSet) '("PDF" "Text" "ImageB" "ImageC" "ImageI")) +(check-equal? (· p resources ProcSet) '("PDF" "Text" "ImageB" "ImageC" "ImageI")) -(check-equal? (· p dictionary payload Type) "Page") -(check-equal? (· p dictionary payload MediaBox) '(0 0 612.0 792.0)) -(check-true (is-a? (· p dictionary payload Contents) PDFReference)) -(check-true (is-a? (· p dictionary payload Resources) PDFReference)) -#;(check-true (is-a? (· p dictionary payload Parent) PDFReference)) \ No newline at end of file +(check-equal? (· p dictionary Type) "Page") +(check-equal? (· p dictionary MediaBox) '(0 0 612.0 792.0)) +(check-true (is-a? (· p dictionary Contents) PDFReference)) +(check-true (is-a? (· p dictionary Resources) PDFReference)) +#;(check-true (is-a? (· p dictionary Parent) PDFReference)) \ No newline at end of file diff --git a/pitfall/pitfall/reference.rkt b/pitfall/pitfall/reference.rkt index 2118b996..c002b7de 100644 --- a/pitfall/pitfall/reference.rkt +++ b/pitfall/pitfall/reference.rkt @@ -2,14 +2,23 @@ (require racket/class racket/match racket/port + racket/dict + racket/private/generic-methods "core.rkt" "object.rkt" "zlib.rkt") (provide PDFReference) +(define dictable<%> + (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 PDFReference - (class object% + (class* object% (dictable<%>) (super-new) (init-field [(@id id)] [(@payload payload) (make-hasheq)])