diff --git a/pitfall/pitfall/document.rkt b/pitfall/pitfall/document.rkt index 10977cf3..cc06fdba 100644 --- a/pitfall/pitfall/document.rkt +++ b/pitfall/pitfall/document.rkt @@ -98,7 +98,7 @@ (define pages-ref (dict-ref ($doc-root doc) 'Pages)) (dict-set! pages-ref 'Count (length ($doc-pages doc))) - (dict-set! pages-ref 'Kids (map $page-dictionary (reverse ($doc-pages doc)))) + (dict-set! pages-ref 'Kids (map $page-ref (reverse ($doc-pages doc)))) (ref-end pages-ref) (ref-end ($doc-root doc)) diff --git a/pitfall/pitfall/embedded-font.rkt b/pitfall/pitfall/embedded-font.rkt index b022b76f..c0ebde2d 100644 --- a/pitfall/pitfall/embedded-font.rkt +++ b/pitfall/pitfall/embedded-font.rkt @@ -54,7 +54,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee (inherit-field [@ascender ascender] [@bbox bbox] [@descender descender] - [@dictionary dictionary]) + [@ref ref]) (define/override (string-width string size [features #f]) ; #f disables features ; null enables default features ; list adds features @@ -150,7 +150,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee (hash-ref widths idx (λ () (error 'embed (format "hash key ~a not found" idx))))))))) (ref-end descendant-font) - (dict-set*! @dictionary + (dict-set*! @ref 'Type 'Font 'Subtype 'Type0 'BaseFont name @@ -158,7 +158,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee 'DescendantFonts (list descendant-font) 'ToUnicode (to-unicode-cmap)) - (ref-end @dictionary)) + (ref-end @ref)) (define/public (to-unicode-cmap) (define cmap-ref (make-ref)) diff --git a/pitfall/pitfall/font.rkt b/pitfall/pitfall/font.rkt index 47fca603..f4e4b29c 100644 --- a/pitfall/pitfall/font.rkt +++ b/pitfall/pitfall/font.rkt @@ -12,18 +12,18 @@ [(@descender descender) #f] [(@line-gap line-gap) #f] [(@bbox bbox) #f]) - (field [(@dictionary dictionary) #f] + (field [(@ref ref) #f] [@embedded #f]) (abstract embed encode string-width) (define/public (make-font-ref) - (unless @dictionary - (set! @dictionary (make-ref))) - @dictionary) + (unless @ref + (set! @ref (make-ref))) + @ref) (define/public (font-end) - (unless (or @embedded (not @dictionary)) + (unless (or @embedded (not @ref)) (embed) (set! @embedded #t))) diff --git a/pitfall/pitfall/page-test.rkt b/pitfall/pitfall/page-test.rkt index 7fafe96d..87276f92 100644 --- a/pitfall/pitfall/page-test.rkt +++ b/pitfall/pitfall/page-test.rkt @@ -15,7 +15,7 @@ (check-equal? ($page-width p) 612.0) (check-equal? (dict-ref ($page-resources p) 'ProcSet) '(PDF Text ImageB ImageC ImageI)) -(check-equal? (dict-ref ($page-dictionary p) 'Type) 'Page) -(check-equal? (dict-ref ($page-dictionary p) 'MediaBox) '(0 0 612.0 792.0)) -(check-true ($ref? (dict-ref ($page-dictionary p) 'Contents))) -(check-true ($ref? (dict-ref ($page-dictionary p) 'Resources))) \ No newline at end of file +(check-equal? (dict-ref ($page-ref p) 'Type) 'Page) +(check-equal? (dict-ref ($page-ref p) 'MediaBox) '(0 0 612.0 792.0)) +(check-true ($ref? (dict-ref ($page-ref p) 'Contents))) +(check-true ($ref? (dict-ref ($page-ref p) 'Resources))) \ No newline at end of file diff --git a/pitfall/pitfall/page.rkt b/pitfall/pitfall/page.rkt index a3ddd3af..33bc1dc6 100644 --- a/pitfall/pitfall/page.rkt +++ b/pitfall/pitfall/page.rkt @@ -13,7 +13,7 @@ (define (add-content doc data) (page-write (current-page doc) data)) -(struct $page (page-parent options size layout dimensions width height content resources margins dictionary) +(struct $page (page-parent options size layout dimensions width height content resources margins ref) #:transparent #:mutable) (define (make-page [page-parent #false] [options (mhasheq)]) @@ -29,13 +29,13 @@ (match (hash-ref options 'margin #f) [(? number? margin-value) (margin margin-value margin-value margin-value margin-value)] [_ (hash-ref options 'margins (current-default-margins))])) - (define page-dictionary + (define page-ref (make-ref (mhasheq 'Type 'Page 'Parent page-parent 'MediaBox (list 0 0 width height) 'Contents content 'Resources resources))) - ($page page-parent options size layout dimensions width height content resources margins page-dictionary)) + ($page page-parent options size layout dimensions width height content resources margins page-ref)) (define (page-fonts p) (dict-ref! ($page-resources p) 'Font (make-hasheq))) @@ -51,8 +51,8 @@ (define (page-annotations p [annot #f]) (if annot - (dict-update! ($page-dictionary p) 'Annots (λ (val) (cons annot val)) null) - (dict-ref! ($page-dictionary p) 'Annots null))) + (dict-update! ($page-ref p) 'Annots (λ (val) (cons annot val)) null) + (dict-ref! ($page-ref p) 'Annots null))) (define (page-maxY p) (- ($page-height p) (margin-bottom ($page-margins p)))) @@ -61,7 +61,7 @@ (ref-write ($page-content p) chunk)) (define (page-end p) - (ref-end ($page-dictionary p)) + (ref-end ($page-ref p)) (ref-end ($page-resources p)) (ref-end ($page-content p))) diff --git a/pitfall/pitfall/standard-font.rkt b/pitfall/pitfall/standard-font.rkt index 86e6fe3e..94141054 100644 --- a/pitfall/pitfall/standard-font.rkt +++ b/pitfall/pitfall/standard-font.rkt @@ -29,18 +29,18 @@ [descender (string->number (hash-ref @attributes 'Descender "0"))] [bbox (for/list ([attr (in-list (string-split (hash-ref @attributes 'FontBBox)))]) (or (string->number attr) 0))] - [line-gap (- (list-ref bbox 3) (list-ref bbox 1) ascender descender)]) + [line-gap (- (third bbox) (first bbox) ascender descender)]) (super-new [ascender ascender] [descender descender] [bbox bbox] [line-gap line-gap])) - (inherit-field [@dictionary dictionary]) + (inherit-field [@ref ref]) (define/override (embed) - (set-$ref-payload! @dictionary + (set-$ref-payload! @ref (mhash 'Type 'Font 'BaseFont (string->symbol name) 'Subtype 'Type1 'Encoding 'WinAnsiEncoding)) - (ref-end @dictionary)) + (ref-end @ref)) (define/public (character-to-glyph char) (define cint (char->integer char))