diff --git a/src/hb-coretext-shape.cc b/src/hb-coretext-shape.cc index 3056397f7..e4bebceea 100644 --- a/src/hb-coretext-shape.cc +++ b/src/hb-coretext-shape.cc @@ -123,94 +123,6 @@ _hb_coretext_shaper_font_data_destroy (hb_coretext_font_data_t *data) CFRelease ((CTFontRef) data); } -/** - * hb_coretext_font_create: - * @ct_font: The CTFontRef to work upon - * - * Creates an #hb_font_t font object from the specified - * CTFontRef. - * - * The created font uses the default font functions implemented - * natively by HarfBuzz. If you want to use the CoreText font functions - * instead (rarely needed), you can do so by calling - * by hb_coretext_font_set_funcs(). - * - * Return value: (transfer full): The new font object - * - * Since: 1.7.2 - **/ -hb_font_t * -hb_coretext_font_create (CTFontRef ct_font) -{ - CGFontRef cg_font = CTFontCopyGraphicsFont (ct_font, nullptr); - hb_face_t *face = hb_coretext_face_create (cg_font); - CFRelease (cg_font); - hb_font_t *font = hb_font_create (face); - hb_face_destroy (face); - - if (unlikely (hb_object_is_immutable (font))) - return font; - - hb_font_set_ptem (font, CTFontGetSize (ct_font)); - - /* Copy font variations */ - CFDictionaryRef variations = CTFontCopyVariation (ct_font); - if (variations) - { - hb_vector_t vars; - hb_vector_t keys; - hb_vector_t values; - - CFIndex count = CFDictionaryGetCount (variations); - if (unlikely (!vars.alloc_exact (count) || !keys.resize_exact (count) || !values.resize_exact (count))) - goto done; - - // Fetch them one by one and collect in a vector of our own. - CFDictionaryGetKeysAndValues (variations, keys.arrayZ, values.arrayZ); - for (CFIndex i = 0; i < count; i++) - { - int tag; - float value; - CFNumberGetValue ((CFNumberRef) keys.arrayZ[i], kCFNumberIntType, &tag); - CFNumberGetValue ((CFNumberRef) values.arrayZ[i], kCFNumberFloatType, &value); - - hb_variation_t var = {tag, value}; - vars.push (var); - } - hb_font_set_variations (font, vars.arrayZ, vars.length); - -done: - CFRelease (variations); - } - - /* Let there be dragons here... */ - font->data.coretext.cmpexch (nullptr, (hb_coretext_font_data_t *) CFRetain (ct_font)); - - // https://github.com/harfbuzz/harfbuzz/pull/4895#issuecomment-2408471254 - //hb_coretext_font_set_funcs (font); - - return font; -} - -/** - * hb_coretext_font_get_ct_font: - * @font: #hb_font_t to work upon - * - * Fetches the CTFontRef associated with the specified - * #hb_font_t font object. - * - * Return value: the CTFontRef found - * - * Since: 0.9.10 - */ -CTFontRef -hb_coretext_font_get_ct_font (hb_font_t *font) -{ - CTFontRef ct_font = (CTFontRef) (const void *) font->data.coretext; - return ct_font ? (CTFontRef) ct_font : nullptr; -} - - /* * shaper */ diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index da7645bce..a1bfc2eb7 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -453,4 +453,92 @@ hb_coretext_face_get_cg_font (hb_face_t *face) return (CGFontRef) (const void *) face->data.coretext; } +/** + * hb_coretext_font_create: + * @ct_font: The CTFontRef to work upon + * + * Creates an #hb_font_t font object from the specified + * CTFontRef. + * + * The created font uses the default font functions implemented + * natively by HarfBuzz. If you want to use the CoreText font functions + * instead (rarely needed), you can do so by calling + * by hb_coretext_font_set_funcs(). + * + * Return value: (transfer full): The new font object + * + * Since: 1.7.2 + **/ +hb_font_t * +hb_coretext_font_create (CTFontRef ct_font) +{ + CGFontRef cg_font = CTFontCopyGraphicsFont (ct_font, nullptr); + hb_face_t *face = hb_coretext_face_create (cg_font); + CFRelease (cg_font); + hb_font_t *font = hb_font_create (face); + hb_face_destroy (face); + + if (unlikely (hb_object_is_immutable (font))) + return font; + + hb_font_set_ptem (font, CTFontGetSize (ct_font)); + + /* Copy font variations */ + CFDictionaryRef variations = CTFontCopyVariation (ct_font); + if (variations) + { + hb_vector_t vars; + hb_vector_t keys; + hb_vector_t values; + + CFIndex count = CFDictionaryGetCount (variations); + if (unlikely (!vars.alloc_exact (count) || !keys.resize_exact (count) || !values.resize_exact (count))) + goto done; + + // Fetch them one by one and collect in a vector of our own. + CFDictionaryGetKeysAndValues (variations, keys.arrayZ, values.arrayZ); + for (CFIndex i = 0; i < count; i++) + { + int tag; + float value; + CFNumberGetValue ((CFNumberRef) keys.arrayZ[i], kCFNumberIntType, &tag); + CFNumberGetValue ((CFNumberRef) values.arrayZ[i], kCFNumberFloatType, &value); + + hb_variation_t var = {tag, value}; + vars.push (var); + } + hb_font_set_variations (font, vars.arrayZ, vars.length); + +done: + CFRelease (variations); + } + + /* Let there be dragons here... */ + font->data.coretext.cmpexch (nullptr, (hb_coretext_font_data_t *) CFRetain (ct_font)); + + // https://github.com/harfbuzz/harfbuzz/pull/4895#issuecomment-2408471254 + //hb_coretext_font_set_funcs (font); + + return font; +} + +/** + * hb_coretext_font_get_ct_font: + * @font: #hb_font_t to work upon + * + * Fetches the CTFontRef associated with the specified + * #hb_font_t font object. + * + * Return value: the CTFontRef found + * + * Since: 0.9.10 + */ +CTFontRef +hb_coretext_font_get_ct_font (hb_font_t *font) +{ + CTFontRef ct_font = (CTFontRef) (const void *) font->data.coretext; + return ct_font ? (CTFontRef) ct_font : nullptr; +} + + #endif