From 762770c964f9f0591bf4c44427f73ea3e1c51733 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 4 Nov 2015 21:42:55 -0800 Subject: [PATCH] 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... --- src/hb-font-private.hh | 19 +++++++++++++++++-- src/hb-font.cc | 7 +++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh index 421bd02..efc12a8 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 9df71c0..33c644b 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 */ -- 2.7.4