2 * Copyright © 2011 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 #ifndef SHAPE_FORMAT_OPTIONS_HH
28 #define SHAPE_FORMAT_OPTIONS_HH
33 struct shape_format_options_t
35 void add_options (option_parser_t *parser);
37 void serialize (hb_buffer_t *buffer,
39 hb_buffer_serialize_format_t format,
40 hb_buffer_serialize_flags_t flags,
42 void serialize_line_no (unsigned int line_no,
44 void serialize_buffer_of_text (hb_buffer_t *buffer,
47 unsigned int text_len,
50 void serialize_message (unsigned int line_no,
54 void serialize_buffer_of_glyphs (hb_buffer_t *buffer,
57 unsigned int text_len,
59 hb_buffer_serialize_format_t output_format,
60 hb_buffer_serialize_flags_t format_flags,
64 hb_bool_t show_glyph_names = true;
65 hb_bool_t show_positions = true;
66 hb_bool_t show_advances = true;
67 hb_bool_t show_clusters = true;
68 hb_bool_t show_text = false;
69 hb_bool_t show_unicode = false;
70 hb_bool_t show_line_num = false;
71 hb_bool_t show_extents = false;
72 hb_bool_t show_flags = false;
73 hb_bool_t trace = false;
78 parse_verbose (const char *name G_GNUC_UNUSED,
79 const char *arg G_GNUC_UNUSED,
80 gpointer data G_GNUC_UNUSED,
81 GError **error G_GNUC_UNUSED)
83 shape_format_options_t *format_opts = (shape_format_options_t *) data;
84 format_opts->show_text = format_opts->show_unicode = format_opts->show_line_num = true;
89 parse_ned (const char *name G_GNUC_UNUSED,
90 const char *arg G_GNUC_UNUSED,
91 gpointer data G_GNUC_UNUSED,
92 GError **error G_GNUC_UNUSED)
94 shape_format_options_t *format_opts = (shape_format_options_t *) data;
95 format_opts->show_clusters = format_opts->show_advances = false;
100 shape_format_options_t::serialize (hb_buffer_t *buffer,
102 hb_buffer_serialize_format_t output_format,
103 hb_buffer_serialize_flags_t flags,
106 unsigned int num_glyphs = hb_buffer_get_length (buffer);
107 unsigned int start = 0;
109 while (start < num_glyphs)
112 unsigned int consumed;
113 start += hb_buffer_serialize (buffer, start, num_glyphs,
114 buf, sizeof (buf), &consumed,
115 font, output_format, flags);
118 g_string_append (gs, buf);
123 shape_format_options_t::serialize_line_no (unsigned int line_no,
127 g_string_append_printf (gs, "%d: ", line_no);
130 shape_format_options_t::serialize_buffer_of_text (hb_buffer_t *buffer,
131 unsigned int line_no,
133 unsigned int text_len,
139 serialize_line_no (line_no, gs);
140 g_string_append_c (gs, '(');
141 g_string_append_len (gs, text, text_len);
142 g_string_append_c (gs, ')');
143 g_string_append_c (gs, '\n');
148 serialize_line_no (line_no, gs);
149 serialize (buffer, font, HB_BUFFER_SERIALIZE_FORMAT_TEXT, HB_BUFFER_SERIALIZE_FLAG_DEFAULT, gs);
150 g_string_append_c (gs, '\n');
154 shape_format_options_t::serialize_message (unsigned int line_no,
159 serialize_line_no (line_no, gs);
160 g_string_append_printf (gs, "%s: %s", type, msg);
161 g_string_append_c (gs, '\n');
164 shape_format_options_t::serialize_buffer_of_glyphs (hb_buffer_t *buffer,
165 unsigned int line_no,
167 unsigned int text_len,
169 hb_buffer_serialize_format_t output_format,
170 hb_buffer_serialize_flags_t format_flags,
173 serialize_line_no (line_no, gs);
174 serialize (buffer, font, output_format, format_flags, gs);
175 g_string_append_c (gs, '\n');
180 shape_format_options_t::add_options (option_parser_t *parser)
182 GOptionEntry entries[] =
184 {"show-text", 0, 0, G_OPTION_ARG_NONE, &this->show_text, "Prefix each line of output with its corresponding input text", nullptr},
185 {"show-unicode", 0, 0, G_OPTION_ARG_NONE, &this->show_unicode, "Prefix each line of output with its corresponding input codepoint(s)", nullptr},
186 {"show-line-num", 0, 0, G_OPTION_ARG_NONE, &this->show_line_num, "Prefix each line of output with its corresponding input line number", nullptr},
187 {"verbose", 'v', G_OPTION_FLAG_NO_ARG,
188 G_OPTION_ARG_CALLBACK, (gpointer) &parse_verbose, "Prefix each line of output with all of the above", nullptr},
189 {"no-glyph-names", 0, G_OPTION_FLAG_REVERSE,
190 G_OPTION_ARG_NONE, &this->show_glyph_names, "Output glyph indices instead of names", nullptr},
191 {"no-positions", 0, G_OPTION_FLAG_REVERSE,
192 G_OPTION_ARG_NONE, &this->show_positions, "Do not output glyph positions", nullptr},
193 {"no-advances", 0, G_OPTION_FLAG_REVERSE,
194 G_OPTION_ARG_NONE, &this->show_advances, "Do not output glyph advances", nullptr},
195 {"no-clusters", 0, G_OPTION_FLAG_REVERSE,
196 G_OPTION_ARG_NONE, &this->show_clusters, "Do not output cluster indices", nullptr},
197 {"show-extents", 0, 0, G_OPTION_ARG_NONE, &this->show_extents, "Output glyph extents", nullptr},
198 {"show-flags", 0, 0, G_OPTION_ARG_NONE, &this->show_flags, "Output glyph flags", nullptr},
199 {"ned", 'v', G_OPTION_FLAG_NO_ARG,
200 G_OPTION_ARG_CALLBACK, (gpointer) &parse_ned, "No Extra Data; Do not output clusters or advances", nullptr},
201 {"trace", 'V', 0, G_OPTION_ARG_NONE, &this->trace, "Output interim shaping results", nullptr},
204 parser->add_group (entries,
207 " text: [<glyph name or index>=<glyph cluster index within input>@<horizontal displacement>,<vertical displacement>+<horizontal advance>,<vertical advance>|...]\n"
208 " json: [{\"g\": <glyph name or index>, \"ax\": <horizontal advance>, \"ay\": <vertical advance>, \"dx\": <horizontal displacement>, \"dy\": <vertical displacement>, \"cl\": <glyph cluster index within input>}, ...]\n"
209 "\nOutput syntax options:",
210 "Options for the syntax of the output",