[util] Add --num-iterations

Useful for profiling shapers.
This commit is contained in:
Behdad Esfahbod 2013-04-11 16:31:01 -04:00
parent 08677c2507
commit 50067e280f
3 changed files with 12 additions and 6 deletions

View File

@ -276,6 +276,7 @@ shape_options_t::add_options (option_parser_t *parser)
{"preserve-default-ignorables",0, 0, G_OPTION_ARG_NONE, &this->preserve_default_ignorables, "Preserve Default-Ignorable characters", NULL},
{"utf8-clusters", 0, 0, G_OPTION_ARG_NONE, &this->utf8_clusters, "Use UTF8 byte indices, not char indices", NULL},
{"normalize-glyphs",0, 0, G_OPTION_ARG_NONE, &this->normalize_glyphs, "Rearrange glyph clusters in nominal order", NULL},
{"num-iterations", 0, 0, G_OPTION_ARG_INT, &this->num_iterations, "Run shaper N times (default: 1)", "N"},
{NULL}
};
parser->add_group (entries,

View File

@ -150,6 +150,7 @@ struct shape_options_t : option_group_t
shapers = NULL;
utf8_clusters = false;
normalize_glyphs = false;
num_iterations = 1;
add_options (parser);
}
@ -234,6 +235,7 @@ struct shape_options_t : option_group_t
char **shapers;
hb_bool_t utf8_clusters;
hb_bool_t normalize_glyphs;
unsigned int num_iterations;
};

View File

@ -51,14 +51,17 @@ struct shape_consumer_t
{
output.new_line ();
shaper.populate_buffer (buffer, text, text_len, text_before, text_after);
output.consume_text (buffer, text, text_len, shaper.utf8_clusters);
if (!shaper.shape (font, buffer)) {
failed = true;
hb_buffer_set_length (buffer, 0);
output.shape_failed (buffer, text, text_len, shaper.utf8_clusters);
return;
for (unsigned int n = shaper.num_iterations; n; n--)
{
shaper.populate_buffer (buffer, text, text_len, text_before, text_after);
if (!shaper.shape (font, buffer)) {
failed = true;
hb_buffer_set_length (buffer, 0);
output.shape_failed (buffer, text, text_len, shaper.utf8_clusters);
return;
}
}
output.consume_glyphs (buffer, text, text_len, shaper.utf8_clusters);