[util] Add --text-before and --text-after to hb-shape / hb-view
Use with Arabic, for example, to see the effect on joining.
diff --git a/util/hb-ot-shape-closure.cc b/util/hb-ot-shape-closure.cc
index 6dce7a1..2289605 100644
--- a/util/hb-ot-shape-closure.cc
+++ b/util/hb-ot-shape-closure.cc
@@ -61,7 +61,9 @@
}
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 44e3bfb..ac51b2d 100644
--- a/util/main-font-text.hh
+++ b/util/main-font-text.hh
@@ -61,7 +61,7 @@
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 1f626b6..ef07e9f 100644
--- a/util/options.cc
+++ b/util/options.cc
@@ -350,6 +350,8 @@
{
{"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 5d25d9e..0f6fce2 100644
--- a/util/options.hh
+++ b/util/options.hh
@@ -167,10 +167,18 @@
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 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 @@
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 220daa4..bf1a22d 100644
--- a/util/shape-consumer.hh
+++ b/util/shape-consumer.hh
@@ -45,11 +45,13 @@
}
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)) {