diff --git a/pitfall/pitfall/color.rkt b/pitfall/pitfall/color.rkt index 08286103..a179ccc2 100644 --- a/pitfall/pitfall/color.rkt +++ b/pitfall/pitfall/color.rkt @@ -24,8 +24,8 @@ (hash-set! dictionary 'CA stroke-opacity)) (define ref-dict (make-ref dictionary)) (ref-end ref-dict) - (set-$doc-opacity-count! doc (add1 ($doc-opacity-count doc))) - (list ref-dict (string->symbol (format "Gs~a" ($doc-opacity-count doc))))))) + (define opacity-index (add1 (length (hash-keys ($doc-opacity-registry doc))))) + (list ref-dict (string->symbol (format "Gs~a" opacity-index)))))) (hash-set! (page-ext_gstates (page doc)) name dictionary) (add-content doc (format "/~a gs" name)))) @@ -103,26 +103,6 @@ (if (integer? x) (inexact->exact x) x))] [_ #false])) -#;(define (color-mixin [% object%]) - (class % - (super-new) - (field [@opacity-registry (make-hash)] - [@opacity-count 0] - [@grad-count 0] - [(@current-fill-color current-fill-color) #false]) - - - - - - - - - - - - )) - (define named-colors (hash "aliceblue" '(240 248 255) "antiquewhite" '(250 235 215) diff --git a/pitfall/pitfall/core.rkt b/pitfall/pitfall/core.rkt index 4feaca61..aa94e579 100644 --- a/pitfall/pitfall/core.rkt +++ b/pitfall/pitfall/core.rkt @@ -10,13 +10,10 @@ root info opacity-registry - opacity-count - grad-count current-fill-color ctm ctm-stack font-families - font-count current-font-size current-font registered-fonts @@ -24,8 +21,7 @@ text-options x y - image-registry - image-count) #:transparent #:mutable) + image-registry) #:transparent #:mutable) ;; for JPEG and PNG diff --git a/pitfall/pitfall/document.rkt b/pitfall/pitfall/document.rkt index 55599345..cd0c526f 100644 --- a/pitfall/pitfall/document.rkt +++ b/pitfall/pitfall/document.rkt @@ -26,13 +26,10 @@ (for ([(key val) (in-hash (hash-ref options 'info (hasheq)))]) (hash-set! info key val)) (define opacity-registry (make-hash)) - (define opacity-count 0) - (define grad-count 0) (define current-fill-color #false) (define ctm default-ctm-value) (define ctm-stack null) (define font-families (make-hash)) - (define font-count 0) (define current-font-size 12) (define current-font #false) (define registered-fonts (make-hash)) @@ -41,20 +38,16 @@ (define x 0) (define y 0) (define image-registry (make-hash)) - (define image-count 0) (define new-doc ($doc options pages refs 'dummy-root-value-that-will-be-replaced-below info opacity-registry - opacity-count - grad-count current-fill-color ctm ctm-stack font-families - font-count current-font-size current-font registered-fonts @@ -62,8 +55,7 @@ text-options x y - image-registry - image-count)) + image-registry)) (set-current-ref-id! 1) (register-ref-listener (λ (ref) (store-ref new-doc ref))) (set-$doc-root! new-doc (make-ref (mhasheq 'Type 'Catalog @@ -213,7 +205,7 @@ (write-bytes-out "xref") (write-bytes-out (format "0 ~a" (add1 (length @refs)))) (write-bytes-out "0000000000 65535 f ") - (for ([ref (in-list (reverse @refs))]) + (for ([ref (in-list @refs)]) (write-bytes-out (string-append (~r ($ref-offset ref) #:min-width 10 #:pad-string "0") " 00000 n "))) (write-bytes-out "trailer") diff --git a/pitfall/pitfall/fonts.rkt b/pitfall/pitfall/fonts.rkt index 47b995e4..65ca1283 100644 --- a/pitfall/pitfall/fonts.rkt +++ b/pitfall/pitfall/fonts.rkt @@ -32,8 +32,8 @@ (match (hash-ref ($doc-font-families doc) cache-key #f) ; check if the font is already in the PDF [(? values val) (set-$doc-current-font! doc val)] [_ ; if not, load the font - (set-$doc-font-count! doc (add1 ($doc-font-count doc))) - (define id (string->symbol (format "F~a" ($doc-font-count doc)))) + (define font-index (add1 (length (hash-keys ($doc-font-families doc))))) + (define id (string->symbol (format "F~a" font-index))) (set-$doc-current-font! doc (PDFFont-open src family id)) ;; check for existing font families with the same name already in the PDF (match (hash-ref ($doc-font-families doc) (get-field name ($doc-current-font doc)) #f) diff --git a/pitfall/pitfall/images.rkt b/pitfall/pitfall/images.rkt index ea724de0..56c227dd 100644 --- a/pitfall/pitfall/images.rkt +++ b/pitfall/pitfall/images.rkt @@ -104,8 +104,8 @@ (cond [(and (string? src) (hash-ref ($doc-image-registry doc) src #f))] [else - (set-$doc-image-count! doc (add1 ($doc-image-count doc))) - (define image-id (string->symbol (format "I~a" ($doc-image-count doc)))) + (define image-idx (add1 (length (hash-keys ($doc-image-registry doc))))) + (define image-id (string->symbol (format "I~a" image-idx))) (define new-image (open-pdf-image src image-id)) (when (string? src) (hash-set! ($doc-image-registry doc) src new-image)) new-image]))