#lang racket/base (require "core.rkt" "reference.rkt" "page.rkt" "color.rkt" racket/match sugar/unstable/dict) (provide (all-defined-out)) (define annots-cache (make-hash)) (define link-ref-cache (make-hash)) (define (reset-annotations-cache!) (set! link-ref-cache (make-hash)) (set! annots-cache (make-hash))) (define (annotate doc x y w h options) (hash-set*! options 'Type 'Annot 'Rect (convert-rect doc x y w h) 'Border '(0 0 0)) (unless (eq? (hash-ref options 'Subtype #f) 'Link) (hash-ref! options 'C (λ () (normalize-color (or (hash-ref options 'color #f) '(0 0 0)))))) (hash-remove! options 'color) (for ([(k v) (in-hash options)]) (hash-set! options (string->symbol (string-titlecase (symbol->string k))) v)) ;; reuse previous identical annotations (= fewer refs in file) (define annots-ref (hash-ref! annots-cache (sort (hash->list options) #:key car symbol