diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh index 421bd0209..efc12a822 100644 --- a/src/hb-font-private.hh +++ b/src/hb-font-private.hh @@ -63,12 +63,13 @@ struct hb_font_funcs_t { /* Don't access these directly. Call font->get_*() instead. */ - union { - struct { + union get_t { + struct get_funcs_t { #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_func_t name; HB_FONT_FUNCS_IMPLEMENT_CALLBACKS #undef HB_FONT_FUNC_IMPLEMENT } f; + void (*array[]) (void); } get; struct { @@ -146,6 +147,20 @@ struct hb_font_t { /* 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) { hb_codepoint_t glyph; diff --git a/src/hb-font.cc b/src/hb-font.cc index 9df71c06b..33c644bc9 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -487,6 +487,13 @@ hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \ HB_FONT_FUNCS_IMPLEMENT_CALLBACKS #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 */