From 27a25f2d3d1a0aacbf7f13ae478ed37eac44baa9 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 11 Feb 2025 23:10:43 +0000 Subject: [PATCH] [coretext] Copy variations when creating hb-font https://github.com/harfbuzz/harfbuzz/issues/3159#issuecomment-2652262262 --- src/hb-coretext-shape.cc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/hb-coretext-shape.cc b/src/hb-coretext-shape.cc index 90d7116c4..f744038d1 100644 --- a/src/hb-coretext-shape.cc +++ b/src/hb-coretext-shape.cc @@ -519,6 +519,35 @@ hb_coretext_font_create (CTFontRef ct_font) hb_font_set_ptem (font, CTFontGetSize (ct_font)); + /* Copy font variations */ + CFDictionaryRef variations = CTFontCopyVariation (ct_font); + if (variations) + { + CFIndex count = CFDictionaryGetCount (variations); + // Fetch them one by one and collect in a vector of our own. + const void *keys; + const void *values; + CFDictionaryGetKeysAndValues (variations, &keys, &values); + + hb_vector_t vars; + for (CFIndex i = 0; i < count; i++) + { + CFNumberRef tag_number = (CFNumberRef) CFArrayGetValueAtIndex ((CFArrayRef) keys, i); + CFNumberRef value_number = (CFNumberRef) CFArrayGetValueAtIndex ((CFArrayRef) values, i); + + int tag; + float value; + CFNumberGetValue (tag_number, kCFNumberIntType, &tag); + CFNumberGetValue (value_number, kCFNumberFloatType, &value); + + hb_variation_t var = {tag, value}; + vars.push (var); + } + hb_font_set_variations (font, vars.arrayZ, vars.length); + + CFRelease (variations); + } + /* Let there be dragons here... */ font->data.coretext.cmpexch (nullptr, (hb_coretext_font_data_t *) CFRetain (ct_font));