From 33b97385fba4bf939c56069f9db5e615a9477da5 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 30 Dec 2018 17:02:25 -0800 Subject: [PATCH] feature tags are byte strings --- fontland/fontland/unsafe/harfbuzz-helper.rkt | 4 +--- fontland/fontland/unsafe/harfbuzz.rkt | 14 ++++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/fontland/fontland/unsafe/harfbuzz-helper.rkt b/fontland/fontland/unsafe/harfbuzz-helper.rkt index 00f980ae..5eb49704 100644 --- a/fontland/fontland/unsafe/harfbuzz-helper.rkt +++ b/fontland/fontland/unsafe/harfbuzz-helper.rkt @@ -13,9 +13,7 @@ HB_DIRECTION_BTT = 7)) (define (->tag bstr) - (define bs (bytes->list bstr)) - (for/sum ([(b i) (in-indexed (reverse bs))]) - (* b (expt 2 (* i 8))))) + (integer-bytes->integer bstr #f #;(= unsigned) 'big-endian)) (define hb-script-values `(HB_SCRIPT_COMMON = ,(->tag #"Zyyy") diff --git a/fontland/fontland/unsafe/harfbuzz.rkt b/fontland/fontland/unsafe/harfbuzz.rkt index 5e8ccea6..244c7d96 100644 --- a/fontland/fontland/unsafe/harfbuzz.rkt +++ b/fontland/fontland/unsafe/harfbuzz.rkt @@ -182,18 +182,16 @@ (define HB_FEATURE_GLOBAL_START 0) (define HB_FEATURE_GLOBAL_END 4294967295) -(define (tag->hb-feature tag) - (define str (symbol->string tag)) - (define bs (string->bytes/utf-8 str)) - (unless (= (bytes-length bs) (string-length str)) - (error 'invalid-tag-char)) +(define (tag->hb-feature bs) + (unless (and (bytes? bs) (= (bytes-length bs) 4)) + (raise-argument-error 'tag->hb-feature "4 bytes" bs)) (hb_feature_from_string bs)) -(define liga_on (tag->hb-feature 'liga)) +(define liga_on (tag->hb-feature #"liga")) (define liga_off (make-hb_feature_t (->tag #"liga") 0 0 4294967295)) -(define kern_on (tag->hb-feature 'kern)) +(define kern_on (tag->hb-feature #"kern")) (define kern_off (make-hb_feature_t (->tag #"kern") 0 0 4294967295)) -(define onum_on (tag->hb-feature 'onum)) +(define onum_on (tag->hb-feature #"onum")) (define onum_off (make-hb_feature_t (->tag #"onum") 0 0 4294967295)) (define (shape font text [feats null])