From 321f73c16efa0730c96e001d65268f4927a0f735 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 13 Nov 2012 15:12:24 -0800 Subject: [PATCH] [util] Add --text-before and --text-after to hb-shape / hb-view Use with Arabic, for example, to see the effect on joining. --- util/hb-ot-shape-closure.cc | 4 +++- util/main-font-text.hh | 2 +- util/options.cc | 2 ++ util/options.hh | 18 ++++++++++++++++-- util/shape-consumer.hh | 6 ++++-- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/util/hb-ot-shape-closure.cc b/util/hb-ot-shape-closure.cc index 6dce7a172..2289605cd 100644 --- a/util/hb-ot-shape-closure.cc +++ b/util/hb-ot-shape-closure.cc @@ -61,7 +61,9 @@ struct shape_closure_consumer_t : option_group_t } void consume_line (hb_buffer_t *buffer, const char *text, - unsigned int text_len) + unsigned int text_len, + const char *text_before, + const char *text_after) { hb_set_clear (glyphs); shaper.shape_closure (text, text_len, font, buffer, glyphs); diff --git a/util/main-font-text.hh b/util/main-font-text.hh index 44e3bfbe7..ac51b2db0 100644 --- a/util/main-font-text.hh +++ b/util/main-font-text.hh @@ -61,7 +61,7 @@ struct main_font_text_t unsigned int text_len; const char *text; while ((text = input.get_line (&text_len))) - consumer.consume_line (buffer, text, text_len); + consumer.consume_line (buffer, text, text_len, input.text_before, input.text_after); hb_buffer_destroy (buffer); consumer.finish (&font_opts); diff --git a/util/options.cc b/util/options.cc index 1f626b61f..ef07e9fee 100644 --- a/util/options.cc +++ b/util/options.cc @@ -350,6 +350,8 @@ text_options_t::add_options (option_parser_t *parser) { {"text", 0, 0, G_OPTION_ARG_STRING, &this->text, "Set input text", "string"}, {"text-file", 0, 0, G_OPTION_ARG_STRING, &this->text_file, "Set input text file-name\n\n If no text is provided, standard input is used for input.", "filename"}, + {"text-before", 0, 0, G_OPTION_ARG_STRING, &this->text_before, "Set text context before each line", "string"}, + {"text-after", 0, 0, G_OPTION_ARG_STRING, &this->text_after, "Set text context after each line", "string"}, {NULL} }; parser->add_group (entries, diff --git a/util/options.hh b/util/options.hh index 5d25d9ea5..0f6fce287 100644 --- a/util/options.hh +++ b/util/options.hh @@ -167,10 +167,18 @@ struct shape_options_t : option_group_t hb_buffer_set_language (buffer, hb_language_from_string (language, -1)); } - void populate_buffer (hb_buffer_t *buffer, const char *text, int text_len) + void populate_buffer (hb_buffer_t *buffer, const char *text, int text_len, + const char *text_before, const char *text_after) { - hb_buffer_reset (buffer); + hb_buffer_clear (buffer); + if (text_before) { + unsigned int len = strlen (text_before); + hb_buffer_add_utf8 (buffer, text_before, len, len, 0); + } hb_buffer_add_utf8 (buffer, text, text_len, 0, text_len); + if (text_after) { + hb_buffer_add_utf8 (buffer, text_after, -1, 0, 0); + } if (!utf8_clusters) { /* Reset cluster values to refer to Unicode character index @@ -245,6 +253,9 @@ struct font_options_t : option_group_t struct text_options_t : option_group_t { text_options_t (option_parser_t *parser) { + text_before = NULL; + text_after = NULL; + text = NULL; text_file = NULL; @@ -273,6 +284,9 @@ struct text_options_t : option_group_t const char *get_line (unsigned int *len); + const char *text_before; + const char *text_after; + const char *text; const char *text_file; diff --git a/util/shape-consumer.hh b/util/shape-consumer.hh index 220daa497..bf1a22da9 100644 --- a/util/shape-consumer.hh +++ b/util/shape-consumer.hh @@ -45,11 +45,13 @@ struct shape_consumer_t } void consume_line (hb_buffer_t *buffer, const char *text, - unsigned int text_len) + unsigned int text_len, + const char *text_before, + const char *text_after) { output.new_line (); - shaper.populate_buffer (buffer, text, text_len); + 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)) {