From 3fb90cae5af1aa8a6eb2dba31b8baf43bd684932 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 30 Dec 2018 18:30:21 -0800 Subject: [PATCH] expose shaping args --- fontland/fontland/font.rkt | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/fontland/fontland/font.rkt b/fontland/fontland/font.rkt index 91748119..5c0e20b6 100644 --- a/fontland/fontland/font.rkt +++ b/fontland/fontland/font.rkt @@ -73,23 +73,28 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js ;; (though this is good news, as it avoids massive disk caches hanging around) ;; ram cache in pitfall suffices -;; todo: preserve semantics of user-features argument from pitfall, which is -;; #f = no features, null = default features, list = explicit features -(define (layout font str [features #f] [script #f] [language #f]) +(define (layout font str + [features null] + [script 'HB_SCRIPT_LATIN] + [lang #"en"] + [direction 'HB_DIRECTION_LTR]) (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) (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 (or features null))) + (hb_shape (hb-font font) buf (map tag->hb-feature 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))) (define hb-positions (map hb_glyph_position_t->list (hb_buffer_get_glyph_positions buf))) (define glyphs (for/vector ([gidx (in-list hb-gids)] - [cluster (in-list hb-clusters)]) - (get-glyph font gidx cluster))) + [cluster (in-list hb-clusters)]) + (get-glyph font gidx cluster))) (define positions (for/vector ([posn (in-list hb-positions)]) - (apply +glyph-position posn))) + (apply +glyph-position posn))) (glyphrun glyphs positions)) @@ -124,8 +129,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/base.js ;; rather than use a `probe` function, ;; just try making a font with each format and see what happens (for/first ([font-format (in-list font-formats)]) - (with-handlers ([probe-fail? (λ (exn) #f)]) - (font-format port))) + (with-handlers ([probe-fail? (λ (exn) #f)]) + (font-format port))) (error 'create-font "unknown font format"))) (module+ test