More code shuffling
authorBehdad Esfahbod <behdad@behdad.org>
Fri, 8 Jul 2011 03:14:42 +0000 (23:14 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Fri, 8 Jul 2011 03:14:42 +0000 (23:14 -0400)
src/hb-font-private.hh
src/hb-font.cc
src/hb-unicode-private.hh
src/hb-unicode.cc

index b170c9d..dd71b67 100644 (file)
@@ -41,13 +41,6 @@ HB_BEGIN_DECLS
  * hb_font_funcs_t
  */
 
-struct _hb_font_funcs_t {
-  hb_object_header_t header;
-
-  hb_bool_t immutable;
-
-  /* Don't access these directly.  Call hb_font_get_*() instead. */
-
 #define HB_FONT_FUNCS_IMPLEMENT_CALLBACKS \
   HB_FONT_FUNC_IMPLEMENT (glyph) \
   HB_FONT_FUNC_IMPLEMENT (glyph_h_advance) \
@@ -57,8 +50,15 @@ struct _hb_font_funcs_t {
   HB_FONT_FUNC_IMPLEMENT (glyph_h_kerning) \
   HB_FONT_FUNC_IMPLEMENT (glyph_v_kerning) \
   HB_FONT_FUNC_IMPLEMENT (glyph_extents) \
-  HB_FONT_FUNC_IMPLEMENT (glyph_contour_point)
+  HB_FONT_FUNC_IMPLEMENT (glyph_contour_point) \
+  /* ^--- Add new callbacks here */
 
+struct _hb_font_funcs_t {
+  hb_object_header_t header;
+
+  hb_bool_t immutable;
+
+  /* Don't access these directly.  Call hb_font_get_*() instead. */
 
   struct {
 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_func_t name;
index 27ec005..0406e10 100644 (file)
@@ -236,7 +236,8 @@ hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
 {
   if (!hb_object_destroy (ffuncs)) return;
 
-#define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) ffuncs->destroy.name (ffuncs->user_data.name);
+#define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
+  ffuncs->destroy.name (ffuncs->user_data.name);
   HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
 #undef HB_FONT_FUNC_IMPLEMENT
 
index 34da030..1f0e490 100644 (file)
@@ -43,6 +43,14 @@ HB_BEGIN_DECLS
  * hb_unicode_funcs_t
  */
 
+#define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS \
+  HB_UNICODE_FUNC_IMPLEMENT (unsigned int, combining_class, 0) \
+  HB_UNICODE_FUNC_IMPLEMENT (unsigned int, eastasian_width, 1) \
+  HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_general_category_t, general_category, HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER) \
+  HB_UNICODE_FUNC_IMPLEMENT (hb_codepoint_t, mirroring, unicode) \
+  HB_UNICODE_FUNC_IMPLEMENT (hb_script_t, script, HB_SCRIPT_UNKNOWN) \
+  /* ^--- Add new callbacks here */
+
 struct _hb_unicode_funcs_t {
   hb_object_header_t header;
 
@@ -50,43 +58,33 @@ struct _hb_unicode_funcs_t {
 
   bool immutable;
 
-#define IMPLEMENT(return_type, name) \
+#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name, default_value) \
   inline return_type \
   get_##name (hb_codepoint_t unicode) \
   { return this->get.name (this, unicode, this->user_data.name); }
 
-  IMPLEMENT (unsigned int, combining_class)
-  IMPLEMENT (unsigned int, eastasian_width)
-  IMPLEMENT (hb_unicode_general_category_t, general_category)
-  IMPLEMENT (hb_codepoint_t, mirroring)
-  IMPLEMENT (hb_script_t, script)
+  HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
 
-#undef IMPLEMENT
+#undef HB_UNICODE_FUNC_IMPLEMENT
 
   /* Don't access these directly.  Call get_*() instead. */
 
   struct {
-    hb_unicode_get_combining_class_func_t      combining_class;
-    hb_unicode_get_eastasian_width_func_t      eastasian_width;
-    hb_unicode_get_general_category_func_t     general_category;
-    hb_unicode_get_mirroring_func_t            mirroring;
-    hb_unicode_get_script_func_t               script;
+#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name, default_value) hb_unicode_get_##name##_func_t name;
+    HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
+#undef HB_UNICODE_FUNC_IMPLEMENT
   } get;
 
   struct {
-    void                                       *combining_class;
-    void                                       *eastasian_width;
-    void                                       *general_category;
-    void                                       *mirroring;
-    void                                       *script;
+#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name, default_value) void *name;
+    HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
+#undef HB_UNICODE_FUNC_IMPLEMENT
   } user_data;
 
   struct {
-    hb_destroy_func_t                          combining_class;
-    hb_destroy_func_t                          eastasian_width;
-    hb_destroy_func_t                          general_category;
-    hb_destroy_func_t                          mirroring;
-    hb_destroy_func_t                          script;
+#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name, default_value) hb_destroy_func_t name;
+    HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
+#undef HB_UNICODE_FUNC_IMPLEMENT
   } destroy;
 };
 
index c2d7311..8ca178e 100644 (file)
@@ -39,45 +39,19 @@ HB_BEGIN_DECLS
  * hb_unicode_funcs_t
  */
 
-static unsigned int
-hb_unicode_get_combining_class_nil (hb_unicode_funcs_t *ufuncs    HB_UNUSED,
-                                   hb_codepoint_t      unicode   HB_UNUSED,
-                                   void               *user_data HB_UNUSED)
-{
-  return 0;
-}
-
-static unsigned int
-hb_unicode_get_eastasian_width_nil (hb_unicode_funcs_t *ufuncs    HB_UNUSED,
-                                   hb_codepoint_t      unicode   HB_UNUSED,
-                                   void               *user_data HB_UNUSED)
-{
-  return 1;
+#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name, default_value)            \
+                                                                               \
+                                                                               \
+static return_type                                                             \
+hb_unicode_get_##name##_nil (hb_unicode_funcs_t *ufuncs    HB_UNUSED,          \
+                            hb_codepoint_t      unicode   HB_UNUSED,           \
+                            void               *user_data HB_UNUSED)           \
+{                                                                              \
+  return default_value;                                                                \
 }
 
-static hb_unicode_general_category_t
-hb_unicode_get_general_category_nil (hb_unicode_funcs_t *ufuncs    HB_UNUSED,
-                                    hb_codepoint_t      unicode   HB_UNUSED,
-                                    void               *user_data HB_UNUSED)
-{
-  return HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER;
-}
-
-static hb_codepoint_t
-hb_unicode_get_mirroring_nil (hb_unicode_funcs_t *ufuncs    HB_UNUSED,
-                             hb_codepoint_t      unicode   HB_UNUSED,
-                             void               *user_data HB_UNUSED)
-{
-  return unicode;
-}
-
-static hb_script_t
-hb_unicode_get_script_nil (hb_unicode_funcs_t *ufuncs    HB_UNUSED,
-                          hb_codepoint_t      unicode   HB_UNUSED,
-                          void               *user_data HB_UNUSED)
-{
-  return HB_SCRIPT_UNKNOWN;
-}
+  HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
+#undef HB_UNICODE_FUNC_IMPLEMENT
 
 
 hb_unicode_funcs_t _hb_unicode_funcs_nil = {
@@ -86,11 +60,9 @@ hb_unicode_funcs_t _hb_unicode_funcs_nil = {
   NULL, /* parent */
   TRUE, /* immutable */
   {
-    hb_unicode_get_combining_class_nil,
-    hb_unicode_get_eastasian_width_nil,
-    hb_unicode_get_general_category_nil,
-    hb_unicode_get_mirroring_nil,
-    hb_unicode_get_script_nil,
+#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name, default_value) hb_unicode_get_##name##_nil,
+    HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
+#undef HB_UNICODE_FUNC_IMPLEMENT
   }
 };
 
@@ -142,13 +114,10 @@ hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs)
 {
   if (!hb_object_destroy (ufuncs)) return;
 
-#define DESTROY(name) if (ufuncs->destroy.name) ufuncs->destroy.name (ufuncs->user_data.name)
-  DESTROY (combining_class);
-  DESTROY (eastasian_width);
-  DESTROY (general_category);
-  DESTROY (mirroring);
-  DESTROY (script);
-#undef DESTROY
+#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name, default_value) \
+  if (ufuncs->destroy.name) ufuncs->destroy.name (ufuncs->user_data.name);
+    HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
+#undef HB_UNICODE_FUNC_IMPLEMENT
 
   hb_unicode_funcs_destroy (ufuncs->parent);
 
@@ -194,45 +163,40 @@ hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs)
 }
 
 
-#define IMPLEMENT(return_type, name)                                           \
-                                                                               \
-void                                                                           \
-hb_unicode_funcs_set_##name##_func (hb_unicode_funcs_t             *ufuncs,    \
-                                    hb_unicode_get_##name##_func_t  func,      \
-                                    void                           *user_data, \
-                                    hb_destroy_func_t               destroy)   \
-{                                                                              \
-  if (ufuncs->immutable)                                                       \
-    return;                                                                    \
-                                                                               \
-  if (ufuncs->destroy.name)                                                    \
-    ufuncs->destroy.name (ufuncs->user_data.name);                             \
-                                                                               \
-  if (func) {                                                                  \
-    ufuncs->get.name = func;                                                   \
-    ufuncs->user_data.name = user_data;                                        \
-    ufuncs->destroy.name = destroy;                                            \
-  } else {                                                                     \
-    ufuncs->get.name = ufuncs->parent->get.name;                               \
-    ufuncs->user_data.name = ufuncs->parent->user_data.name;                   \
-    ufuncs->destroy.name = NULL;                                               \
-  }                                                                            \
-}                                                                              \
-                                                                               \
-return_type                                                                    \
-hb_unicode_get_##name (hb_unicode_funcs_t *ufuncs,                             \
-                      hb_codepoint_t      unicode)                            \
-{                                                                              \
-  return ufuncs->get.name (ufuncs, unicode, ufuncs->user_data.name);           \
-}
-
-IMPLEMENT (unsigned int, combining_class)
-IMPLEMENT (unsigned int, eastasian_width)
-IMPLEMENT (hb_unicode_general_category_t, general_category)
-IMPLEMENT (hb_codepoint_t, mirroring)
-IMPLEMENT (hb_script_t, script)
-
-#undef IMPLEMENT
+#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name, default_value)            \
+                                                                               \
+void                                                                           \
+hb_unicode_funcs_set_##name##_func (hb_unicode_funcs_t            *ufuncs,     \
+                                   hb_unicode_get_##name##_func_t  func,       \
+                                   void                           *user_data,  \
+                                   hb_destroy_func_t               destroy)    \
+{                                                                              \
+  if (ufuncs->immutable)                                                       \
+    return;                                                                    \
+                                                                               \
+  if (ufuncs->destroy.name)                                                    \
+    ufuncs->destroy.name (ufuncs->user_data.name);                             \
+                                                                               \
+  if (func) {                                                                  \
+    ufuncs->get.name = func;                                                   \
+    ufuncs->user_data.name = user_data;                                                \
+    ufuncs->destroy.name = destroy;                                            \
+  } else {                                                                     \
+    ufuncs->get.name = ufuncs->parent->get.name;                               \
+    ufuncs->user_data.name = ufuncs->parent->user_data.name;                   \
+    ufuncs->destroy.name = NULL;                                               \
+  }                                                                            \
+}                                                                              \
+                                                                               \
+return_type                                                                    \
+hb_unicode_get_##name (hb_unicode_funcs_t *ufuncs,                             \
+                      hb_codepoint_t      unicode)                             \
+{                                                                              \
+  return ufuncs->get.name (ufuncs, unicode, ufuncs->user_data.name);           \
+}
+
+    HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
+#undef HB_UNICODE_FUNC_IMPLEMENT
 
 
 HB_END_DECLS