From f87ab67ab501c19d49e2f79f432df101f93a5389 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 30 Dec 2018 20:37:33 -0800 Subject: [PATCH] improve features semantics --- fontland/fontland/font.rkt | 19 +++++++++++-------- fontland/fontland/unsafe/harfbuzz.rkt | 10 +++++----- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/fontland/fontland/font.rkt b/fontland/fontland/font.rkt index 5c0e20b6..87a9fad2 100644 --- a/fontland/fontland/font.rkt +++ b/fontland/fontland/font.rkt @@ -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))) diff --git a/fontland/fontland/unsafe/harfbuzz.rkt b/fontland/fontland/unsafe/harfbuzz.rkt index e8d80774..78c82b28 100644 --- a/fontland/fontland/unsafe/harfbuzz.rkt +++ b/fontland/fontland/unsafe/harfbuzz.rkt @@ -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))