[hb-shape] Add --show-line-num

Ok, much more useful as a test suite driver now.
This commit is contained in:
Behdad Esfahbod 2012-01-19 12:46:18 -05:00
parent cc4d9810d6
commit cdc673d97c
3 changed files with 59 additions and 24 deletions

View File

@ -42,7 +42,7 @@ struct output_buffer_t : output_options_t, format_options_t
protected: protected:
GString *gs; GString *gs;
hb_font_t *font; hb_font_t *font;
hb_buffer_t *scratch; unsigned int line_no;
}; };
void void
@ -51,7 +51,7 @@ output_buffer_t::init (const font_options_t *font_opts)
get_file_handle (); get_file_handle ();
font = hb_font_reference (font_opts->get_font ()); font = hb_font_reference (font_opts->get_font ());
gs = g_string_new (NULL); gs = g_string_new (NULL);
scratch = hb_buffer_create (); line_no = 0;
} }
void void
@ -59,29 +59,15 @@ output_buffer_t::consume_line (hb_buffer_t *buffer,
const char *text, const char *text,
unsigned int text_len) unsigned int text_len)
{ {
line_no++;
g_string_set_size (gs, 0); g_string_set_size (gs, 0);
serialize_line (buffer, line_no, text, text_len, font, gs);
if (show_text) { fprintf (fp, "%s", gs->str);
g_string_append_len (gs, text, text_len);
g_string_append_c (gs, '\n');
}
if (show_unicode) {
hb_buffer_reset (scratch);
hb_buffer_add_utf8 (scratch, text, text_len, 0, -1);
serialize_unicode (buffer, gs);
g_string_append_c (gs, '\n');
}
serialize_glyphs (buffer, font, gs);
fprintf (fp, "%s\n", gs->str);
} }
void void
output_buffer_t::finish (const font_options_t *font_opts) output_buffer_t::finish (const font_options_t *font_opts)
{ {
hb_buffer_destroy (scratch);
scratch = NULL;
g_string_free (gs, TRUE); g_string_free (gs, TRUE);
gs = NULL; gs = NULL;
hb_font_destroy (font); hb_font_destroy (font);

View File

@ -678,6 +678,7 @@ format_options_t::add_options (option_parser_t *parser)
{"no-clusters", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &this->show_clusters, "Do not show cluster mapping", NULL}, {"no-clusters", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &this->show_clusters, "Do not show cluster mapping", NULL},
{"show-text", 0, 0, G_OPTION_ARG_NONE, &this->show_text, "Show input text", NULL}, {"show-text", 0, 0, G_OPTION_ARG_NONE, &this->show_text, "Show input text", NULL},
{"show-unicode", 0, 0, G_OPTION_ARG_NONE, &this->show_unicode, "Show input Unicode codepoints", NULL}, {"show-unicode", 0, 0, G_OPTION_ARG_NONE, &this->show_unicode, "Show input Unicode codepoints", NULL},
{"show-line-num", 0, 0, G_OPTION_ARG_NONE, &this->show_line_num, "Show line numbers", NULL},
{NULL} {NULL}
}; };
parser->add_group (entries, parser->add_group (entries,
@ -750,3 +751,36 @@ format_options_t::serialize_glyphs (hb_buffer_t *buffer,
} }
g_string_append_c (gs, '>'); g_string_append_c (gs, '>');
} }
void
format_options_t::serialize_line_no (unsigned int line_no,
GString *gs)
{
if (show_line_num)
g_string_append_printf (gs, "%d: ", line_no);
}
void
format_options_t::serialize_line (hb_buffer_t *buffer,
unsigned int line_no,
const char *text,
unsigned int text_len,
hb_font_t *font,
GString *gs)
{
if (show_text) {
serialize_line_no (line_no, gs);
g_string_append_len (gs, text, text_len);
g_string_append_c (gs, '\n');
}
if (show_unicode) {
serialize_line_no (line_no, gs);
hb_buffer_reset (scratch);
hb_buffer_add_utf8 (scratch, text, text_len, 0, -1);
serialize_unicode (buffer, gs);
g_string_append_c (gs, '\n');
}
serialize_line_no (line_no, gs);
serialize_glyphs (buffer, font, gs);
g_string_append_c (gs, '\n');
}

View File

@ -285,19 +285,31 @@ struct format_options_t : option_group_t
show_clusters = true; show_clusters = true;
show_text = false; show_text = false;
show_unicode = false; show_unicode = false;
show_line_num = false;
scratch = hb_buffer_create ();
add_options (parser); add_options (parser);
} }
~format_options_t (void) { ~format_options_t (void) {
hb_buffer_destroy (scratch);
} }
void add_options (option_parser_t *parser); void add_options (option_parser_t *parser);
void serialize_unicode (hb_buffer_t *buffer, void serialize_unicode (hb_buffer_t *buffer,
GString *gs); GString *gs);
void serialize_glyphs (hb_buffer_t *buffer, void serialize_glyphs (hb_buffer_t *buffer,
hb_font_t *font, hb_font_t *font,
GString *gs); GString *gs);
void serialize_line_no (unsigned int line_no,
GString *gs);
void serialize_line (hb_buffer_t *buffer,
unsigned int line_no,
const char *text,
unsigned int text_len,
hb_font_t *font,
GString *gs);
protected: protected:
hb_bool_t show_glyph_names; hb_bool_t show_glyph_names;
@ -305,6 +317,9 @@ struct format_options_t : option_group_t
hb_bool_t show_clusters; hb_bool_t show_clusters;
hb_bool_t show_text; hb_bool_t show_text;
hb_bool_t show_unicode; hb_bool_t show_unicode;
hb_bool_t show_line_num;
private:
hb_buffer_t *scratch;
}; };