2 * Copyright © 2011,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
36 struct supported_font_funcs_t {
38 void (*func) (hb_font_t *);
39 } supported_font_funcs[] =
42 {"ft", hb_ft_font_set_funcs},
45 {"ot", hb_ot_font_set_funcs},
51 fail (hb_bool_t suggest_help, const char *format, ...)
56 va_start (vap, format);
57 msg = g_strdup_vprintf (format, vap);
59 const char *prgname = g_get_prgname ();
60 g_printerr ("%s: %s\n", prgname, msg);
62 g_printerr ("Try `%s --help' for more information.\n", prgname);
69 shapers_to_string (void)
71 GString *shapers = g_string_new (nullptr);
72 const char **shaper_list = hb_shape_list_shapers ();
74 for (; *shaper_list; shaper_list++) {
75 g_string_append (shapers, *shaper_list);
76 g_string_append_c (shapers, ',');
78 g_string_truncate (shapers, MAX (0, (gint)shapers->len - 1));
80 return g_string_free (shapers, false);
83 static G_GNUC_NORETURN gboolean
84 show_version (const char *name G_GNUC_UNUSED,
85 const char *arg G_GNUC_UNUSED,
86 gpointer data G_GNUC_UNUSED,
87 GError **error G_GNUC_UNUSED)
89 g_printf ("%s (%s) %s\n", g_get_prgname (), PACKAGE_NAME, PACKAGE_VERSION);
91 char *shapers = shapers_to_string ();
92 g_printf ("Available shapers: %s\n", shapers);
94 if (strcmp (HB_VERSION_STRING, hb_version_string ()))
95 g_printf ("Linked HarfBuzz library has a different version: %s\n", hb_version_string ());
102 option_parser_t::add_main_options (void)
104 GOptionEntry entries[] =
106 {"version", 0, G_OPTION_FLAG_NO_ARG,
107 G_OPTION_ARG_CALLBACK, (gpointer) &show_version, "Show version numbers", nullptr},
110 g_option_context_add_main_entries (context, entries, nullptr);
114 pre_parse (GOptionContext *context G_GNUC_UNUSED,
115 GOptionGroup *group G_GNUC_UNUSED,
119 option_group_t *option_group = (option_group_t *) data;
120 option_group->pre_parse (error);
121 return *error == nullptr;
125 post_parse (GOptionContext *context G_GNUC_UNUSED,
126 GOptionGroup *group G_GNUC_UNUSED,
130 option_group_t *option_group = static_cast<option_group_t *>(data);
131 option_group->post_parse (error);
132 return *error == nullptr;
136 option_parser_t::add_group (GOptionEntry *entries,
138 const gchar *description,
139 const gchar *help_description,
140 option_group_t *option_group)
142 GOptionGroup *group = g_option_group_new (name, description, help_description,
143 static_cast<gpointer>(option_group), nullptr);
144 g_option_group_add_entries (group, entries);
145 g_option_group_set_parse_hooks (group, pre_parse, post_parse);
146 g_option_context_add_group (context, group);
150 option_parser_t::parse (int *argc, char ***argv)
152 setlocale (LC_ALL, "");
154 GError *parse_error = nullptr;
155 if (!g_option_context_parse (context, argc, argv, &parse_error))
157 if (parse_error != nullptr) {
158 fail (true, "%s", parse_error->message);
159 //g_error_free (parse_error);
161 fail (true, "Option parse error");
167 parse_margin (const char *name G_GNUC_UNUSED,
170 GError **error G_GNUC_UNUSED)
172 view_options_t *view_opts = (view_options_t *) data;
173 view_options_t::margin_t &m = view_opts->margin;
174 switch (sscanf (arg, "%lf%*[ ,]%lf%*[ ,]%lf%*[ ,]%lf", &m.t, &m.r, &m.b, &m.l)) {
180 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
181 "%s argument should be one to four space-separated numbers",
189 parse_shapers (const char *name G_GNUC_UNUSED,
194 shape_options_t *shape_opts = (shape_options_t *) data;
195 char **shapers = g_strsplit (arg, ",", 0);
197 for (char **shaper = shapers; *shaper; shaper++) {
199 for (const char **hb_shaper = hb_shape_list_shapers (); *hb_shaper; hb_shaper++) {
200 if (strcmp (*shaper, *hb_shaper) == 0) {
206 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
207 "Unknown or unsupported shaper: %s", *shaper);
208 g_strfreev (shapers);
213 g_strfreev (shape_opts->shapers);
214 shape_opts->shapers = shapers;
218 static G_GNUC_NORETURN gboolean
219 list_shapers (const char *name G_GNUC_UNUSED,
220 const char *arg G_GNUC_UNUSED,
221 gpointer data G_GNUC_UNUSED,
222 GError **error G_GNUC_UNUSED)
224 for (const char **shaper = hb_shape_list_shapers (); *shaper; shaper++)
225 g_printf ("%s\n", *shaper);
232 parse_features (const char *name G_GNUC_UNUSED,
235 GError **error G_GNUC_UNUSED)
237 shape_options_t *shape_opts = (shape_options_t *) data;
238 char *s = (char *) arg;
241 shape_opts->num_features = 0;
242 g_free (shape_opts->features);
243 shape_opts->features = nullptr;
248 /* count the features first, so we can allocate memory */
251 shape_opts->num_features++;
257 shape_opts->features = (hb_feature_t *) calloc (shape_opts->num_features, sizeof (*shape_opts->features));
258 if (!shape_opts->features)
261 /* now do the actual parsing */
263 shape_opts->num_features = 0;
265 char *end = strchr (p, ',');
266 if (hb_feature_from_string (p, end ? end - p : -1, &shape_opts->features[shape_opts->num_features]))
267 shape_opts->num_features++;
268 p = end ? end + 1 : nullptr;
275 parse_variations (const char *name G_GNUC_UNUSED,
278 GError **error G_GNUC_UNUSED)
280 font_options_t *font_opts = (font_options_t *) data;
281 char *s = (char *) arg;
284 font_opts->num_variations = 0;
285 g_free (font_opts->variations);
286 font_opts->variations = nullptr;
291 /* count the variations first, so we can allocate memory */
294 font_opts->num_variations++;
300 font_opts->variations = (hb_variation_t *) calloc (font_opts->num_variations, sizeof (*font_opts->variations));
301 if (!font_opts->variations)
304 /* now do the actual parsing */
306 font_opts->num_variations = 0;
308 char *end = strchr (p, ',');
309 if (hb_variation_from_string (p, end ? end - p : -1, &font_opts->variations[font_opts->num_variations]))
310 font_opts->num_variations++;
311 p = end ? end + 1 : nullptr;
318 parse_text (const char *name G_GNUC_UNUSED,
321 GError **error G_GNUC_UNUSED)
323 text_options_t *text_opts = (text_options_t *) data;
327 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
328 "Either --text or --unicodes can be provided but not both");
332 text_opts->text = g_strdup (arg);
338 parse_unicodes (const char *name G_GNUC_UNUSED,
341 GError **error G_GNUC_UNUSED)
343 text_options_t *text_opts = (text_options_t *) data;
347 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
348 "Either --text or --unicodes can be provided but not both");
352 GString *gs = g_string_new (nullptr);
353 char *s = (char *) arg;
358 while (*s && strchr ("<+>{},;&#\\xXuUnNiI\n\t\v\f\r ", *s))
364 hb_codepoint_t u = strtoul (s, &p, 16);
367 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
368 "Failed parsing Unicode values at: '%s'", s);
372 g_string_append_unichar (gs, u);
377 text_opts->text = g_string_free (gs, FALSE);
383 view_options_t::add_options (option_parser_t *parser)
385 GOptionEntry entries[] =
387 {"annotate", 0, 0, G_OPTION_ARG_NONE, &this->annotate, "Annotate output rendering", nullptr},
388 {"background", 0, 0, G_OPTION_ARG_STRING, &this->back, "Set background color (default: " DEFAULT_BACK ")", "rrggbb/rrggbbaa"},
389 {"foreground", 0, 0, G_OPTION_ARG_STRING, &this->fore, "Set foreground color (default: " DEFAULT_FORE ")", "rrggbb/rrggbbaa"},
390 {"line-space", 0, 0, G_OPTION_ARG_DOUBLE, &this->line_space, "Set space between lines (default: 0)", "units"},
391 {"margin", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_margin, "Margin around output (default: " G_STRINGIFY(DEFAULT_MARGIN) ")","one to four numbers"},
394 parser->add_group (entries,
397 "Options for output rendering",
402 shape_options_t::add_options (option_parser_t *parser)
404 GOptionEntry entries[] =
406 {"list-shapers", 0, G_OPTION_FLAG_NO_ARG,
407 G_OPTION_ARG_CALLBACK, (gpointer) &list_shapers, "List available shapers and quit", nullptr},
408 {"shaper", 0, G_OPTION_FLAG_HIDDEN,
409 G_OPTION_ARG_CALLBACK, (gpointer) &parse_shapers, "Hidden duplicate of --shapers", nullptr},
410 {"shapers", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_shapers, "Set comma-separated list of shapers to try","list"},
411 {"direction", 0, 0, G_OPTION_ARG_STRING, &this->direction, "Set text direction (default: auto)", "ltr/rtl/ttb/btt"},
412 {"language", 0, 0, G_OPTION_ARG_STRING, &this->language, "Set text language (default: $LANG)", "langstr"},
413 {"script", 0, 0, G_OPTION_ARG_STRING, &this->script, "Set text script (default: auto)", "ISO-15924 tag"},
414 {"bot", 0, 0, G_OPTION_ARG_NONE, &this->bot, "Treat text as beginning-of-paragraph", nullptr},
415 {"eot", 0, 0, G_OPTION_ARG_NONE, &this->eot, "Treat text as end-of-paragraph", nullptr},
416 {"preserve-default-ignorables",0, 0, G_OPTION_ARG_NONE, &this->preserve_default_ignorables, "Preserve Default-Ignorable characters", nullptr},
417 {"remove-default-ignorables",0, 0, G_OPTION_ARG_NONE, &this->remove_default_ignorables, "Remove Default-Ignorable characters", nullptr},
418 {"utf8-clusters", 0, 0, G_OPTION_ARG_NONE, &this->utf8_clusters, "Use UTF8 byte indices, not char indices", nullptr},
419 {"cluster-level", 0, 0, G_OPTION_ARG_INT, &this->cluster_level, "Cluster merging level (default: 0)", "0/1/2"},
420 {"normalize-glyphs",0, 0, G_OPTION_ARG_NONE, &this->normalize_glyphs, "Rearrange glyph clusters in nominal order", nullptr},
421 {"verify", 0, 0, G_OPTION_ARG_NONE, &this->verify, "Perform sanity checks on shaping results", nullptr},
422 {"num-iterations", 0, 0, G_OPTION_ARG_INT, &this->num_iterations, "Run shaper N times (default: 1)", "N"},
425 parser->add_group (entries,
428 "Options for the shaping process",
431 const gchar *features_help = "Comma-separated list of font features\n"
433 " Features can be enabled or disabled, either globally or limited to\n"
434 " specific character ranges. The format for specifying feature settings\n"
435 " follows. All valid CSS font-feature-settings values other than 'normal'\n"
436 " and 'inherited' are also accepted, though, not documented below.\n"
438 " The range indices refer to the positions between Unicode characters,\n"
439 " unless the --utf8-clusters is provided, in which case range indices\n"
440 " refer to UTF-8 byte indices. The position before the first character\n"
443 " The format is Python-esque. Here is how it all works:\n"
445 " Syntax: Value: Start: End:\n"
448 " \"kern\" 1 0 ∞ # Turn feature on\n"
449 " \"+kern\" 1 0 ∞ # Turn feature on\n"
450 " \"-kern\" 0 0 ∞ # Turn feature off\n"
451 " \"kern=0\" 0 0 ∞ # Turn feature off\n"
452 " \"kern=1\" 1 0 ∞ # Turn feature on\n"
453 " \"aalt=2\" 2 0 ∞ # Choose 2nd alternate\n"
456 " \"kern[]\" 1 0 ∞ # Turn feature on\n"
457 " \"kern[:]\" 1 0 ∞ # Turn feature on\n"
458 " \"kern[5:]\" 1 5 ∞ # Turn feature on, partial\n"
459 " \"kern[:5]\" 1 0 5 # Turn feature on, partial\n"
460 " \"kern[3:5]\" 1 3 5 # Turn feature on, range\n"
461 " \"kern[3]\" 1 3 3+1 # Turn feature on, single char\n"
465 " \"aalt[3:5]=2\" 2 3 5 # Turn 2nd alternate on for range";
467 GOptionEntry entries2[] =
469 {"features", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_features, features_help, "list"},
472 parser->add_group (entries2,
475 "Options for font features used",
480 parse_font_size (const char *name G_GNUC_UNUSED,
483 GError **error G_GNUC_UNUSED)
485 font_options_t *font_opts = (font_options_t *) data;
486 if (0 == strcmp (arg, "upem"))
488 font_opts->font_size_y = font_opts->font_size_x = FONT_SIZE_UPEM;
491 switch (sscanf (arg, "%lf%*[ ,]%lf", &font_opts->font_size_x, &font_opts->font_size_y)) {
492 case 1: font_opts->font_size_y = font_opts->font_size_x;
495 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
496 "%s argument should be one or two space-separated numbers",
503 parse_font_ppem (const char *name G_GNUC_UNUSED,
506 GError **error G_GNUC_UNUSED)
508 font_options_t *font_opts = (font_options_t *) data;
509 switch (sscanf (arg, "%d%*[ ,]%d", &font_opts->x_ppem, &font_opts->y_ppem)) {
510 case 1: font_opts->y_ppem = font_opts->x_ppem;
513 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
514 "%s argument should be one or two space-separated numbers",
521 font_options_t::add_options (option_parser_t *parser)
523 char *text = nullptr;
526 static_assert ((ARRAY_LENGTH_CONST (supported_font_funcs) > 0),
527 "No supported font-funcs found.");
528 GString *s = g_string_new (nullptr);
529 g_string_printf (s, "Set font functions implementation to use (default: %s)\n\n Supported font function implementations are: %s",
530 supported_font_funcs[0].name,
531 supported_font_funcs[0].name);
532 for (unsigned int i = 1; i < ARRAY_LENGTH (supported_font_funcs); i++)
534 g_string_append_c (s, '/');
535 g_string_append (s, supported_font_funcs[i].name);
537 text = g_string_free (s, FALSE);
538 parser->free_later (text);
541 char *font_size_text;
542 if (default_font_size == FONT_SIZE_UPEM)
543 font_size_text = (char *) "Font size (default: upem)";
546 font_size_text = g_strdup_printf ("Font size (default: %d)", default_font_size);
547 parser->free_later (font_size_text);
550 GOptionEntry entries[] =
552 {"font-file", 0, 0, G_OPTION_ARG_STRING, &this->font_file, "Set font file-name", "filename"},
553 {"face-index", 0, 0, G_OPTION_ARG_INT, &this->face_index, "Set face index (default: 0)", "index"},
554 {"font-size", 0, default_font_size ? 0 : G_OPTION_FLAG_HIDDEN,
555 G_OPTION_ARG_CALLBACK, (gpointer) &parse_font_size, font_size_text, "1/2 integers or 'upem'"},
556 {"font-ppem", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_font_ppem, "Set x,y pixels per EM (default: 0; disabled)", "1/2 integers"},
557 {"font-ptem", 0, 0, G_OPTION_ARG_DOUBLE, &this->ptem, "Set font point-size (default: 0; disabled)", "point-size"},
558 {"font-funcs", 0, 0, G_OPTION_ARG_STRING, &this->font_funcs, text, "impl"},
561 parser->add_group (entries,
564 "Options for the font",
567 const gchar *variations_help = "Comma-separated list of font variations\n"
569 " Variations are set globally. The format for specifying variation settings\n"
570 " follows. All valid CSS font-variation-settings values other than 'normal'\n"
571 " and 'inherited' are also accepted, though, not documented below.\n"
573 " The format is a tag, optionally followed by an equals sign, followed by a\n"
574 " number. For example:\n"
579 GOptionEntry entries2[] =
581 {"variations", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_variations, variations_help, "list"},
584 parser->add_group (entries2,
586 "Variations options:",
587 "Options for font variations used",
592 text_options_t::add_options (option_parser_t *parser)
594 GOptionEntry entries[] =
596 {"text", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_text, "Set input text", "string"},
597 {"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.\n", "filename"},
598 {"unicodes", 'u', 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_unicodes, "Set input Unicode codepoints", "list of hex numbers"},
599 {"text-before", 0, 0, G_OPTION_ARG_STRING, &this->text_before, "Set text context before each line", "string"},
600 {"text-after", 0, 0, G_OPTION_ARG_STRING, &this->text_after, "Set text context after each line", "string"},
603 parser->add_group (entries,
606 "Options for the input text",
611 output_options_t::add_options (option_parser_t *parser)
615 if (nullptr == supported_formats)
616 text = "Set output serialization format";
619 char *items = g_strjoinv ("/", const_cast<char **> (supported_formats));
620 text = g_strdup_printf ("Set output format\n\n Supported output formats are: %s", items);
622 parser->free_later ((char *) text);
625 GOptionEntry entries[] =
627 {"output-file", 'o', 0, G_OPTION_ARG_STRING, &this->output_file, "Set output file-name (default: stdout)","filename"},
628 {"output-format", 'O', 0, G_OPTION_ARG_STRING, &this->output_format, text, "format"},
631 parser->add_group (entries,
633 "Output destination & format options:",
634 "Options for the destination & form of the output",
641 font_options_t::get_font (void) const
646 hb_blob_t *blob = nullptr;
648 /* Create the blob */
650 fail (true, "No font file set");
652 if (0 == strcmp (font_file, "-")) {
654 GString *gs = g_string_new (nullptr);
656 #if defined(_WIN32) || defined(__CYGWIN__)
657 setmode (fileno (stdin), O_BINARY);
659 while (!feof (stdin)) {
660 size_t ret = fread (buf, 1, sizeof (buf), stdin);
662 fail (false, "Failed reading font from standard input: %s",
664 g_string_append_len (gs, buf, ret);
666 char *font_data = g_string_free (gs, false);
667 blob = hb_blob_create (font_data, gs->len,
668 HB_MEMORY_MODE_WRITABLE, font_data,
669 (hb_destroy_func_t) g_free);
671 blob = hb_blob_create_from_file (font_file);
674 /* Create the face */
675 hb_face_t *face = hb_face_create (blob, face_index);
676 hb_blob_destroy (blob);
679 font = hb_font_create (face);
681 if (font_size_x == FONT_SIZE_UPEM)
682 font_size_x = hb_face_get_upem (face);
683 if (font_size_y == FONT_SIZE_UPEM)
684 font_size_y = hb_face_get_upem (face);
686 hb_font_set_ppem (font, x_ppem, y_ppem);
687 hb_font_set_ptem (font, ptem);
689 int scale_x = (int) scalbnf (font_size_x, subpixel_bits);
690 int scale_y = (int) scalbnf (font_size_y, subpixel_bits);
691 hb_font_set_scale (font, scale_x, scale_y);
692 hb_face_destroy (face);
694 hb_font_set_variations (font, variations, num_variations);
696 void (*set_font_funcs) (hb_font_t *) = nullptr;
699 set_font_funcs = supported_font_funcs[0].func;
703 for (unsigned int i = 0; i < ARRAY_LENGTH (supported_font_funcs); i++)
704 if (0 == g_ascii_strcasecmp (font_funcs, supported_font_funcs[i].name))
706 set_font_funcs = supported_font_funcs[i].func;
711 GString *s = g_string_new (nullptr);
712 for (unsigned int i = 0; i < ARRAY_LENGTH (supported_font_funcs); i++)
715 g_string_append_c (s, '/');
716 g_string_append (s, supported_font_funcs[i].name);
718 char *p = g_string_free (s, FALSE);
719 fail (false, "Unknown font function implementation `%s'; supported values are: %s; default is %s",
722 supported_font_funcs[0].name);
726 set_font_funcs (font);
733 text_options_t::get_line (unsigned int *len)
736 if (!line) line = text;
737 if (line_len == (unsigned int) -1)
738 line_len = strlen (line);
745 const char *ret = line;
746 const char *p = (const char *) memchr (line, '\n', line_len);
747 unsigned int ret_len;
755 line_len -= ret_len + 1;
764 fail (true, "At least one of text or text-file must be set");
766 if (0 != strcmp (text_file, "-"))
767 fp = fopen (text_file, "r");
772 fail (false, "Failed opening text file `%s': %s",
773 text_file, strerror (errno));
775 gs = g_string_new (nullptr);
778 g_string_set_size (gs, 0);
780 while (fgets (buf, sizeof (buf), fp)) {
781 unsigned int bytes = strlen (buf);
782 if (bytes && buf[bytes - 1] == '\n') {
784 g_string_append_len (gs, buf, bytes);
787 g_string_append_len (gs, buf, bytes);
790 fail (false, "Failed reading text: %s",
793 return !*len && feof (fp) ? nullptr : gs->str;
798 output_options_t::get_file_handle (void)
804 fp = fopen (output_file, "wb");
806 #if defined(_WIN32) || defined(__CYGWIN__)
807 setmode (fileno (stdout), O_BINARY);
812 fail (false, "Cannot open output file `%s': %s",
813 g_filename_display_name (output_file), strerror (errno));
819 parse_verbose (const char *name G_GNUC_UNUSED,
820 const char *arg G_GNUC_UNUSED,
821 gpointer data G_GNUC_UNUSED,
822 GError **error G_GNUC_UNUSED)
824 format_options_t *format_opts = (format_options_t *) data;
825 format_opts->show_text = format_opts->show_unicode = format_opts->show_line_num = true;
830 parse_ned (const char *name G_GNUC_UNUSED,
831 const char *arg G_GNUC_UNUSED,
832 gpointer data G_GNUC_UNUSED,
833 GError **error G_GNUC_UNUSED)
835 format_options_t *format_opts = (format_options_t *) data;
836 format_opts->show_clusters = format_opts->show_advances = false;
841 format_options_t::add_options (option_parser_t *parser)
843 GOptionEntry entries[] =
845 {"show-text", 0, 0, G_OPTION_ARG_NONE, &this->show_text, "Prefix each line of output with its corresponding input text", nullptr},
846 {"show-unicode", 0, 0, G_OPTION_ARG_NONE, &this->show_unicode, "Prefix each line of output with its corresponding input codepoint(s)", nullptr},
847 {"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},
848 {"verbose", 'v', G_OPTION_FLAG_NO_ARG,
849 G_OPTION_ARG_CALLBACK, (gpointer) &parse_verbose, "Prefix each line of output with all of the above", nullptr},
850 {"no-glyph-names", 0, G_OPTION_FLAG_REVERSE,
851 G_OPTION_ARG_NONE, &this->show_glyph_names, "Output glyph indices instead of names", nullptr},
852 {"no-positions", 0, G_OPTION_FLAG_REVERSE,
853 G_OPTION_ARG_NONE, &this->show_positions, "Do not output glyph positions", nullptr},
854 {"no-advances", 0, G_OPTION_FLAG_REVERSE,
855 G_OPTION_ARG_NONE, &this->show_advances, "Do not output glyph advances", nullptr},
856 {"no-clusters", 0, G_OPTION_FLAG_REVERSE,
857 G_OPTION_ARG_NONE, &this->show_clusters, "Do not output cluster indices", nullptr},
858 {"show-extents", 0, 0, G_OPTION_ARG_NONE, &this->show_extents, "Output glyph extents", nullptr},
859 {"show-flags", 0, 0, G_OPTION_ARG_NONE, &this->show_flags, "Output glyph flags", nullptr},
860 {"ned", 'v', G_OPTION_FLAG_NO_ARG,
861 G_OPTION_ARG_CALLBACK, (gpointer) &parse_ned, "No Extra Data; Do not output clusters or advances", nullptr},
862 {"trace", 'V', 0, G_OPTION_ARG_NONE, &this->trace, "Output interim shaping results", nullptr},
865 parser->add_group (entries,
868 " text: [<glyph name or index>=<glyph cluster index within input>@<horizontal displacement>,<vertical displacement>+<horizontal advance>,<vertical advance>|...]\n"
869 " 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"
870 "\nOutput syntax options:",
871 "Options for the syntax of the output",
876 format_options_t::serialize_unicode (hb_buffer_t *buffer,
879 unsigned int num_glyphs = hb_buffer_get_length (buffer);
880 hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, nullptr);
882 g_string_append_c (gs, '<');
883 for (unsigned int i = 0; i < num_glyphs; i++)
886 g_string_append_c (gs, ',');
887 g_string_append_printf (gs, "U+%04X", info->codepoint);
890 g_string_append_c (gs, '>');
894 format_options_t::serialize_glyphs (hb_buffer_t *buffer,
896 hb_buffer_serialize_format_t output_format,
897 hb_buffer_serialize_flags_t flags,
900 g_string_append_c (gs, '[');
901 unsigned int num_glyphs = hb_buffer_get_length (buffer);
902 unsigned int start = 0;
904 while (start < num_glyphs)
907 unsigned int consumed;
908 start += hb_buffer_serialize_glyphs (buffer, start, num_glyphs,
909 buf, sizeof (buf), &consumed,
910 font, output_format, flags);
913 g_string_append (gs, buf);
915 g_string_append_c (gs, ']');
918 format_options_t::serialize_line_no (unsigned int line_no,
922 g_string_append_printf (gs, "%d: ", line_no);
925 format_options_t::serialize_buffer_of_text (hb_buffer_t *buffer,
926 unsigned int line_no,
928 unsigned int text_len,
934 serialize_line_no (line_no, gs);
935 g_string_append_c (gs, '(');
936 g_string_append_len (gs, text, text_len);
937 g_string_append_c (gs, ')');
938 g_string_append_c (gs, '\n');
943 serialize_line_no (line_no, gs);
944 serialize_unicode (buffer, gs);
945 g_string_append_c (gs, '\n');
949 format_options_t::serialize_message (unsigned int line_no,
954 serialize_line_no (line_no, gs);
955 g_string_append_printf (gs, "%s: %s", type, msg);
956 g_string_append_c (gs, '\n');
959 format_options_t::serialize_buffer_of_glyphs (hb_buffer_t *buffer,
960 unsigned int line_no,
962 unsigned int text_len,
964 hb_buffer_serialize_format_t output_format,
965 hb_buffer_serialize_flags_t format_flags,
968 serialize_line_no (line_no, gs);
969 serialize_glyphs (buffer, font, output_format, format_flags, gs);
970 g_string_append_c (gs, '\n');
974 subset_options_t::add_options (option_parser_t *parser)
976 GOptionEntry entries[] =
978 {"no-hinting", 0, 0, G_OPTION_ARG_NONE, &this->drop_hints, "Whether to drop hints", nullptr},
981 parser->add_group (entries,
984 "Options subsetting",