Add font->has_...() to check for individual nil font funcs
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 5 Nov 2015 05:42:55 +0000 (21:42 -0800)
committerBehdad Esfahbod <behdad@behdad.org>
Thu, 5 Nov 2015 05:49:19 +0000 (21:49 -0800)
Hopefully this wouldn't break any compiler.  There was some magic
moments to getting this to compile...

src/hb-font-private.hh
src/hb-font.cc

index 421bd02..efc12a8 100644 (file)
@@ -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;
index 9df71c0..33c644b 100644 (file)
@@ -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 */