From f7456c764a2dd5244263c63352141d73d0b009b3 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 16 May 2019 10:53:28 -0700 Subject: [PATCH] check for multiple glyphs per codepoint --- fontland/fontland/font.rkt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fontland/fontland/font.rkt b/fontland/fontland/font.rkt index eb238f6b..ffcfaf76 100644 --- a/fontland/fontland/font.rkt +++ b/fontland/fontland/font.rkt @@ -9,6 +9,7 @@ "table-stream.rkt" xenomorph racket/match + racket/list sugar/unstable/dict "unsafe/harfbuzz.rkt" "glyph-position.rkt" @@ -92,7 +93,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js (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))) + ;; `remove-duplicates` in case we get a funny codepoint that expands into multiple glyphs (rare but possible) + (define hb-clusters (break-at codepoints (remove-duplicates (map hb_glyph_info_t-cluster gis) eq?))) (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)])