• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2010  Behdad Esfahbod
3  * Copyright © 2011,2012  Google, Inc.
4  *
5  *  This is part of HarfBuzz, a text shaping library.
6  *
7  * Permission is hereby granted, without written agreement and without
8  * license or royalty fees, to use, copy, modify, and distribute this
9  * software and its documentation for any purpose, provided that the
10  * above copyright notice and the following two paragraphs appear in
11  * all copies of this software.
12  *
13  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17  * DAMAGE.
18  *
19  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24  *
25  * Google Author(s): Garret Rieger, Rod Sheeter
26  */
27 
28 #include "batch.hh"
29 #include "face-options.hh"
30 #include "main-font-text.hh"
31 #include "output-options.hh"
32 
33 #include <hb-subset.h>
34 
35 /*
36  * Command line interface to the harfbuzz font subsetter.
37  */
38 
39 struct subset_main_t : option_parser_t, face_options_t, output_options_t<false>
40 {
subset_main_tsubset_main_t41   subset_main_t ()
42   : input (hb_subset_input_create_or_fail ())
43   {}
~subset_main_tsubset_main_t44   ~subset_main_t ()
45   {
46     hb_subset_input_destroy (input);
47   }
48 
parse_facesubset_main_t49   void parse_face (int argc, const char * const *argv)
50   {
51     option_parser_t parser;
52     face_options_t face_opts;
53 
54     face_opts.add_options (&parser);
55 
56     GOptionEntry entries[] =
57     {
58       {G_OPTION_REMAINING,	0, G_OPTION_FLAG_IN_MAIN,
59 				G_OPTION_ARG_CALLBACK,	(gpointer) &collect_face,	nullptr,	"[FONT-FILE] [TEXT]"},
60       {nullptr}
61     };
62     parser.add_main_group (entries, &face_opts);
63     parser.add_options ();
64 
65     g_option_context_set_ignore_unknown_options (parser.context, true);
66     g_option_context_set_help_enabled (parser.context, false);
67 
68     char **args = (char **)
69 #if GLIB_CHECK_VERSION (2, 68, 0)
70       g_memdup2
71 #else
72       g_memdup
73 #endif
74       (argv, argc * sizeof (*argv));
75     parser.parse (&argc, &args);
76     g_free (args);
77 
78     set_face (face_opts.face);
79   }
80 
parsesubset_main_t81   void parse (int argc, char **argv)
82   {
83     bool help = false;
84     for (auto i = 1; i < argc; i++)
85       if (!strncmp ("--help", argv[i], 6))
86       {
87 	help = true;
88 	break;
89       }
90 
91     if (likely (!help))
92     {
93       /* Do a preliminary parse to load font-face, such that we can use it
94        * during main option parsing. */
95       parse_face (argc, argv);
96     }
97 
98     add_options ();
99     option_parser_t::parse (&argc, &argv);
100   }
101 
operator ()subset_main_t102   int operator () (int argc, char **argv)
103   {
104     parse (argc, argv);
105 
106     hb_face_t *new_face = nullptr;
107     for (unsigned i = 0; i < num_iterations; i++)
108     {
109       hb_face_destroy (new_face);
110       new_face = hb_subset_or_fail (face, input);
111     }
112 
113     bool success = new_face;
114     if (success)
115     {
116       hb_blob_t *result = hb_face_reference_blob (new_face);
117       write_file (output_file, result);
118       hb_blob_destroy (result);
119     }
120 
121     hb_face_destroy (new_face);
122 
123     return success ? 0 : 1;
124   }
125 
126   bool
write_filesubset_main_t127   write_file (const char *output_file, hb_blob_t *blob)
128   {
129     assert (out_fp);
130 
131     unsigned int size;
132     const char* data = hb_blob_get_data (blob, &size);
133 
134     while (size)
135     {
136       size_t ret = fwrite (data, 1, size, out_fp);
137       size -= ret;
138       data += ret;
139       if (size && ferror (out_fp))
140         fail (false, "Failed to write output: %s", strerror (errno));
141     }
142 
143     return true;
144   }
145 
146   void add_options ();
147 
148   protected:
149   static gboolean
150   collect_face (const char *name,
151 		const char *arg,
152 		gpointer    data,
153 		GError    **error);
154   static gboolean
155   collect_rest (const char *name,
156 		const char *arg,
157 		gpointer    data,
158 		GError    **error);
159 
160   public:
161 
162   unsigned num_iterations = 1;
163   hb_subset_input_t *input = nullptr;
164 };
165 
166 static gboolean
parse_gids(const char * name G_GNUC_UNUSED,const char * arg,gpointer data,GError ** error)167 parse_gids (const char *name G_GNUC_UNUSED,
168 	    const char *arg,
169 	    gpointer    data,
170 	    GError    **error)
171 {
172   subset_main_t *subset_main = (subset_main_t *) data;
173   hb_bool_t is_remove = (name[strlen (name) - 1] == '-');
174   hb_bool_t is_add = (name[strlen (name) - 1] == '+');
175   hb_set_t *gids = hb_subset_input_glyph_set (subset_main->input);
176 
177   if (!is_remove && !is_add) hb_set_clear (gids);
178 
179   if (0 == strcmp (arg, "*"))
180   {
181     hb_set_clear (gids);
182     if (!is_remove)
183       hb_set_invert (gids);
184     return true;
185   }
186 
187   char *s = (char *) arg;
188   char *p;
189 
190   while (s && *s)
191   {
192     while (*s && strchr (", ", *s))
193       s++;
194     if (!*s)
195       break;
196 
197     errno = 0;
198     hb_codepoint_t start_code = strtoul (s, &p, 10);
199     if (s[0] == '-' || errno || s == p)
200     {
201       g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
202 		   "Failed parsing glyph-index at: '%s'", s);
203       return false;
204     }
205 
206     if (p && p[0] == '-') // ranges
207     {
208       s = ++p;
209       hb_codepoint_t end_code = strtoul (s, &p, 10);
210       if (s[0] == '-' || errno || s == p)
211       {
212 	g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
213 		     "Failed parsing glyph-index at: '%s'", s);
214 	return false;
215       }
216 
217       if (end_code < start_code)
218       {
219 	g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
220 		     "Invalid glyph-index range %u-%u", start_code, end_code);
221 	return false;
222       }
223       if (!is_remove)
224         hb_set_add_range (gids, start_code, end_code);
225       else
226         hb_set_del_range (gids, start_code, end_code);
227     }
228     else
229     {
230       if (!is_remove)
231         hb_set_add (gids, start_code);
232       else
233         hb_set_del (gids, start_code);
234     }
235 
236     s = p;
237   }
238 
239   return true;
240 }
241 
242 static gboolean
parse_glyphs(const char * name G_GNUC_UNUSED,const char * arg,gpointer data,GError ** error G_GNUC_UNUSED)243 parse_glyphs (const char *name G_GNUC_UNUSED,
244 	      const char *arg,
245 	      gpointer    data,
246 	      GError    **error G_GNUC_UNUSED)
247 {
248   subset_main_t *subset_main = (subset_main_t *) data;
249   hb_bool_t is_remove = (name[strlen (name) - 1] == '-');
250   hb_bool_t is_add = (name[strlen (name) - 1] == '+');
251   hb_set_t *gids = hb_subset_input_glyph_set (subset_main->input);
252 
253   if (!is_remove && !is_add) hb_set_clear (gids);
254 
255   if (0 == strcmp (arg, "*"))
256   {
257     hb_set_clear (gids);
258     if (!is_remove)
259       hb_set_invert (gids);
260     return true;
261   }
262 
263   const char *p = arg;
264   const char *p_end = arg + strlen (arg);
265 
266   hb_font_t *font = hb_font_create (subset_main->face);
267   while (p < p_end)
268   {
269     while (p < p_end && (*p == ' ' || *p == ','))
270       p++;
271 
272     const char *end = p;
273     while (end < p_end && *end != ' ' && *end != ',')
274       end++;
275 
276     if (p < end)
277     {
278       hb_codepoint_t gid;
279       if (!hb_font_get_glyph_from_name (font, p, end - p, &gid))
280       {
281 	g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
282 		     "Failed parsing glyph name: '%s'", p);
283 	return false;
284       }
285 
286       if (!is_remove)
287         hb_set_add (gids, gid);
288       else
289         hb_set_del (gids, gid);
290     }
291 
292     p = end + 1;
293   }
294   hb_font_destroy (font);
295 
296   return true;
297 }
298 
299 static gboolean
parse_text(const char * name G_GNUC_UNUSED,const char * arg,gpointer data,GError ** error G_GNUC_UNUSED)300 parse_text (const char *name G_GNUC_UNUSED,
301 	    const char *arg,
302 	    gpointer    data,
303 	    GError    **error G_GNUC_UNUSED)
304 {
305   subset_main_t *subset_main = (subset_main_t *) data;
306   hb_bool_t is_remove = (name[strlen (name) - 1] == '-');
307   hb_bool_t is_add = (name[strlen (name) - 1] == '+');
308   hb_set_t *unicodes = hb_subset_input_unicode_set (subset_main->input);
309 
310   if (!is_remove && !is_add) hb_set_clear (unicodes);
311 
312   if (0 == strcmp (arg, "*"))
313   {
314     hb_set_clear (unicodes);
315     if (!is_remove)
316       hb_set_invert (unicodes);
317     return true;
318   }
319 
320   for (gchar *c = (gchar *) arg;
321        *c;
322        c = g_utf8_find_next_char(c, nullptr))
323   {
324     gunichar cp = g_utf8_get_char(c);
325     if (!is_remove)
326       hb_set_add (unicodes, cp);
327     else
328       hb_set_del (unicodes, cp);
329   }
330   return true;
331 }
332 
333 static gboolean
parse_unicodes(const char * name G_GNUC_UNUSED,const char * arg,gpointer data,GError ** error)334 parse_unicodes (const char *name G_GNUC_UNUSED,
335 		const char *arg,
336 		gpointer    data,
337 		GError    **error)
338 {
339   subset_main_t *subset_main = (subset_main_t *) data;
340   hb_bool_t is_remove = (name[strlen (name) - 1] == '-');
341   hb_bool_t is_add = (name[strlen (name) - 1] == '+');
342   hb_set_t *unicodes = hb_subset_input_unicode_set (subset_main->input);
343 
344   if (!is_remove && !is_add) hb_set_clear (unicodes);
345 
346   if (0 == strcmp (arg, "*"))
347   {
348     hb_set_clear (unicodes);
349     if (!is_remove)
350       hb_set_invert (unicodes);
351     return true;
352   }
353 
354   // XXX TODO Ranges
355 #define DELIMITERS "<+->{},;&#\\xXuUnNiI\n\t\v\f\r "
356 
357   char *s = (char *) arg;
358   char *p;
359 
360   while (s && *s)
361   {
362     while (*s && strchr (DELIMITERS, *s))
363       s++;
364     if (!*s)
365       break;
366 
367     errno = 0;
368     hb_codepoint_t start_code = strtoul (s, &p, 16);
369     if (errno || s == p)
370     {
371       g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
372 		   "Failed parsing Unicode at: '%s'", s);
373       return false;
374     }
375 
376     if (p && p[0] == '-') // ranges
377     {
378       s = ++p;
379       hb_codepoint_t end_code = strtoul (s, &p, 16);
380       if (s[0] == '-' || errno || s == p)
381       {
382 	g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
383 		     "Failed parsing Unicode at: '%s'", s);
384 	return false;
385       }
386 
387       if (end_code < start_code)
388       {
389 	g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
390 		     "Invalid Unicode range %u-%u", start_code, end_code);
391 	return false;
392       }
393       if (!is_remove)
394         hb_set_add_range (unicodes, start_code, end_code);
395       else
396         hb_set_del_range (unicodes, start_code, end_code);
397     }
398     else
399     {
400       if (!is_remove)
401         hb_set_add (unicodes, start_code);
402       else
403         hb_set_del (unicodes, start_code);
404     }
405 
406     s = p;
407   }
408 
409   return true;
410 }
411 
412 static gboolean
parse_nameids(const char * name,const char * arg,gpointer data,GError ** error)413 parse_nameids (const char *name,
414 	       const char *arg,
415 	       gpointer    data,
416 	       GError    **error)
417 {
418   subset_main_t *subset_main = (subset_main_t *) data;
419   hb_bool_t is_remove = (name[strlen (name) - 1] == '-');
420   hb_bool_t is_add = (name[strlen (name) - 1] == '+');
421   hb_set_t *name_ids = hb_subset_input_set (subset_main->input, HB_SUBSET_SETS_NAME_ID);
422 
423 
424   if (!is_remove && !is_add) hb_set_clear (name_ids);
425 
426   if (0 == strcmp (arg, "*"))
427   {
428     hb_set_clear (name_ids);
429     if (!is_remove)
430       hb_set_invert (name_ids);
431     return true;
432   }
433 
434   char *s = (char *) arg;
435   char *p;
436 
437   while (s && *s)
438   {
439     while (*s && strchr (", ", *s))
440       s++;
441     if (!*s)
442       break;
443 
444     errno = 0;
445     hb_codepoint_t u = strtoul (s, &p, 10);
446     if (errno || s == p)
447     {
448       g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
449 		   "Failed parsing nameID at: '%s'", s);
450       return false;
451     }
452 
453     if (!is_remove)
454     {
455       hb_set_add (name_ids, u);
456     } else {
457       hb_set_del (name_ids, u);
458     }
459 
460     s = p;
461   }
462 
463   return true;
464 }
465 
466 static gboolean
parse_name_languages(const char * name,const char * arg,gpointer data,GError ** error)467 parse_name_languages (const char *name,
468 		      const char *arg,
469 		      gpointer    data,
470 		      GError    **error)
471 {
472   subset_main_t *subset_main = (subset_main_t *) data;
473   hb_bool_t is_remove = (name[strlen (name) - 1] == '-');
474   hb_bool_t is_add = (name[strlen (name) - 1] == '+');
475   hb_set_t *name_languages = hb_subset_input_set (subset_main->input, HB_SUBSET_SETS_NAME_LANG_ID);
476 
477   if (!is_remove && !is_add) hb_set_clear (name_languages);
478 
479   if (0 == strcmp (arg, "*"))
480   {
481     hb_set_clear (name_languages);
482     if (!is_remove)
483       hb_set_invert (name_languages);
484     return true;
485   }
486 
487   char *s = (char *) arg;
488   char *p;
489 
490   while (s && *s)
491   {
492     while (*s && strchr (", ", *s))
493       s++;
494     if (!*s)
495       break;
496 
497     errno = 0;
498     hb_codepoint_t u = strtoul (s, &p, 10);
499     if (errno || s == p)
500     {
501       g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
502 		   "Failed parsing name-language code at: '%s'", s);
503       return false;
504     }
505 
506     if (!is_remove)
507     {
508       hb_set_add (name_languages, u);
509     } else {
510       hb_set_del (name_languages, u);
511     }
512 
513     s = p;
514   }
515 
516   return true;
517 }
518 
519 template <hb_subset_flags_t flag>
520 static gboolean
set_flag(const char * name,const char * arg,gpointer data,GError ** error G_GNUC_UNUSED)521 set_flag (const char *name,
522 	  const char *arg,
523 	  gpointer    data,
524 	  GError    **error G_GNUC_UNUSED)
525 {
526   subset_main_t *subset_main = (subset_main_t *) data;
527 
528   hb_subset_input_set_flags (subset_main->input,
529 			     hb_subset_input_get_flags (subset_main->input) | flag);
530 
531   return true;
532 }
533 
534 static gboolean
parse_layout_features(const char * name,const char * arg,gpointer data,GError ** error G_GNUC_UNUSED)535 parse_layout_features (const char *name,
536 		       const char *arg,
537 		       gpointer    data,
538 		       GError    **error G_GNUC_UNUSED)
539 {
540   subset_main_t *subset_main = (subset_main_t *) data;
541   hb_bool_t is_remove = (name[strlen (name) - 1] == '-');
542   hb_bool_t is_add = (name[strlen (name) - 1] == '+');
543   hb_set_t *layout_features = hb_subset_input_set (subset_main->input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG);
544 
545   if (!is_remove && !is_add) hb_set_clear (layout_features);
546 
547   if (0 == strcmp (arg, "*"))
548   {
549     hb_set_clear (layout_features);
550     if (!is_remove)
551       hb_set_invert (layout_features);
552     return true;
553   }
554 
555   char *s = strtok((char *) arg, ", ");
556   while (s)
557   {
558     if (strlen (s) > 4) // table tags are at most 4 bytes
559     {
560       g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
561                    "Failed parsing table tag at: '%s'", s);
562       return false;
563     }
564 
565     hb_tag_t tag = hb_tag_from_string (s, strlen (s));
566 
567     if (!is_remove)
568       hb_set_add (layout_features, tag);
569     else
570       hb_set_del (layout_features, tag);
571 
572     s = strtok(nullptr, ", ");
573   }
574 
575   return true;
576 }
577 
578 static gboolean
parse_drop_tables(const char * name,const char * arg,gpointer data,GError ** error)579 parse_drop_tables (const char *name,
580 		   const char *arg,
581 		   gpointer    data,
582 		   GError    **error)
583 {
584   subset_main_t *subset_main = (subset_main_t *) data;
585   hb_bool_t is_remove = (name[strlen (name) - 1] == '-');
586   hb_bool_t is_add = (name[strlen (name) - 1] == '+');
587   hb_set_t *drop_tables = hb_subset_input_set (subset_main->input, HB_SUBSET_SETS_DROP_TABLE_TAG);
588 
589   if (!is_remove && !is_add) hb_set_clear (drop_tables);
590 
591   if (0 == strcmp (arg, "*"))
592   {
593     hb_set_clear (drop_tables);
594     if (!is_remove)
595       hb_set_invert (drop_tables);
596     return true;
597   }
598 
599   char *s = strtok((char *) arg, ", ");
600   while (s)
601   {
602     if (strlen (s) > 4) // Table tags are at most 4 bytes.
603     {
604       g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
605 		   "Failed parsing table tag at: '%s'", s);
606       return false;
607     }
608 
609     hb_tag_t tag = hb_tag_from_string (s, strlen (s));
610 
611     if (!is_remove)
612       hb_set_add (drop_tables, tag);
613     else
614       hb_set_del (drop_tables, tag);
615 
616     s = strtok(nullptr, ", ");
617   }
618 
619   return true;
620 }
621 
622 template <GOptionArgFunc line_parser, bool allow_comments=true>
623 static gboolean
parse_file_for(const char * name,const char * arg,gpointer data,GError ** error)624 parse_file_for (const char *name,
625 		const char *arg,
626 		gpointer    data,
627 		GError    **error)
628 {
629   FILE *fp = nullptr;
630   if (0 != strcmp (arg, "-"))
631     fp = fopen (arg, "r");
632   else
633     fp = stdin;
634 
635   if (!fp)
636   {
637     g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
638 		 "Failed opening file `%s': %s",
639 		 arg, strerror (errno));
640     return false;
641   }
642 
643   GString *gs = g_string_new (nullptr);
644   do
645   {
646     g_string_set_size (gs, 0);
647     char buf[BUFSIZ];
648     while (fgets (buf, sizeof (buf), fp))
649     {
650       unsigned bytes = strlen (buf);
651       if (bytes && buf[bytes - 1] == '\n')
652       {
653 	bytes--;
654 	g_string_append_len (gs, buf, bytes);
655 	break;
656       }
657       g_string_append_len (gs, buf, bytes);
658     }
659     if (ferror (fp))
660     {
661       g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
662 		   "Failed reading file `%s': %s",
663 		   arg, strerror (errno));
664       return false;
665     }
666     g_string_append_c (gs, '\0');
667 
668     if (allow_comments)
669     {
670       char *comment = strchr (gs->str, '#');
671       if (comment)
672         *comment = '\0';
673     }
674 
675     line_parser ("+", gs->str, data, error);
676 
677     if (*error)
678       break;
679   }
680   while (!feof (fp));
681 
682   g_string_free (gs, false);
683 
684   return true;
685 }
686 
687 gboolean
collect_face(const char * name,const char * arg,gpointer data,GError ** error)688 subset_main_t::collect_face (const char *name,
689 			     const char *arg,
690 			     gpointer    data,
691 			     GError    **error)
692 {
693   face_options_t *thiz = (face_options_t *) data;
694 
695   if (!thiz->font_file)
696   {
697     thiz->font_file = g_strdup (arg);
698     return true;
699   }
700 
701   return true;
702 }
703 
704 gboolean
collect_rest(const char * name,const char * arg,gpointer data,GError ** error)705 subset_main_t::collect_rest (const char *name,
706 			     const char *arg,
707 			     gpointer    data,
708 			     GError    **error)
709 {
710   subset_main_t *thiz = (subset_main_t *) data;
711 
712   if (!thiz->font_file)
713   {
714     thiz->font_file = g_strdup (arg);
715     return true;
716   }
717 
718   parse_text (name, arg, data, error);
719   return true;
720 }
721 
722 void
add_options()723 subset_main_t::add_options ()
724 {
725   set_summary ("Subset fonts to specification.");
726 
727   face_options_t::add_options (this);
728 
729   GOptionEntry glyphset_entries[] =
730   {
731     {"gids",		0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_gids,
732      "Specify glyph IDs or ranges to include in the subset.\n"
733      "                                                       "
734      "Use --gids-=... to subtract codepoints from the current set.", "list of glyph indices/ranges or *"},
735     {"gids-",		0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_gids,			"Specify glyph IDs or ranges to remove from the subset", "list of glyph indices/ranges or *"},
736     {"gids+",		0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_gids,			"Specify glyph IDs or ranges to include in the subset", "list of glyph indices/ranges or *"},
737     {"gids-file",	0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_file_for<parse_gids>,	"Specify file to read glyph IDs or ranges from", "filename"},
738     {"glyphs",		0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_glyphs,			"Specify glyph names to include in the subset. Use --glyphs-=... to subtract glyphs from the current set.", "list of glyph names or *"},
739     {"glyphs+",		0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_glyphs,			"Specify glyph names to include in the subset", "list of glyph names"},
740     {"glyphs-",		0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_glyphs,			"Specify glyph names to remove from the subset", "list of glyph names"},
741 
742 
743     {"glyphs-file",	0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_file_for<parse_glyphs>,	"Specify file to read glyph names fromt", "filename"},
744 
745     {"text",		0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_text,			"Specify text to include in the subset. Use --text-=... to subtract codepoints from the current set.", "string"},
746     {"text-",		0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_text,			"Specify text to remove from the subset", "string"},
747     {"text+",		0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_text,			"Specify text to include in the subset", "string"},
748 
749 
750     {"text-file",	0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_file_for<parse_text, false>,"Specify file to read text from", "filename"},
751     {"unicodes",	0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_unicodes,
752      "Specify Unicode codepoints or ranges to include in the subset. Use * to include all codepoints.\n"
753      "                                                       "
754      "--unicodes-=... can be used to subtract codepoints from the current set.\n"
755      "                                                       "
756      "For example: --unicodes=* --unicodes-=41,42,43 would create a subset with all codepoints\n"
757      "                                                       "
758      "except for 41, 42, 43.",
759      "list of hex numbers/ranges or *"},
760     {"unicodes-",	0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_unicodes, "Specify Unicode codepoints or ranges to remove from the subset", "list of hex numbers/ranges or *"},
761     {"unicodes+",	0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_unicodes, "Specify Unicode codepoints or ranges to include in the subset", "list of hex numbers/ranges or *"},
762 
763     {"unicodes-file",	0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_file_for<parse_unicodes>,"Specify file to read Unicode codepoints or ranges from", "filename"},
764     {nullptr}
765   };
766   add_group (glyphset_entries,
767 	     "subset-glyphset",
768 	     "Subset glyph-set option:",
769 	     "Subsetting glyph-set options",
770 	     this);
771 
772   GOptionEntry other_entries[] =
773   {
774     {"name-IDs",	0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_nameids,		"Subset specified nameids. Use --name-IDs-=... to substract from the current set.", "list of int numbers or *"},
775     {"name-IDs-",	0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_nameids,		"Subset specified nameids", "list of int numbers or *"},
776     {"name-IDs+",	0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_nameids,		"Subset specified nameids", "list of int numbers or *"},
777     {"name-languages",	0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_name_languages,	"Subset nameRecords with specified language IDs. Use --name-languages-=... to substract from the current set.", "list of int numbers or *"},
778     {"name-languages-",	0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_name_languages,	"Subset nameRecords with specified language IDs", "list of int numbers or *"},
779     {"name-languages+",	0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_name_languages,	"Subset nameRecords with specified language IDs", "list of int numbers or *"},
780     {"layout-features",	0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_layout_features,	"Specify set of layout feature tags that will be preserved. Use --layout-features-=... to substract from the current set.", "list of string table tags or *"},
781     {"layout-features+",0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_layout_features,	"Specify set of layout feature tags that will be preserved", "list of string table tags or *"},
782     {"layout-features-",0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_layout_features,	"Specify set of layout feature tags that will be preserved", "list of string table tags or *"},
783     {"drop-tables",	0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_drop_tables,	"Drop the specified tables. Use --drop-tables-=... to substract from the current set.", "list of string table tags or *"},
784     {"drop-tables+",	0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_drop_tables,	"Drop the specified tables.", "list of string table tags or *"},
785     {"drop-tables-",	0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, (gpointer) &parse_drop_tables,	"Drop the specified tables.", "list of string table tags or *"},
786     {nullptr}
787   };
788   add_group (other_entries,
789 	     "subset-other",
790 	     "Subset other option:",
791 	     "Subsetting other options",
792 	     this);
793 
794   GOptionEntry flag_entries[] =
795   {
796     {"no-hinting",		0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_NO_HINTING>,		"Whether to drop hints", nullptr},
797     {"retain-gids",		0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_RETAIN_GIDS>,		"If set don't renumber glyph ids in the subset.", nullptr},
798     {"desubroutinize",		0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_DESUBROUTINIZE>,		"Remove CFF/CFF2 use of subroutines", nullptr},
799     {"name-legacy",		0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_NAME_LEGACY>,		"Keep legacy (non-Unicode) 'name' table entries", nullptr},
800     {"set-overlaps-flag",	0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_SET_OVERLAPS_FLAG>,	"Set the overlaps flag on each glyph.", nullptr},
801     {"notdef-outline",		0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_NOTDEF_OUTLINE>,		"Keep the outline of \'.notdef\' glyph", nullptr},
802     {"no-prune-unicode-ranges",	0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES>,	"Don't change the 'OS/2 ulUnicodeRange*' bits.", nullptr},
803     {"glyph-names",		0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_GLYPH_NAMES>,		"Keep PS glyph names in TT-flavored fonts. ", nullptr},
804     {nullptr}
805   };
806   add_group (flag_entries,
807 	     "subset-flags",
808 	     "Subset boolean option:",
809 	     "Subsetting boolean options",
810 	     this);
811 
812   GOptionEntry app_entries[] =
813   {
814     {"num-iterations",	'n', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT,
815      &this->num_iterations,
816      "Run subsetter N times (default: 1)", "N"},
817     {nullptr}
818   };
819   add_group (app_entries,
820 	     "subset-app",
821 	     "Subset app option:",
822 	     "Subsetting application options",
823 	     this);
824 
825   output_options_t::add_options (this);
826 
827   GOptionEntry entries[] =
828   {
829     {G_OPTION_REMAINING,	0, G_OPTION_FLAG_IN_MAIN,
830 			      G_OPTION_ARG_CALLBACK,	(gpointer) &collect_rest,	nullptr,	"[FONT-FILE] [TEXT]"},
831     {nullptr}
832   };
833   add_main_group (entries, this);
834   option_parser_t::add_options ();
835 }
836 
837 int
main(int argc,char ** argv)838 main (int argc, char **argv)
839 {
840   return batch_main<subset_main_t, true> (argc, argv);
841 }
842