|
|
|
@ -3,6 +3,7 @@
|
|
|
|
|
"core.rkt"
|
|
|
|
|
racket/match
|
|
|
|
|
racket/class
|
|
|
|
|
racket/list
|
|
|
|
|
"standard-font.rkt"
|
|
|
|
|
"embedded-font.rkt")
|
|
|
|
|
(provide (all-defined-out))
|
|
|
|
@ -46,16 +47,39 @@
|
|
|
|
|
(set-$doc-current-font-size! doc size)
|
|
|
|
|
doc)
|
|
|
|
|
|
|
|
|
|
(define (font-features doc features [unfeatures null])
|
|
|
|
|
(unless (or (not features) (and (list? features) (andmap bytes? features)))
|
|
|
|
|
(raise-argument-error 'font-features "list of byte strings or #f" features))
|
|
|
|
|
(unless (and (list? unfeatures) (andmap bytes? unfeatures))
|
|
|
|
|
(raise-argument-error 'font-features "list of byte strings" unfeatures))
|
|
|
|
|
(set-$doc-current-font-features! doc
|
|
|
|
|
(and features
|
|
|
|
|
(sort (for/list ([f (in-list features)]
|
|
|
|
|
#:unless (memv f unfeatures))
|
|
|
|
|
f) bytes<?)))
|
|
|
|
|
(define (net-features feats)
|
|
|
|
|
;; filter out pairs of features with opposing (0 and 1) values
|
|
|
|
|
(let loop ([feats (remove-duplicates feats)]
|
|
|
|
|
[acc null])
|
|
|
|
|
(cond
|
|
|
|
|
[(empty? feats) acc]
|
|
|
|
|
[(empty? (cdr feats)) (loop empty (cons (car feats) acc))]
|
|
|
|
|
[else (define first-feat (car feats))
|
|
|
|
|
(match (cdr feats)
|
|
|
|
|
[(list head ... (? (λ (f) (bytes=? (car f) (car first-feat)))) tail ...)
|
|
|
|
|
(loop (append head tail) acc)]
|
|
|
|
|
[rest (loop rest (cons first-feat acc))])])))
|
|
|
|
|
|
|
|
|
|
(define (font-features doc [features-on null] [features-off null])
|
|
|
|
|
(unless (and (list? features-on) (andmap bytes? features-on))
|
|
|
|
|
(raise-argument-error 'font-features "list of feature byte strings" features-on))
|
|
|
|
|
(unless (and (list? features-off) (andmap bytes? features-off))
|
|
|
|
|
(raise-argument-error 'font-features "list of feature byte strings" 'features-off))
|
|
|
|
|
|
|
|
|
|
(define (make-feat-pairs feats val)
|
|
|
|
|
(for/list ([f (in-list feats)])
|
|
|
|
|
(match f
|
|
|
|
|
[(cons (? bytes?) (? exact-nonnegative-integer?)) f]
|
|
|
|
|
[(? bytes?) (cons f val)]
|
|
|
|
|
[else
|
|
|
|
|
(raise-argument-error 'font-features
|
|
|
|
|
"byte string or byte string + integer pair" f)])))
|
|
|
|
|
|
|
|
|
|
(define new-features (append (make-feat-pairs features-on 1)
|
|
|
|
|
(make-feat-pairs features-off 0)))
|
|
|
|
|
|
|
|
|
|
(set-$doc-current-font-features!
|
|
|
|
|
doc (net-features (append ($doc-current-font-features doc) new-features)))
|
|
|
|
|
doc)
|
|
|
|
|
|
|
|
|
|
(define (register-font doc name src)
|
|
|
|
|