[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:
parent
9ea0aa43ac
commit
0475ef2f97
|
@ -124,6 +124,11 @@ struct hb_buffer_t {
|
||||||
hb_codepoint_t context[2][CONTEXT_LENGTH];
|
hb_codepoint_t context[2][CONTEXT_LENGTH];
|
||||||
unsigned int context_len[2];
|
unsigned int context_len[2];
|
||||||
|
|
||||||
|
/* Debugging */
|
||||||
|
hb_buffer_message_func_t message_func;
|
||||||
|
void *message_data;
|
||||||
|
hb_destroy_func_t message_destroy;
|
||||||
|
|
||||||
|
|
||||||
/* Methods */
|
/* Methods */
|
||||||
|
|
||||||
|
@ -233,6 +238,19 @@ struct hb_buffer_t {
|
||||||
inline void clear_context (unsigned int side) { context_len[side] = 0; }
|
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 *));
|
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -798,6 +798,8 @@ hb_buffer_destroy (hb_buffer_t *buffer)
|
||||||
|
|
||||||
free (buffer->info);
|
free (buffer->info);
|
||||||
free (buffer->pos);
|
free (buffer->pos);
|
||||||
|
if (buffer->message_destroy)
|
||||||
|
buffer->message_destroy (buffer->message_data);
|
||||||
|
|
||||||
free (buffer);
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -373,6 +373,21 @@ hb_buffer_deserialize_glyphs (hb_buffer_t *buffer,
|
||||||
hb_buffer_serialize_format_t format);
|
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
|
HB_END_DECLS
|
||||||
|
|
||||||
#endif /* HB_BUFFER_H */
|
#endif /* HB_BUFFER_H */
|
||||||
|
|
|
@ -1014,23 +1014,15 @@ inline void hb_ot_map_t::apply (const Proxy &proxy,
|
||||||
const stage_map_t *stage = &stages[table_index][stage_index];
|
const stage_map_t *stage = &stages[table_index][stage_index];
|
||||||
for (; i < stage->last_lookup; i++)
|
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;
|
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_index (lookup_index);
|
||||||
c.set_lookup_mask (lookups[table_index][i].mask);
|
c.set_lookup_mask (lookups[table_index][i].mask);
|
||||||
c.set_auto_zwj (lookups[table_index][i].auto_zwj);
|
c.set_auto_zwj (lookups[table_index][i].auto_zwj);
|
||||||
apply_string<Proxy> (&c,
|
apply_string<Proxy> (&c,
|
||||||
proxy.table.get_lookup (lookup_index),
|
proxy.table.get_lookup (lookup_index),
|
||||||
proxy.accels[lookup_index]);
|
proxy.accels[lookup_index]);
|
||||||
|
(void) buffer->message (font, "end lookup %d", lookup_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stage->pause_func)
|
if (stage->pause_func)
|
||||||
|
|
|
@ -46,6 +46,22 @@ locale_to_utf8 (char *s)
|
||||||
return t;
|
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>
|
template <typename consumer_t, int default_font_size, int subpixel_bits>
|
||||||
struct main_font_text_t
|
struct main_font_text_t
|
||||||
|
@ -74,6 +90,8 @@ struct main_font_text_t
|
||||||
consumer.init (&font_opts);
|
consumer.init (&font_opts);
|
||||||
|
|
||||||
hb_buffer_t *buffer = hb_buffer_create ();
|
hb_buffer_t *buffer = hb_buffer_create ();
|
||||||
|
if (debug)
|
||||||
|
hb_buffer_set_message_func (buffer, message_func, NULL, NULL);
|
||||||
unsigned int text_len;
|
unsigned int text_len;
|
||||||
const char *text;
|
const char *text;
|
||||||
while ((text = input.get_line (&text_len)))
|
while ((text = input.get_line (&text_len)))
|
||||||
|
|
Loading…
Reference in New Issue