mirror of
https://github.com/harfbuzz/harfbuzz.git
synced 2025-04-17 02:35:52 +00:00
[coretext] Move more code around
This commit is contained in:
parent
471ac1cdc0
commit
7e4698abe2
2 changed files with 88 additions and 88 deletions
|
@ -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<hb_variation_t> vars;
|
||||
hb_vector_t<CFTypeRef> keys;
|
||||
hb_vector_t<CFTypeRef> 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
|
||||
*/
|
||||
|
|
|
@ -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<hb_variation_t> vars;
|
||||
hb_vector_t<CFTypeRef> keys;
|
||||
hb_vector_t<CFTypeRef> 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
|
||||
|
|
Loading…
Add table
Reference in a new issue