src/hb-buffer-private.hh | 18 ++++++++++++++++++ src/hb-buffer-serialize.cc | 3 +++ src/hb-buffer.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/hb-buffer.h | 15 +++++++++++++++ src/hb-ot-layout.cc | 14 ++------------ util/main-font-text.hh | 18 ++++++++++++++++++ 6 files changed, 100 insertions(+), 12 deletions(-)
New commits: commit 0475ef2f97e3035a2eea9a0f96031331e07e8e29 Author: Behdad Esfahbod <[email protected]> Date: Fri Dec 18 18:17:07 2015 +0000 [buffer] Add debugging, aka, message, API Currently just announces lookup applications. Message-API *will* change. hb-shape / hb-view are updated to print-out messages to stder if --debug is specified. diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index 111078c..4983f84 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -124,6 +124,11 @@ struct hb_buffer_t { hb_codepoint_t context[2][CONTEXT_LENGTH]; unsigned int context_len[2]; + /* Debugging */ + hb_buffer_message_func_t message_func; + void *message_data; + hb_destroy_func_t message_destroy; + /* Methods */ @@ -233,6 +238,19 @@ struct hb_buffer_t { inline void clear_context (unsigned int side) { context_len[side] = 0; } HB_INTERNAL void sort (unsigned int start, unsigned int end, int(*compar)(const hb_glyph_info_t *, const hb_glyph_info_t *)); + + inline bool messaging (void) { return unlikely (message_func); } + inline bool message (hb_font_t *font, const char *fmt, ...) HB_PRINTF_FUNC(3, 4) + { + if (!messaging ()) + return true; + va_list ap; + va_start (ap, fmt); + bool ret = message_impl (font, fmt, ap); + va_end (ap); + return ret; + } + HB_INTERNAL bool message_impl (hb_font_t *font, const char *fmt, va_list ap) HB_PRINTF_FUNC(3, 0); }; diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index c271086..764b8ed 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -798,6 +798,8 @@ hb_buffer_destroy (hb_buffer_t *buffer) free (buffer->info); free (buffer->pos); + if (buffer->message_destroy) + buffer->message_destroy (buffer->message_data); free (buffer); } @@ -1713,3 +1715,45 @@ hb_buffer_t::sort (unsigned int start, unsigned int end, int(*compar)(const hb_g } } } + +/* + * Debugging. + */ + +/** + * hb_buffer_set_message_func: + * @buffer: a buffer. + * @func: (closure user_data) (destroy destroy) (scope notified): + * @user_data: + * @destroy: + * + * + * + * Since: 1.1.3 + **/ +void +hb_buffer_set_message_func (hb_buffer_t *buffer, + hb_buffer_message_func_t func, + void *user_data, hb_destroy_func_t destroy) +{ + if (buffer->message_destroy) + buffer->message_destroy (buffer->message_data); + + if (func) { + buffer->message_func = func; + buffer->message_data = user_data; + buffer->message_destroy = destroy; + } else { + buffer->message_func = NULL; + buffer->message_data = NULL; + buffer->message_destroy = NULL; + } +} + +bool +hb_buffer_t::message_impl (hb_font_t *font, const char *fmt, va_list ap) +{ + char buf[100]; + vsnprintf (buf, sizeof (buf), fmt, ap); + return (bool) this->message_func (this, font, buf, this->message_data); +} diff --git a/src/hb-buffer.h b/src/hb-buffer.h index d3a2512..a28d47f 100644 --- a/src/hb-buffer.h +++ b/src/hb-buffer.h @@ -373,6 +373,21 @@ hb_buffer_deserialize_glyphs (hb_buffer_t *buffer, hb_buffer_serialize_format_t format); +/* + * Debugging. + */ + +typedef hb_bool_t (*hb_buffer_message_func_t) (hb_buffer_t *buffer, + hb_font_t *font, + const char *message, + void *user_data); + +HB_EXTERN void +hb_buffer_set_message_func (hb_buffer_t *buffer, + hb_buffer_message_func_t func, + void *user_data, hb_destroy_func_t destroy); + + HB_END_DECLS #endif /* HB_BUFFER_H */ diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 6bb4059..3049fa1 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1014,23 +1014,15 @@ inline void hb_ot_map_t::apply (const Proxy &proxy, const stage_map_t *stage = &stages[table_index][stage_index]; for (; i < stage->last_lookup; i++) { -#if 0 - char buf[4096]; - hb_buffer_serialize_glyphs (buffer, 0, buffer->len, - buf, sizeof (buf), NULL, - font, - HB_BUFFER_SERIALIZE_FORMAT_TEXT, - HB_BUFFER_SERIALIZE_FLAG_DEFAULT); - printf ("buf: [%s]\n", buf); -#endif - unsigned int lookup_index = lookups[table_index][i].index; + if (!buffer->message (font, "start lookup %d", lookup_index)) continue; c.set_lookup_index (lookup_index); c.set_lookup_mask (lookups[table_index][i].mask); c.set_auto_zwj (lookups[table_index][i].auto_zwj); apply_string<Proxy> (&c, proxy.table.get_lookup (lookup_index), proxy.accels[lookup_index]); + (void) buffer->message (font, "end lookup %d", lookup_index); } if (stage->pause_func) diff --git a/util/main-font-text.hh b/util/main-font-text.hh index 7e8bffe..059dde4 100644 --- a/util/main-font-text.hh +++ b/util/main-font-text.hh @@ -46,6 +46,22 @@ locale_to_utf8 (char *s) return t; } +static hb_bool_t +message_func (hb_buffer_t *buffer, + hb_font_t *font, + const char *message, + void *user_data) +{ + fprintf (stderr, "HB: %s\n", message); + char buf[4096]; + hb_buffer_serialize_glyphs (buffer, 0, hb_buffer_get_length (buffer), + buf, sizeof (buf), NULL, + font, + HB_BUFFER_SERIALIZE_FORMAT_TEXT, + HB_BUFFER_SERIALIZE_FLAG_DEFAULT); + printf ("HB: buffer [%s]\n", buf); + return true; +} template <typename consumer_t, int default_font_size, int subpixel_bits> struct main_font_text_t @@ -74,6 +90,8 @@ struct main_font_text_t consumer.init (&font_opts); hb_buffer_t *buffer = hb_buffer_create (); + if (debug) + hb_buffer_set_message_func (buffer, message_func, NULL, NULL); unsigned int text_len; const char *text; while ((text = input.get_line (&text_len))) commit 9ea0aa43ac5cf243b698aae0ec80241b5efd7488 Author: Behdad Esfahbod <[email protected]> Date: Fri Dec 18 17:30:18 2015 +0000 Don't deserialize positions if buffer has no positions diff --git a/src/hb-buffer-serialize.cc b/src/hb-buffer-serialize.cc index 7839cbc..2dc146a 100644 --- a/src/hb-buffer-serialize.cc +++ b/src/hb-buffer-serialize.cc @@ -282,6 +282,9 @@ hb_buffer_serialize_glyphs (hb_buffer_t *buffer, assert ((!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID) || buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS); + if (!buffer->have_positions) + flags |= HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS; + if (unlikely (start == end)) return 0; diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index b0257f6..6bb4059 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1020,8 +1020,6 @@ inline void hb_ot_map_t::apply (const Proxy &proxy, buf, sizeof (buf), NULL, font, HB_BUFFER_SERIALIZE_FORMAT_TEXT, - Proxy::table_index == 0 ? - HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS : HB_BUFFER_SERIALIZE_FLAG_DEFAULT); printf ("buf: [%s]\n", buf); #endif _______________________________________________ HarfBuzz mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/harfbuzz
