improve features semantics

main
Matthew Butterick 6 years ago
parent 3fb90cae5a
commit f87ab67ab5

@ -74,18 +74,21 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js
;; ram cache in pitfall suffices
(define (layout font str
[features null]
[script 'HB_SCRIPT_LATIN]
[lang #"en"]
[direction 'HB_DIRECTION_LTR])
#:features [features null]
#:script [script #f]
#:language [lang #f]
#:direction [direction #f])
(define buf (hb-buf font))
(hb_buffer_reset buf)
(hb_buffer_set_script buf script)
(hb_buffer_set_language buf (hb_language_from_string lang))
(hb_buffer_set_direction buf direction)
(when script
(hb_buffer_set_script buf script))
(when lang
(hb_buffer_set_language buf (hb_language_from_string lang)))
(when direction
(hb_buffer_set_direction buf direction))
(define codepoints (for/list ([c (in-string str)]) (char->integer c)))
(hb_buffer_add_codepoints buf codepoints)
(hb_shape (hb-font font) buf (map tag->hb-feature features))
(hb_shape (hb-font font) buf (map (λ (fpr) (tag->hb-feature (car fpr) (cdr fpr))) features))
(define gis (hb_buffer_get_glyph_infos buf))
(define hb-gids (map hb_glyph_info_t-codepoint gis))
(define hb-clusters (break-at codepoints (map hb_glyph_info_t-cluster gis)))

@ -182,17 +182,17 @@
(define HB_FEATURE_GLOBAL_START 0)
(define HB_FEATURE_GLOBAL_END 4294967295)
(define (tag->hb-feature bs)
(define (tag->hb-feature bs [val 1])
(unless (and (bytes? bs) (= (bytes-length bs) 4))
(raise-argument-error 'tag->hb-feature "4 bytes" bs))
(hb_feature_from_string bs))
(make-hb_feature_t (->tag bs) val HB_FEATURE_GLOBAL_START HB_FEATURE_GLOBAL_END))
(define liga_on (tag->hb-feature #"liga"))
(define liga_off (make-hb_feature_t (->tag #"liga") 0 HB_FEATURE_GLOBAL_START HB_FEATURE_GLOBAL_END))
(define liga_off (tag->hb-feature #"liga" 0))
(define kern_on (tag->hb-feature #"kern"))
(define kern_off (make-hb_feature_t (->tag #"kern") 0 HB_FEATURE_GLOBAL_START HB_FEATURE_GLOBAL_END))
(define kern_off (tag->hb-feature #"kern" 0))
(define onum_on (tag->hb-feature #"onum"))
(define onum_off (make-hb_feature_t (->tag #"onum") 0 HB_FEATURE_GLOBAL_START HB_FEATURE_GLOBAL_END))
(define onum_off (tag->hb-feature #"onum" 0))
(define (shape font text [feats null])
(define buf (hb_buffer_create))

Loading…
Cancel
Save