Add font->has_...() to check for individual nil font funcs

Hopefully this wouldn't break any compiler.  There was some magic
moments to getting this to compile...
This commit is contained in:
Behdad Esfahbod 2015-11-04 21:42:55 -08:00
parent 88e9a9bcae
commit 762770c964
2 changed files with 24 additions and 2 deletions

View File

@ -63,12 +63,13 @@ struct hb_font_funcs_t {
/* Don't access these directly. Call font->get_*() instead. */ /* Don't access these directly. Call font->get_*() instead. */
union { union get_t {
struct { struct get_funcs_t {
#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_func_t name; #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_func_t name;
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
#undef HB_FONT_FUNC_IMPLEMENT #undef HB_FONT_FUNC_IMPLEMENT
} f; } f;
void (*array[]) (void);
} get; } get;
struct { struct {
@ -146,6 +147,20 @@ struct hb_font_t {
/* Public getters */ /* Public getters */
HB_INTERNAL bool has_func (unsigned int i);
/* has_* ... */
#define HB_FONT_FUNC_IMPLEMENT(name) \
bool \
has_##name##_func (void) \
{ \
hb_font_funcs_t *funcs = this->klass; \
unsigned int i = offsetof (hb_font_funcs_t::get_t::get_funcs_t, name) / sizeof (funcs->get.array[0]); \
return has_func (i); \
}
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
#undef HB_FONT_FUNC_IMPLEMENT
inline hb_bool_t has_glyph (hb_codepoint_t unicode) inline hb_bool_t has_glyph (hb_codepoint_t unicode)
{ {
hb_codepoint_t glyph; hb_codepoint_t glyph;

View File

@ -487,6 +487,13 @@ hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
#undef HB_FONT_FUNC_IMPLEMENT #undef HB_FONT_FUNC_IMPLEMENT
bool
hb_font_t::has_func (unsigned int i)
{
if (parent && parent != hb_font_get_empty () && parent->has_func (i))
return true;
return this->klass->get.array[i] != _hb_font_funcs_parent.get.array[i];
}
/* Public getters */ /* Public getters */