1*2d1272b8SAndroid Build Coastguard Worker /*
2*2d1272b8SAndroid Build Coastguard Worker * Copyright © 2011 Google, Inc.
3*2d1272b8SAndroid Build Coastguard Worker *
4*2d1272b8SAndroid Build Coastguard Worker * This is part of HarfBuzz, a text shaping library.
5*2d1272b8SAndroid Build Coastguard Worker *
6*2d1272b8SAndroid Build Coastguard Worker * Permission is hereby granted, without written agreement and without
7*2d1272b8SAndroid Build Coastguard Worker * license or royalty fees, to use, copy, modify, and distribute this
8*2d1272b8SAndroid Build Coastguard Worker * software and its documentation for any purpose, provided that the
9*2d1272b8SAndroid Build Coastguard Worker * above copyright notice and the following two paragraphs appear in
10*2d1272b8SAndroid Build Coastguard Worker * all copies of this software.
11*2d1272b8SAndroid Build Coastguard Worker *
12*2d1272b8SAndroid Build Coastguard Worker * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13*2d1272b8SAndroid Build Coastguard Worker * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14*2d1272b8SAndroid Build Coastguard Worker * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15*2d1272b8SAndroid Build Coastguard Worker * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16*2d1272b8SAndroid Build Coastguard Worker * DAMAGE.
17*2d1272b8SAndroid Build Coastguard Worker *
18*2d1272b8SAndroid Build Coastguard Worker * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19*2d1272b8SAndroid Build Coastguard Worker * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20*2d1272b8SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21*2d1272b8SAndroid Build Coastguard Worker * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22*2d1272b8SAndroid Build Coastguard Worker * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23*2d1272b8SAndroid Build Coastguard Worker *
24*2d1272b8SAndroid Build Coastguard Worker * Google Author(s): Behdad Esfahbod
25*2d1272b8SAndroid Build Coastguard Worker */
26*2d1272b8SAndroid Build Coastguard Worker
27*2d1272b8SAndroid Build Coastguard Worker #ifndef SHAPE_FORMAT_OPTIONS_HH
28*2d1272b8SAndroid Build Coastguard Worker #define SHAPE_FORMAT_OPTIONS_HH
29*2d1272b8SAndroid Build Coastguard Worker
30*2d1272b8SAndroid Build Coastguard Worker #include "options.hh"
31*2d1272b8SAndroid Build Coastguard Worker
32*2d1272b8SAndroid Build Coastguard Worker
33*2d1272b8SAndroid Build Coastguard Worker struct shape_format_options_t
34*2d1272b8SAndroid Build Coastguard Worker {
35*2d1272b8SAndroid Build Coastguard Worker void add_options (option_parser_t *parser);
36*2d1272b8SAndroid Build Coastguard Worker
37*2d1272b8SAndroid Build Coastguard Worker void serialize (hb_buffer_t *buffer,
38*2d1272b8SAndroid Build Coastguard Worker hb_font_t *font,
39*2d1272b8SAndroid Build Coastguard Worker hb_buffer_serialize_format_t format,
40*2d1272b8SAndroid Build Coastguard Worker hb_buffer_serialize_flags_t flags,
41*2d1272b8SAndroid Build Coastguard Worker GString *gs);
42*2d1272b8SAndroid Build Coastguard Worker void serialize_line_no (unsigned int line_no,
43*2d1272b8SAndroid Build Coastguard Worker GString *gs);
44*2d1272b8SAndroid Build Coastguard Worker void serialize_buffer_of_text (hb_buffer_t *buffer,
45*2d1272b8SAndroid Build Coastguard Worker unsigned int line_no,
46*2d1272b8SAndroid Build Coastguard Worker const char *text,
47*2d1272b8SAndroid Build Coastguard Worker unsigned int text_len,
48*2d1272b8SAndroid Build Coastguard Worker hb_font_t *font,
49*2d1272b8SAndroid Build Coastguard Worker GString *gs);
50*2d1272b8SAndroid Build Coastguard Worker void serialize_message (unsigned int line_no,
51*2d1272b8SAndroid Build Coastguard Worker const char *type,
52*2d1272b8SAndroid Build Coastguard Worker const char *msg,
53*2d1272b8SAndroid Build Coastguard Worker GString *gs);
54*2d1272b8SAndroid Build Coastguard Worker void serialize_buffer_of_glyphs (hb_buffer_t *buffer,
55*2d1272b8SAndroid Build Coastguard Worker unsigned int line_no,
56*2d1272b8SAndroid Build Coastguard Worker const char *text,
57*2d1272b8SAndroid Build Coastguard Worker unsigned int text_len,
58*2d1272b8SAndroid Build Coastguard Worker hb_font_t *font,
59*2d1272b8SAndroid Build Coastguard Worker hb_buffer_serialize_format_t output_format,
60*2d1272b8SAndroid Build Coastguard Worker hb_buffer_serialize_flags_t format_flags,
61*2d1272b8SAndroid Build Coastguard Worker GString *gs);
62*2d1272b8SAndroid Build Coastguard Worker
63*2d1272b8SAndroid Build Coastguard Worker
64*2d1272b8SAndroid Build Coastguard Worker hb_bool_t show_glyph_names = true;
65*2d1272b8SAndroid Build Coastguard Worker hb_bool_t show_positions = true;
66*2d1272b8SAndroid Build Coastguard Worker hb_bool_t show_advances = true;
67*2d1272b8SAndroid Build Coastguard Worker hb_bool_t show_clusters = true;
68*2d1272b8SAndroid Build Coastguard Worker hb_bool_t show_text = false;
69*2d1272b8SAndroid Build Coastguard Worker hb_bool_t show_unicode = false;
70*2d1272b8SAndroid Build Coastguard Worker hb_bool_t show_line_num = false;
71*2d1272b8SAndroid Build Coastguard Worker hb_bool_t show_extents = false;
72*2d1272b8SAndroid Build Coastguard Worker hb_bool_t show_flags = false;
73*2d1272b8SAndroid Build Coastguard Worker hb_bool_t trace = false;
74*2d1272b8SAndroid Build Coastguard Worker };
75*2d1272b8SAndroid Build Coastguard Worker
76*2d1272b8SAndroid Build Coastguard Worker
77*2d1272b8SAndroid Build Coastguard Worker static gboolean
parse_verbose(const char * name G_GNUC_UNUSED,const char * arg G_GNUC_UNUSED,gpointer data G_GNUC_UNUSED,GError ** error G_GNUC_UNUSED)78*2d1272b8SAndroid Build Coastguard Worker parse_verbose (const char *name G_GNUC_UNUSED,
79*2d1272b8SAndroid Build Coastguard Worker const char *arg G_GNUC_UNUSED,
80*2d1272b8SAndroid Build Coastguard Worker gpointer data G_GNUC_UNUSED,
81*2d1272b8SAndroid Build Coastguard Worker GError **error G_GNUC_UNUSED)
82*2d1272b8SAndroid Build Coastguard Worker {
83*2d1272b8SAndroid Build Coastguard Worker shape_format_options_t *format_opts = (shape_format_options_t *) data;
84*2d1272b8SAndroid Build Coastguard Worker format_opts->show_text = format_opts->show_unicode = format_opts->show_line_num = true;
85*2d1272b8SAndroid Build Coastguard Worker return true;
86*2d1272b8SAndroid Build Coastguard Worker }
87*2d1272b8SAndroid Build Coastguard Worker
88*2d1272b8SAndroid Build Coastguard Worker static gboolean
parse_ned(const char * name G_GNUC_UNUSED,const char * arg G_GNUC_UNUSED,gpointer data G_GNUC_UNUSED,GError ** error G_GNUC_UNUSED)89*2d1272b8SAndroid Build Coastguard Worker parse_ned (const char *name G_GNUC_UNUSED,
90*2d1272b8SAndroid Build Coastguard Worker const char *arg G_GNUC_UNUSED,
91*2d1272b8SAndroid Build Coastguard Worker gpointer data G_GNUC_UNUSED,
92*2d1272b8SAndroid Build Coastguard Worker GError **error G_GNUC_UNUSED)
93*2d1272b8SAndroid Build Coastguard Worker {
94*2d1272b8SAndroid Build Coastguard Worker shape_format_options_t *format_opts = (shape_format_options_t *) data;
95*2d1272b8SAndroid Build Coastguard Worker format_opts->show_clusters = format_opts->show_advances = false;
96*2d1272b8SAndroid Build Coastguard Worker return true;
97*2d1272b8SAndroid Build Coastguard Worker }
98*2d1272b8SAndroid Build Coastguard Worker
99*2d1272b8SAndroid Build Coastguard Worker inline void
serialize(hb_buffer_t * buffer,hb_font_t * font,hb_buffer_serialize_format_t output_format,hb_buffer_serialize_flags_t flags,GString * gs)100*2d1272b8SAndroid Build Coastguard Worker shape_format_options_t::serialize (hb_buffer_t *buffer,
101*2d1272b8SAndroid Build Coastguard Worker hb_font_t *font,
102*2d1272b8SAndroid Build Coastguard Worker hb_buffer_serialize_format_t output_format,
103*2d1272b8SAndroid Build Coastguard Worker hb_buffer_serialize_flags_t flags,
104*2d1272b8SAndroid Build Coastguard Worker GString *gs)
105*2d1272b8SAndroid Build Coastguard Worker {
106*2d1272b8SAndroid Build Coastguard Worker unsigned int num_glyphs = hb_buffer_get_length (buffer);
107*2d1272b8SAndroid Build Coastguard Worker unsigned int start = 0;
108*2d1272b8SAndroid Build Coastguard Worker
109*2d1272b8SAndroid Build Coastguard Worker while (start < num_glyphs)
110*2d1272b8SAndroid Build Coastguard Worker {
111*2d1272b8SAndroid Build Coastguard Worker char buf[32768];
112*2d1272b8SAndroid Build Coastguard Worker unsigned int consumed;
113*2d1272b8SAndroid Build Coastguard Worker start += hb_buffer_serialize (buffer, start, num_glyphs,
114*2d1272b8SAndroid Build Coastguard Worker buf, sizeof (buf), &consumed,
115*2d1272b8SAndroid Build Coastguard Worker font, output_format, flags);
116*2d1272b8SAndroid Build Coastguard Worker if (!consumed)
117*2d1272b8SAndroid Build Coastguard Worker break;
118*2d1272b8SAndroid Build Coastguard Worker g_string_append (gs, buf);
119*2d1272b8SAndroid Build Coastguard Worker }
120*2d1272b8SAndroid Build Coastguard Worker }
121*2d1272b8SAndroid Build Coastguard Worker
122*2d1272b8SAndroid Build Coastguard Worker inline void
serialize_line_no(unsigned int line_no,GString * gs)123*2d1272b8SAndroid Build Coastguard Worker shape_format_options_t::serialize_line_no (unsigned int line_no,
124*2d1272b8SAndroid Build Coastguard Worker GString *gs)
125*2d1272b8SAndroid Build Coastguard Worker {
126*2d1272b8SAndroid Build Coastguard Worker if (show_line_num)
127*2d1272b8SAndroid Build Coastguard Worker g_string_append_printf (gs, "%u: ", line_no);
128*2d1272b8SAndroid Build Coastguard Worker }
129*2d1272b8SAndroid Build Coastguard Worker inline void
serialize_buffer_of_text(hb_buffer_t * buffer,unsigned int line_no,const char * text,unsigned int text_len,hb_font_t * font,GString * gs)130*2d1272b8SAndroid Build Coastguard Worker shape_format_options_t::serialize_buffer_of_text (hb_buffer_t *buffer,
131*2d1272b8SAndroid Build Coastguard Worker unsigned int line_no,
132*2d1272b8SAndroid Build Coastguard Worker const char *text,
133*2d1272b8SAndroid Build Coastguard Worker unsigned int text_len,
134*2d1272b8SAndroid Build Coastguard Worker hb_font_t *font,
135*2d1272b8SAndroid Build Coastguard Worker GString *gs)
136*2d1272b8SAndroid Build Coastguard Worker {
137*2d1272b8SAndroid Build Coastguard Worker if (show_text)
138*2d1272b8SAndroid Build Coastguard Worker {
139*2d1272b8SAndroid Build Coastguard Worker serialize_line_no (line_no, gs);
140*2d1272b8SAndroid Build Coastguard Worker g_string_append_c (gs, '(');
141*2d1272b8SAndroid Build Coastguard Worker g_string_append_len (gs, text, text_len);
142*2d1272b8SAndroid Build Coastguard Worker g_string_append_c (gs, ')');
143*2d1272b8SAndroid Build Coastguard Worker g_string_append_c (gs, '\n');
144*2d1272b8SAndroid Build Coastguard Worker }
145*2d1272b8SAndroid Build Coastguard Worker
146*2d1272b8SAndroid Build Coastguard Worker if (show_unicode)
147*2d1272b8SAndroid Build Coastguard Worker {
148*2d1272b8SAndroid Build Coastguard Worker serialize_line_no (line_no, gs);
149*2d1272b8SAndroid Build Coastguard Worker serialize (buffer, font, HB_BUFFER_SERIALIZE_FORMAT_TEXT, HB_BUFFER_SERIALIZE_FLAG_DEFAULT, gs);
150*2d1272b8SAndroid Build Coastguard Worker g_string_append_c (gs, '\n');
151*2d1272b8SAndroid Build Coastguard Worker }
152*2d1272b8SAndroid Build Coastguard Worker }
153*2d1272b8SAndroid Build Coastguard Worker inline void
serialize_message(unsigned int line_no,const char * type,const char * msg,GString * gs)154*2d1272b8SAndroid Build Coastguard Worker shape_format_options_t::serialize_message (unsigned int line_no,
155*2d1272b8SAndroid Build Coastguard Worker const char *type,
156*2d1272b8SAndroid Build Coastguard Worker const char *msg,
157*2d1272b8SAndroid Build Coastguard Worker GString *gs)
158*2d1272b8SAndroid Build Coastguard Worker {
159*2d1272b8SAndroid Build Coastguard Worker serialize_line_no (line_no, gs);
160*2d1272b8SAndroid Build Coastguard Worker g_string_append_printf (gs, "%s: %s", type, msg);
161*2d1272b8SAndroid Build Coastguard Worker g_string_append_c (gs, '\n');
162*2d1272b8SAndroid Build Coastguard Worker }
163*2d1272b8SAndroid Build Coastguard Worker inline void
serialize_buffer_of_glyphs(hb_buffer_t * buffer,unsigned int line_no,const char * text,unsigned int text_len,hb_font_t * font,hb_buffer_serialize_format_t output_format,hb_buffer_serialize_flags_t format_flags,GString * gs)164*2d1272b8SAndroid Build Coastguard Worker shape_format_options_t::serialize_buffer_of_glyphs (hb_buffer_t *buffer,
165*2d1272b8SAndroid Build Coastguard Worker unsigned int line_no,
166*2d1272b8SAndroid Build Coastguard Worker const char *text,
167*2d1272b8SAndroid Build Coastguard Worker unsigned int text_len,
168*2d1272b8SAndroid Build Coastguard Worker hb_font_t *font,
169*2d1272b8SAndroid Build Coastguard Worker hb_buffer_serialize_format_t output_format,
170*2d1272b8SAndroid Build Coastguard Worker hb_buffer_serialize_flags_t format_flags,
171*2d1272b8SAndroid Build Coastguard Worker GString *gs)
172*2d1272b8SAndroid Build Coastguard Worker {
173*2d1272b8SAndroid Build Coastguard Worker serialize_line_no (line_no, gs);
174*2d1272b8SAndroid Build Coastguard Worker serialize (buffer, font, output_format, format_flags, gs);
175*2d1272b8SAndroid Build Coastguard Worker g_string_append_c (gs, '\n');
176*2d1272b8SAndroid Build Coastguard Worker }
177*2d1272b8SAndroid Build Coastguard Worker
178*2d1272b8SAndroid Build Coastguard Worker
179*2d1272b8SAndroid Build Coastguard Worker void
add_options(option_parser_t * parser)180*2d1272b8SAndroid Build Coastguard Worker shape_format_options_t::add_options (option_parser_t *parser)
181*2d1272b8SAndroid Build Coastguard Worker {
182*2d1272b8SAndroid Build Coastguard Worker GOptionEntry entries[] =
183*2d1272b8SAndroid Build Coastguard Worker {
184*2d1272b8SAndroid Build Coastguard Worker {"show-text", 0, 0, G_OPTION_ARG_NONE, &this->show_text, "Prefix each line of output with its corresponding input text", nullptr},
185*2d1272b8SAndroid Build Coastguard Worker {"show-unicode", 0, 0, G_OPTION_ARG_NONE, &this->show_unicode, "Prefix each line of output with its corresponding input codepoint(s)", nullptr},
186*2d1272b8SAndroid Build Coastguard Worker {"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*2d1272b8SAndroid Build Coastguard Worker {"verbose", 'v', G_OPTION_FLAG_NO_ARG,
188*2d1272b8SAndroid Build Coastguard Worker G_OPTION_ARG_CALLBACK, (gpointer) &parse_verbose, "Prefix each line of output with all of the above", nullptr},
189*2d1272b8SAndroid Build Coastguard Worker {"no-glyph-names", 0, G_OPTION_FLAG_REVERSE,
190*2d1272b8SAndroid Build Coastguard Worker G_OPTION_ARG_NONE, &this->show_glyph_names, "Output glyph indices instead of names", nullptr},
191*2d1272b8SAndroid Build Coastguard Worker {"no-positions", 0, G_OPTION_FLAG_REVERSE,
192*2d1272b8SAndroid Build Coastguard Worker G_OPTION_ARG_NONE, &this->show_positions, "Do not output glyph positions", nullptr},
193*2d1272b8SAndroid Build Coastguard Worker {"no-advances", 0, G_OPTION_FLAG_REVERSE,
194*2d1272b8SAndroid Build Coastguard Worker G_OPTION_ARG_NONE, &this->show_advances, "Do not output glyph advances", nullptr},
195*2d1272b8SAndroid Build Coastguard Worker {"no-clusters", 0, G_OPTION_FLAG_REVERSE,
196*2d1272b8SAndroid Build Coastguard Worker G_OPTION_ARG_NONE, &this->show_clusters, "Do not output cluster indices", nullptr},
197*2d1272b8SAndroid Build Coastguard Worker {"show-extents", 0, 0, G_OPTION_ARG_NONE, &this->show_extents, "Output glyph extents", nullptr},
198*2d1272b8SAndroid Build Coastguard Worker {"show-flags", 0, 0, G_OPTION_ARG_NONE, &this->show_flags, "Output glyph flags", nullptr},
199*2d1272b8SAndroid Build Coastguard Worker {"ned", 'v', G_OPTION_FLAG_NO_ARG,
200*2d1272b8SAndroid Build Coastguard Worker G_OPTION_ARG_CALLBACK, (gpointer) &parse_ned, "No Extra Data; Do not output clusters or advances", nullptr},
201*2d1272b8SAndroid Build Coastguard Worker {"trace", 'V', 0, G_OPTION_ARG_NONE, &this->trace, "Output interim shaping results", nullptr},
202*2d1272b8SAndroid Build Coastguard Worker {nullptr}
203*2d1272b8SAndroid Build Coastguard Worker };
204*2d1272b8SAndroid Build Coastguard Worker parser->add_group (entries,
205*2d1272b8SAndroid Build Coastguard Worker "output-syntax",
206*2d1272b8SAndroid Build Coastguard Worker "Output syntax:\n"
207*2d1272b8SAndroid Build Coastguard Worker " text: [<glyph name or index>=<glyph cluster index within input>@<horizontal displacement>,<vertical displacement>+<horizontal advance>,<vertical advance>|...]\n"
208*2d1272b8SAndroid Build Coastguard Worker " 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*2d1272b8SAndroid Build Coastguard Worker "\nOutput syntax options:",
210*2d1272b8SAndroid Build Coastguard Worker "Options for the syntax of the output",
211*2d1272b8SAndroid Build Coastguard Worker this);
212*2d1272b8SAndroid Build Coastguard Worker }
213*2d1272b8SAndroid Build Coastguard Worker
214*2d1272b8SAndroid Build Coastguard Worker #endif
215