From f6bf9f697e58ac14035002cb5bebe329ddc8351a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 9 Feb 2025 03:52:13 +0000 Subject: [PATCH] [coretext-font] Do early-return in get_nominal_glyphs() Related to https://github.com/harfbuzz/harfbuzz/issues/5056 --- src/hb-coretext-font.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/hb-coretext-font.cc b/src/hb-coretext-font.cc index 4f5a02014..6f74cd13c 100644 --- a/src/hb-coretext-font.cc +++ b/src/hb-coretext-font.cc @@ -136,7 +136,16 @@ hb_coretext_get_nominal_glyphs (hb_font_t *font HB_UNUSED, ch[j] = *first_unicode; first_unicode = &StructAtOffset (first_unicode, unicode_stride); } - CTFontGetGlyphsForCharacters (ct_font, ch, cg_glyph, c); + if (unlikely (!CTFontGetGlyphsForCharacters (ct_font, ch, cg_glyph, c))) + { + // Use slow path partially and return at first failure. + for (unsigned j = 0; j < c; j++) + { + if (!hb_coretext_get_nominal_glyph (font, font_data, ch[j], first_glyph, nullptr)) + return i + j; + first_glyph = &StructAtOffset (first_glyph, glyph_stride); + } + } for (unsigned j = 0; j < c; j++) { *first_glyph = cg_glyph[j];