allow percentage for font-tracking

main
Matthew Butterick 4 years ago
parent 0deb440ea0
commit 4cd69f71db

@ -16,16 +16,17 @@
(define (parse-dimension x) (define (parse-dimension x)
(match x (match x
[#false #false] [#false #false]
[(? number?) x] [(? number? num) num]
[(? string? x) [(? string? str)
(match (cdr (regexp-match #px"^(-?[0-9\\.]+)\\s*([a-z]+)$" (string-downcase x))) (match (regexp-match #px"^(-?[0-9\\.]+)\\s*([a-z]+)$" (string-downcase str))
[(list num-string unit) [#false str] ; a string other than a dimension string, so leave it
[(list _ num-string unit)
((match unit ((match unit
[(regexp #rx"(pt|point)(s)?$") values] [(regexp #rx"(pt|point)(s)?$") values]
[(regexp #rx"in(ch(es)?)?$") in->pts] [(regexp #rx"in(ch(es)?)?$") in->pts]
[(regexp #rx"cm$") (compose1 in->pts cm->in)] [(regexp #rx"cm$") (compose1 in->pts cm->in)]
[(regexp #rx"mm$") (compose1 in->pts cm->in mm->cm)] [(regexp #rx"mm$") (compose1 in->pts cm->in mm->cm)]
[_ (raise-argument-error 'parse-dimension "dimension string" x)]) (string->number num-string))])])) [_ (raise-argument-error 'parse-dimension "dimension string" str)]) (string->number num-string))])]))
(define (copy-block-attrs source-hash dest-hash) (define (copy-block-attrs source-hash dest-hash)
(define new-hash (make-hasheq)) (define new-hash (make-hasheq))

@ -76,7 +76,10 @@
(hash-set! attrs :font-path (font-attrs->path this-font-family this-bold this-italic)))) (hash-set! attrs :font-path (font-attrs->path this-font-family this-bold this-italic))))
(define (parse-percentage pstr) (define (parse-percentage pstr)
(/ (string->number (string-trim pstr "%")) 100.0)) (and
(string? pstr)
(string-suffix? pstr "%")
(/ (string->number (string-trim pstr "%")) 100.0)))
(define (adjuster-base attrs key adjustment-key default-value) (define (adjuster-base attrs key adjustment-key default-value)
(define this-val (hash-ref! attrs key default-value)) (define this-val (hash-ref! attrs key default-value))
@ -91,3 +94,10 @@
(define (resolve-line-height! attrs) (define (resolve-line-height! attrs)
(adjuster-base attrs :line-height :line-height-adjust default-line-height)) (adjuster-base attrs :line-height :line-height-adjust default-line-height))
(define (resolve-font-tracking! attrs)
;; if it's a percentage, we need to look at the font size.
;; if it's anything else, we're done.
(match (parse-percentage (hash-ref attrs :font-tracking #false))
[#false (void)]
[pct (hash-set! attrs :font-tracking (* pct (hash-ref attrs :font-size)))]))

@ -112,6 +112,7 @@
complete-every-path! complete-every-path!
resolve-font-path! resolve-font-path!
resolve-font-size! resolve-font-size!
resolve-font-tracking!
resolve-line-height! resolve-line-height!
parse-font-features!))]) parse-font-features!))])
(proc attrs))) (proc attrs)))

Loading…
Cancel
Save