diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 79e70b8cc..e5c4c0dc3 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -154,6 +154,19 @@ ASSERT_STATIC (Type::min_size + 1 <= sizeof (_Null##Type)) #define Null(Type) Null() +/* + * Dispatch + */ + +template +struct hb_dispatch_context_t +{ + static const unsigned int max_debug_depth = MaxDebugDepth; + typedef Return return_t; + template + inline bool may_dispatch (const T *obj, const F *format) { return true; } +}; + /* * Sanitize @@ -174,11 +187,16 @@ ASSERT_STATIC (Type::min_size + 1 <= sizeof (_Null##Type)) #define HB_SANITIZE_MAX_EDITS 100 #endif -struct hb_sanitize_context_t +struct hb_sanitize_context_t : + hb_dispatch_context_t { + inline hb_sanitize_context_t (void) : + debug_depth (0), + start (NULL), end (NULL), + writable (false), edit_count (0), + blob (NULL) {} + inline const char *get_name (void) { return "SANITIZE"; } - static const unsigned int max_debug_depth = HB_DEBUG_SANITIZE; - typedef bool return_t; template inline bool may_dispatch (const T *obj, const F *format) { return format->sanitize (this); } @@ -295,7 +313,7 @@ template struct Sanitizer { static hb_blob_t *sanitize (hb_blob_t *blob) { - hb_sanitize_context_t c[1] = {{0, NULL, NULL, false, 0, NULL}}; + hb_sanitize_context_t c[1]; bool sane; /* TODO is_sane() stuff */ diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index 6cf1ffca7..65e39a607 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -46,14 +46,11 @@ namespace OT { (&c->debug_depth, c->get_name (), this, HB_FUNC, \ ""); -struct hb_closure_context_t +struct hb_closure_context_t : + hb_dispatch_context_t { inline const char *get_name (void) { return "CLOSURE"; } - static const unsigned int max_debug_depth = HB_DEBUG_CLOSURE; - typedef hb_void_t return_t; typedef return_t (*recurse_func_t) (hb_closure_context_t *c, unsigned int lookup_index); - template - inline bool may_dispatch (const T *obj, const F *format) { return true; } template inline return_t dispatch (const T &obj) { obj.closure (this); return HB_VOID; } static return_t default_return_value (void) { return HB_VOID; } @@ -98,13 +95,10 @@ struct hb_closure_context_t (&c->debug_depth, c->get_name (), this, HB_FUNC, \ "%d glyphs", c->len); -struct hb_would_apply_context_t +struct hb_would_apply_context_t : + hb_dispatch_context_t { inline const char *get_name (void) { return "WOULD_APPLY"; } - static const unsigned int max_debug_depth = HB_DEBUG_WOULD_APPLY; - typedef bool return_t; - template - inline bool may_dispatch (const T *obj, const F *format) { return true; } template inline return_t dispatch (const T &obj) { return obj.would_apply (this); } static return_t default_return_value (void) { return false; } @@ -138,14 +132,11 @@ struct hb_would_apply_context_t (&c->debug_depth, c->get_name (), this, HB_FUNC, \ ""); -struct hb_collect_glyphs_context_t +struct hb_collect_glyphs_context_t : + hb_dispatch_context_t { inline const char *get_name (void) { return "COLLECT_GLYPHS"; } - static const unsigned int max_debug_depth = HB_DEBUG_COLLECT_GLYPHS; - typedef hb_void_t return_t; typedef return_t (*recurse_func_t) (hb_collect_glyphs_context_t *c, unsigned int lookup_index); - template - inline bool may_dispatch (const T *obj, const F *format) { return true; } template inline return_t dispatch (const T &obj) { obj.collect_glyphs (this); return HB_VOID; } static return_t default_return_value (void) { return HB_VOID; } @@ -232,14 +223,14 @@ struct hb_collect_glyphs_context_t #define HB_DEBUG_GET_COVERAGE (HB_DEBUG+0) #endif +/* XXX Can we remove this? */ + template -struct hb_add_coverage_context_t +struct hb_add_coverage_context_t : + hb_dispatch_context_t, const Coverage &, HB_DEBUG_GET_COVERAGE> { inline const char *get_name (void) { return "GET_COVERAGE"; } - static const unsigned int max_debug_depth = HB_DEBUG_GET_COVERAGE; typedef const Coverage &return_t; - template - inline bool may_dispatch (const T *obj, const F *format) { return true; } template inline return_t dispatch (const T &obj) { return obj.get_coverage (); } static return_t default_return_value (void) { return Null(Coverage); } @@ -269,7 +260,8 @@ struct hb_add_coverage_context_t "idx %d gid %u lookup %d", \ c->buffer->idx, c->buffer->cur().codepoint, (int) c->lookup_index); -struct hb_apply_context_t +struct hb_apply_context_t : + hb_dispatch_context_t { struct matcher_t { @@ -449,11 +441,7 @@ struct hb_apply_context_t inline const char *get_name (void) { return "APPLY"; } - static const unsigned int max_debug_depth = HB_DEBUG_APPLY; - typedef bool return_t; typedef return_t (*recurse_func_t) (hb_apply_context_t *c, unsigned int lookup_index); - template - inline bool may_dispatch (const T *obj, const F *format) { return true; } template inline return_t dispatch (const T &obj) { return obj.apply (this); } static return_t default_return_value (void) { return false; } diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 1a6fb15ee..275a960d5 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -28,6 +28,7 @@ * Google Author(s): Behdad Esfahbod */ +#include "hb-open-type-private.hh" #include "hb-ot-layout-private.hh" #include "hb-ot-layout-gdef-table.hh" @@ -925,13 +926,10 @@ apply_backward (OT::hb_apply_context_t *c, return ret; } -struct hb_apply_forward_context_t +struct hb_apply_forward_context_t : + OT::hb_dispatch_context_t { inline const char *get_name (void) { return "APPLY_FWD"; } - static const unsigned int max_debug_depth = HB_DEBUG_APPLY; - typedef bool return_t; - template - inline bool may_dispatch (const T *obj, const F *format) { return true; } template inline return_t dispatch (const T &obj) { return apply_forward (c, obj, accel); } static return_t default_return_value (void) { return false; }