[util] Add --num-iterations
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 11 Apr 2013 20:31:01 +0000 (16:31 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Thu, 11 Apr 2013 20:31:01 +0000 (16:31 -0400)
Useful for profiling shapers.

util/options.cc
util/options.hh
util/shape-consumer.hh

index 5e57548..66b5e15 100644 (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,
index 35ea0bc..9302427 100644 (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;
 };
 
 
index bf1a22d..2b86a3c 100644 (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);