blob: 77ca20135091849dc7d6369fb1186d1dacf589d1 [file] [log] [blame]
Behdad Esfahbodc87b3172012-05-15 23:53:18 -04001/*
2 * Copyright © 2012 Google, Inc.
3 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
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.
11 *
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
16 * DAMAGE.
17 *
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.
23 *
24 * Google Author(s): Behdad Esfahbod
25 */
26
27#include "main-font-text.hh"
28
29#ifdef HAVE_FREETYPE
30#include <hb-ft.h>
31#endif
32
33struct shape_closure_consumer_t : option_group_t
34{
35 shape_closure_consumer_t (option_parser_t *parser) :
36 shaper (parser),
37 show_glyph_names (true)
38 {
39 add_options (parser);
40 }
41
42 void add_options (struct option_parser_t *parser)
43 {
44 GOptionEntry entries[] =
45 {
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +020046 {"no-glyph-names", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &this->show_glyph_names, "Use glyph indices instead of names", nullptr},
47 {nullptr}
Behdad Esfahbodc87b3172012-05-15 23:53:18 -040048 };
49 parser->add_group (entries,
50 "format",
51 "Format options:",
52 "Options controlling output formatting",
53 this);
54 }
55
Behdad Esfahbode6035052017-07-18 19:14:19 -070056 void init (hb_buffer_t *buffer_,
57 const font_options_t *font_opts)
Behdad Esfahbodc87b3172012-05-15 23:53:18 -040058 {
59 glyphs = hb_set_create ();
60 font = hb_font_reference (font_opts->get_font ());
Behdad Esfahbod5db06832012-06-02 12:13:08 -040061 failed = false;
Behdad Esfahbode6035052017-07-18 19:14:19 -070062 buffer = hb_buffer_reference (buffer_);
Behdad Esfahbodc87b3172012-05-15 23:53:18 -040063 }
Behdad Esfahbode6035052017-07-18 19:14:19 -070064 void consume_line (const char *text,
Behdad Esfahbod321f73c2012-11-13 15:12:24 -080065 unsigned int text_len,
66 const char *text_before,
67 const char *text_after)
Behdad Esfahbodc87b3172012-05-15 23:53:18 -040068 {
Behdad Esfahbodc87b3172012-05-15 23:53:18 -040069 hb_set_clear (glyphs);
70 shaper.shape_closure (text, text_len, font, buffer, glyphs);
Behdad Esfahbod29ce4462012-05-25 14:17:54 -040071
Behdad Esfahbodaec89de2012-11-15 16:15:42 -080072 if (hb_set_is_empty (glyphs))
Behdad Esfahbod29ce4462012-05-25 14:17:54 -040073 return;
74
Behdad Esfahbodc87b3172012-05-15 23:53:18 -040075 /* Print it out! */
Behdad Esfahbodc87b3172012-05-15 23:53:18 -040076 bool first = true;
Behdad Esfahbod29ce4462012-05-25 14:17:54 -040077 for (hb_codepoint_t i = -1; hb_set_next (glyphs, &i);)
Behdad Esfahbod75da37d2012-11-15 18:39:23 -080078 {
79 if (first)
80 first = false;
81 else
82 printf (" ");
Behdad Esfahbod7235f332013-06-10 14:39:51 -040083 if (show_glyph_names)
84 {
85 char glyph_name[64];
Behdad Esfahbod5fbc9522013-07-29 14:34:40 -040086 hb_font_glyph_to_string (font, i, glyph_name, sizeof (glyph_name));
Behdad Esfahbod75da37d2012-11-15 18:39:23 -080087 printf ("%s", glyph_name);
88 } else
89 printf ("%u", i);
90 }
Behdad Esfahbodc87b3172012-05-15 23:53:18 -040091 }
92 void finish (const font_options_t *font_opts)
93 {
94 printf ("\n");
95 hb_font_destroy (font);
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +020096 font = nullptr;
Behdad Esfahbodc87b3172012-05-15 23:53:18 -040097 hb_set_destroy (glyphs);
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +020098 glyphs = nullptr;
Behdad Esfahbode6035052017-07-18 19:14:19 -070099 hb_buffer_destroy (buffer);
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200100 buffer = nullptr;
Behdad Esfahbodc87b3172012-05-15 23:53:18 -0400101 }
102
Behdad Esfahbod5db06832012-06-02 12:13:08 -0400103 bool failed;
104
Behdad Esfahbodc87b3172012-05-15 23:53:18 -0400105 protected:
106 shape_options_t shaper;
107 hb_bool_t show_glyph_names;
108
109 hb_set_t *glyphs;
110 hb_font_t *font;
Behdad Esfahbode6035052017-07-18 19:14:19 -0700111 hb_buffer_t *buffer;
Behdad Esfahbodc87b3172012-05-15 23:53:18 -0400112};
113
114int
115main (int argc, char **argv)
116{
Behdad Esfahbodcd4eb962015-01-20 12:30:45 -0800117 main_font_text_t<shape_closure_consumer_t, FONT_SIZE_NONE, 0> driver;
Behdad Esfahbodc87b3172012-05-15 23:53:18 -0400118 return driver.main (argc, argv);
119}