local option for font-face

master
Matthew Butterick 7 years ago
parent 6a33aed790
commit cd43e1ee33

@ -80,14 +80,14 @@
(define (valid-font-stretch? x) (define (valid-font-stretch? x)
(and (string? x) (member x '("normal" (and (string? x) (member x '("normal"
"ultra-condensed" "ultra-condensed"
"extra-condensed" "extra-condensed"
"condensed" "condensed"
"semi-condensed" "semi-condensed"
"semi-expanded" "semi-expanded"
"expanded" "expanded"
"extra-expanded" "extra-expanded"
"ultra-expanded")) #t)) "ultra-expanded")) #t))
(module+ test (module+ test
(check-true (valid-font-stretch? "normal")) (check-true (valid-font-stretch? "normal"))
@ -97,16 +97,18 @@
(define/contract (font-face-declaration font-family (define/contract (font-face-declaration font-family
src-url src-url
#:local [local-name #f]
#:font-style [font-style "normal"] #:font-style [font-style "normal"]
#:font-weight [font-weight "normal"] #:font-weight [font-weight "normal"]
#:font-stretch [font-stretch "normal"] #:font-stretch [font-stretch "normal"]
#:base64 [base64? #f]) #:base64 [base64? #f])
((string? (or/c urlish? base64-font-string?)) ((string? (or/c urlish? base64-font-string?))
(#:font-style valid-font-style? #:font-weight valid-font-weight? #:font-stretch valid-font-stretch? #:base64 boolean?) (#:font-style valid-font-style? #:font-weight valid-font-weight? #:font-stretch valid-font-stretch? #:base64 boolean? #:local (or/c #f string?))
. ->* . string?) . ->* . string?)
(let* [(url (->url src-url)) (let* ([url (->url src-url)]
(url-value (if base64? (path->base64-font-string src-url) (->path url))) [url-value (if base64? (path->base64-font-string src-url) (->path url))]
(src (format "url('~a') format('~a')" url-value (font-format src-url)))] [src (format "url('~a') format('~a')" url-value (font-format src-url))]
[src (string-append (if local-name (format "local(~v), " local-name) "") src)])
(string-append "@font-face {\n" (string-append "@font-face {\n"
(join-css-strings (map make-css-string (join-css-strings (map make-css-string
'(font-family font-style font-weight font-stretch src) '(font-family font-style font-weight font-stretch src)

Loading…
Cancel
Save