delete font-size-previous key

main
Matthew Butterick 2 years ago
parent 169030b6bf
commit d0e6a86cd5

@ -17,5 +17,4 @@
[:font-path (make-attr-path-key 'font-path)] [:font-path (make-attr-path-key 'font-path)]
[:font-bold (make-attr-boolean-key 'font-bold #true #false)] [:font-bold (make-attr-boolean-key 'font-bold #true #false)]
[:font-italic (make-attr-boolean-key 'font-italic #true #false)] [:font-italic (make-attr-boolean-key 'font-italic #true #false)]
[:font-size (make-attr-dimension-string-key 'font-size #true default-font-size)] [:font-size (make-attr-dimension-string-key 'font-size #true default-font-size)])
[:font-size-previous (make-attr-dimension-string-key 'font-size-previous)])

@ -160,25 +160,20 @@
#:post (list-of quad?) #:post (list-of quad?)
(define (resolve-font-size-once attrs parent-attrs) (define (resolve-font-size-once attrs parent-attrs)
(define previous-font-size
(cond
[(and parent-attrs (hash-ref parent-attrs :font-size #false))]
[else default-font-size]))
(define base-size-adjusted (define base-size-adjusted
(match (hash-ref attrs :font-size 'missing) (match (hash-ref attrs :font-size #false)
[(? procedure? proc)
;; if our value represents an adjustment, ;; if our value represents an adjustment,
;; we apply the adjustment to the previous value ;; we apply the adjustment to the previous value
[(? procedure? proc)
(define previous-font-size (cond
[(and parent-attrs (hash-ref parent-attrs :font-size-previous #false))]
[else default-font-size]))
(proc previous-font-size)] (proc previous-font-size)]
;; otherwise we use our value directly ;; otherwise we use our value directly
[(? number? num) num] [(? number? num) num]
[other (raise-user-error 'resolve-font-sizes "procedure or number" other)])) [other #false]))
;; we write our new value into both font-size and font-size-previous (hash-set! attrs :font-size (or base-size-adjusted previous-font-size)))
;; because as we cascade down, we're likely to come across superseding values
;; of font-size
;; but the font-size-previous will persist
;; because on the next recursion, the current `attrs` will be `parent-attrs`
(hash-set*! attrs :font-size base-size-adjusted
:font-size-previous base-size-adjusted))
(for-each-attrs qs resolve-font-size-once)) (for-each-attrs qs resolve-font-size-once))

@ -21,7 +21,12 @@
;; all attrs start out as symbol-string pairs. ;; all attrs start out as symbol-string pairs.
;; we convert keys & values to corresponding higher-level types. ;; we convert keys & values to corresponding higher-level types.
upgrade-attr-keys upgrade-attr-keys
fill-default-attr-values ;; I think this is wrong. Filling in default values here
;; will prevent parent values from cascading during linearization
;; but it would be OK at the top level, to ensure
;; that there are values that cascade
;; but that can be done by wrapping in a quad with the default values
#;fill-default-attr-values
downcase-string-attr-values downcase-string-attr-values
convert-boolean-attr-values convert-boolean-attr-values
convert-numeric-attr-values convert-numeric-attr-values
@ -30,6 +35,7 @@
;; these need the tree shape ;; these need the tree shape
parse-dimension-strings parse-dimension-strings
resolve-font-sizes resolve-font-sizes
#;resolve-font-features
;; linearization ============= ;; linearization =============
;; we postpone this step until we're certain any ;; we postpone this step until we're certain any

Loading…
Cancel
Save