2 * Copyright © 2012 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Google Author(s): Behdad Esfahbod
27 #include "main-font-text.hh"
33 struct shape_closure_consumer_t : option_group_t
35 shape_closure_consumer_t (option_parser_t *parser) :
37 show_glyph_names (true)
42 void add_options (struct option_parser_t *parser)
44 GOptionEntry entries[] =
46 {"no-glyph-names", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &this->show_glyph_names, "Use glyph indices instead of names", NULL},
49 parser->add_group (entries,
52 "Options controlling output formatting",
56 void init (const font_options_t *font_opts)
58 glyphs = hb_set_create ();
59 font = hb_font_reference (font_opts->get_font ());
62 void consume_line (hb_buffer_t *buffer,
64 unsigned int text_len,
65 const char *text_before,
66 const char *text_after)
68 hb_set_clear (glyphs);
69 shaper.shape_closure (text, text_len, font, buffer, glyphs);
71 if (hb_set_is_empty (glyphs))
76 for (hb_codepoint_t i = -1; hb_set_next (glyphs, &i);)
83 if (show_glyph_names) {
84 hb_font_get_glyph_name (font, i, glyph_name, sizeof (glyph_name));
85 printf ("%s", glyph_name);
90 void finish (const font_options_t *font_opts)
93 hb_font_destroy (font);
95 hb_set_destroy (glyphs);
102 shape_options_t shaper;
103 hb_bool_t show_glyph_names;
110 main (int argc, char **argv)
112 main_font_text_t<shape_closure_consumer_t> driver;
113 return driver.main (argc, argv);