[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.
This commit is contained in:
Behdad Esfahbod 2015-12-18 18:17:07 +00:00
parent 9ea0aa43ac
commit 0475ef2f97
5 changed files with 97 additions and 10 deletions

View File

@ -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);
};

View File

@ -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);
}

View File

@ -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 */

View File

@ -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)

View File

@ -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)))