[util] Add --text-before and --text-after to hb-shape / hb-view

Use with Arabic, for example, to see the effect on joining.
This commit is contained in:
Behdad Esfahbod 2012-11-13 15:12:24 -08:00
parent e13f8d280b
commit 321f73c16e
5 changed files with 26 additions and 6 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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,

View File

@ -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;

View File

@ -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)) {