Before, that was printed using --debug (and in both hb-shape and hb-view).
Changed it, now hb-shape has a new command-line argument called --show-messages.
When invoked, it also respects other output formatting options. The messages
are better formatted and printed to te same place that hb-shape output is
directed to. Previously they were written to stderr.
Fixes https://github.com/behdad/harfbuzz/issues/506
this);
}
- void init (const font_options_t *font_opts)
+ void init (hb_buffer_t *buffer_,
+ const font_options_t *font_opts)
{
glyphs = hb_set_create ();
font = hb_font_reference (font_opts->get_font ());
failed = false;
+ buffer = hb_buffer_reference (buffer_);
}
- void consume_line (hb_buffer_t *buffer,
- const char *text,
+ void consume_line (const char *text,
unsigned int text_len,
const char *text_before,
const char *text_after)
font = NULL;
hb_set_destroy (glyphs);
glyphs = NULL;
+ hb_buffer_destroy (buffer);
+ buffer = NULL;
}
bool failed;
hb_set_t *glyphs;
hb_font_t *font;
+ hb_buffer_t *buffer;
};
int
output_format (HB_BUFFER_SERIALIZE_FORMAT_INVALID),
format_flags (HB_BUFFER_SERIALIZE_FLAG_DEFAULT) {}
- void init (const font_options_t *font_opts)
+ void init (hb_buffer_t *buffer, const font_options_t *font_opts)
{
options.get_file_handle ();
gs = g_string_new (NULL);
if (format.show_extents)
flags |= HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS;
format_flags = (hb_buffer_serialize_flags_t) flags;
+
+ if (format.show_messages)
+ hb_buffer_set_message_func (buffer, message_func, this, NULL);
}
void new_line (void)
{
output_format, format_flags, gs);
fprintf (options.fp, "%s", gs->str);
}
- void finish (const font_options_t *font_opts)
+ void finish (hb_buffer_t *buffer, const font_options_t *font_opts)
{
+ hb_buffer_set_message_func (buffer, NULL, NULL, NULL);
hb_font_destroy (font);
g_string_free (gs, true);
gs = NULL;
font = NULL;
}
+ static hb_bool_t
+ message_func (hb_buffer_t *buffer,
+ hb_font_t *font,
+ const char *message,
+ void *user_data)
+ {
+ output_buffer_t *that = (output_buffer_t *) user_data;
+ that->message (buffer, font, message);
+ return true;
+ }
+
+ void
+ message (hb_buffer_t *buffer,
+ hb_font_t *font,
+ const char *message)
+ {
+ g_string_set_size (gs, 0);
+ format.serialize_line_no (line_no, gs);
+ g_string_append_printf (gs, "HB: %s buffer: ", message);
+ format.serialize_glyphs (buffer, font, output_format, format_flags, gs);
+ g_string_append_c (gs, '\n');
+ fprintf (options.fp, "%s", gs->str);
+ }
+
+
protected:
output_options_t options;
format_options_t format;
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);
- fprintf (stderr, "HB: buffer [%s]\n", buf);
- return true;
-}
-
template <typename consumer_t, int default_font_size, int subpixel_bits>
struct main_font_text_t
{
if (!input.text && !input.text_file)
input.text_file = g_strdup ("-");
- consumer.init (&font_opts);
-
hb_buffer_t *buffer = hb_buffer_create ();
- if (debug)
- hb_buffer_set_message_func (buffer, message_func, NULL, NULL);
+ consumer.init (buffer, &font_opts);
+ hb_buffer_destroy (buffer);
+
unsigned int text_len;
const char *text;
while ((text = input.get_line (&text_len)))
- consumer.consume_line (buffer, text, text_len, input.text_before, input.text_after);
- hb_buffer_destroy (buffer);
+ consumer.consume_line (text, text_len, input.text_before, input.text_after);
consumer.finish (&font_opts);
{"no-clusters", 0, G_OPTION_FLAG_REVERSE,
G_OPTION_ARG_NONE, &this->show_clusters, "Do not output cluster indices", NULL},
{"show-extents", 0, 0, G_OPTION_ARG_NONE, &this->show_extents, "Output glyph extents", NULL},
+ {"show-messages", 0, 0, G_OPTION_ARG_NONE, &this->show_messages, "Output shaping debug messages", NULL},
{NULL}
};
parser->add_group (entries,
unsigned int num_glyphs = hb_buffer_get_length (buffer);
unsigned int start = 0;
- while (start < num_glyphs) {
+ while (start < num_glyphs)
+ {
char buf[1024];
unsigned int consumed;
start += hb_buffer_serialize_glyphs (buffer, start, num_glyphs,
hb_font_t *font,
GString *gs)
{
- if (show_text) {
+ if (show_text)
+ {
serialize_line_no (line_no, gs);
g_string_append_c (gs, '(');
g_string_append_len (gs, text, text_len);
g_string_append_c (gs, '\n');
}
- if (show_unicode) {
+ if (show_unicode)
+ {
serialize_line_no (line_no, gs);
serialize_unicode (buffer, gs);
g_string_append_c (gs, '\n');
show_unicode = false;
show_line_num = false;
show_extents = false;
+ show_messages = false;
add_options (parser);
}
hb_bool_t show_unicode;
hb_bool_t show_line_num;
hb_bool_t show_extents;
+ hb_bool_t show_messages;
};
/* fallback implementation for scalbn()/scalbnf() for pre-2013 MSVC */
output (parser),
font (NULL) {}
- void init (const font_options_t *font_opts)
+ void init (hb_buffer_t *buffer_,
+ const font_options_t *font_opts)
{
font = hb_font_reference (font_opts->get_font ());
- output.init (font_opts);
failed = false;
+ buffer = hb_buffer_reference (buffer_);
+
+ output.init (buffer, font_opts);
}
- void consume_line (hb_buffer_t *buffer,
- const char *text,
+ void consume_line (const char *text,
unsigned int text_len,
const char *text_before,
const char *text_after)
shaper.populate_buffer (buffer, text, text_len, text_before, text_after);
if (n == 1)
output.consume_text (buffer, text, text_len, shaper.utf8_clusters);
- if (!shaper.shape (font, buffer)) {
+ if (!shaper.shape (font, buffer))
+ {
failed = true;
hb_buffer_set_length (buffer, 0);
output.shape_failed (buffer, text, text_len, shaper.utf8_clusters);
}
void finish (const font_options_t *font_opts)
{
- output.finish (font_opts);
+ output.finish (buffer, font_opts);
hb_font_destroy (font);
font = NULL;
+ hb_buffer_destroy (buffer);
+ buffer = NULL;
}
public:
output_t output;
hb_font_t *font;
+ hb_buffer_t *buffer;
};
cairo_debug_reset_static_data ();
}
- void init (const font_options_t *font_opts)
+ void init (hb_buffer_t *buffer, const font_options_t *font_opts)
{
lines = g_array_new (false, false, sizeof (helper_cairo_line_t));
scale_bits = -font_opts->subpixel_bits;
helper_cairo_line_from_buffer (&l, buffer, text, text_len, scale_bits, utf8_clusters);
g_array_append_val (lines, l);
}
- void finish (const font_options_t *font_opts)
+ void finish (hb_buffer_t *buffer, const font_options_t *font_opts)
{
render (font_opts);