[coretext] Add hb_coretext_font_create()

Fixes https://github.com/harfbuzz/harfbuzz/issues/628

New API:
hb_coretext_font_create()
This commit is contained in:
Behdad Esfahbod 2017-11-28 23:11:34 -08:00
parent 9d0194b3a8
commit d5e29303db
2 changed files with 38 additions and 20 deletions

View File

@ -81,21 +81,12 @@ _hb_cg_font_release (void *data)
CGFontRelease ((CGFontRef) data);
}
hb_face_t *
hb_coretext_face_create (CGFontRef cg_font)
{
return hb_face_create_for_tables (reference_table, CGFontRetain (cg_font), _hb_cg_font_release);
}
HB_SHAPER_DATA_ENSURE_DEFINE(coretext, face)
HB_SHAPER_DATA_ENSURE_DEFINE_WITH_CONDITION(coretext, font,
fabs (CTFontGetSize((CTFontRef) data) - coretext_font_size (font->ptem)) <= .5
)
/*
* shaper face data
*/
static CTFontDescriptorRef
get_last_resort_font_desc (void)
{
@ -267,6 +258,12 @@ _hb_coretext_shaper_face_data_destroy (hb_coretext_shaper_face_data_t *data)
CFRelease ((CGFontRef) data);
}
hb_face_t *
hb_coretext_face_create (CGFontRef cg_font)
{
return hb_face_create_for_tables (reference_table, CGFontRetain (cg_font), _hb_cg_font_release);
}
/*
* Since: 0.9.10
*/
@ -278,10 +275,6 @@ hb_coretext_face_get_cg_font (hb_face_t *face)
}
/*
* shaper font data
*/
hb_coretext_shaper_font_data_t *
_hb_coretext_shaper_font_data_create (hb_font_t *font)
{
@ -306,6 +299,35 @@ _hb_coretext_shaper_font_data_destroy (hb_coretext_shaper_font_data_t *data)
CFRelease ((CTFontRef) data);
}
/*
* Since: 1.7.2
*/
hb_font_t *
hb_coretext_font_create (CTFontRef ct_font)
{
CGFontRef cg_font = CTFontCopyGraphicsFont (ct_font, 0);
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_inert (font)))
return font;
/* Let there be dragons here... */
HB_SHAPER_DATA_GET (font) = (hb_coretext_shaper_font_data_t *) CFRetain (ct_font);
return font;
}
CTFontRef
hb_coretext_font_get_ct_font (hb_font_t *font)
{
if (unlikely (!hb_coretext_shaper_font_data_ensure (font))) return nullptr;
return (CTFontRef) HB_SHAPER_DATA_GET (font);
}
/*
* shaper shape_plan data
@ -328,13 +350,6 @@ _hb_coretext_shaper_shape_plan_data_destroy (hb_coretext_shaper_shape_plan_data_
{
}
CTFontRef
hb_coretext_font_get_ct_font (hb_font_t *font)
{
if (unlikely (!hb_coretext_shaper_font_data_ensure (font))) return nullptr;
return (CTFontRef)HB_SHAPER_DATA_GET (font);
}
/*
* shaper

View File

@ -48,6 +48,9 @@ HB_BEGIN_DECLS
HB_EXTERN hb_face_t *
hb_coretext_face_create (CGFontRef cg_font);
HB_EXTERN hb_font_t *
hb_coretext_font_create (CTFontRef ct_font);
HB_EXTERN CGFontRef
hb_coretext_face_get_cg_font (hb_face_t *face);