From d44cc8a1fc49980532818a2f39f8e6ed1ad30f5e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 15 Oct 2024 13:54:16 -0600 Subject: [PATCH] [coretext-font] Implement get_glyph_name() --- src/hb-coretext-font.cc | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/hb-coretext-font.cc b/src/hb-coretext-font.cc index 8baf42f85..e367300ad 100644 --- a/src/hb-coretext-font.cc +++ b/src/hb-coretext-font.cc @@ -245,6 +245,32 @@ hb_coretext_draw_glyph (hb_font_t *font, } #endif +static hb_bool_t +hb_coretext_get_glyph_name (hb_font_t *font, + void *font_data HB_UNUSED, + hb_codepoint_t glyph, + char *name, unsigned int size, + void *user_data HB_UNUSED) +{ + CGFontRef cg_font = (CGFontRef) (const void *) font->face->data.coretext; + + CGGlyph cg_glyph = glyph; + CFStringRef cf_name = CGFontCopyGlyphNameForGlyph (cg_font, cg_glyph); + if (!cf_name) + return false; + + CFIndex len = CFStringGetLength (cf_name); + if (len > size - 1) + len = size - 1; + + CFStringGetBytes (cf_name, CFRangeMake (0, len), + kCFStringEncodingUTF8, 0, false, + (UInt8 *) name, size, &len); + + name[len] = '\0'; + return true; +} + static hb_bool_t hb_coretext_get_glyph_from_name (hb_font_t *font HB_UNUSED, void *font_data, @@ -300,7 +326,7 @@ static struct hb_coretext_font_funcs_lazy_loader_t : hb_font_funcs_lazy_loader_t hb_font_funcs_set_glyph_extents_func (funcs, hb_coretext_get_glyph_extents, nullptr, nullptr); #ifndef HB_NO_OT_FONT_GLYPH_NAMES - //hb_font_funcs_set_glyph_name_func (funcs, hb_coretext_get_glyph_name, nullptr, nullptr); + hb_font_funcs_set_glyph_name_func (funcs, hb_coretext_get_glyph_name, nullptr, nullptr); hb_font_funcs_set_glyph_from_name_func (funcs, hb_coretext_get_glyph_from_name, nullptr, nullptr); #endif