[subset] Add drop-tables option to hb-subset util.
authorGarret Rieger <grieger@google.com>
Thu, 16 May 2019 22:13:39 +0000 (15:13 -0700)
committerGarret Rieger <grieger@google.com>
Mon, 20 May 2019 20:35:46 +0000 (13:35 -0700)
util/hb-subset.cc
util/options.cc
util/options.hh

index 682ca4c..5ac541a 100644 (file)
@@ -94,6 +94,7 @@ struct subset_consumer_t
     hb_subset_input_set_retain_gids (input, subset_options.retain_gids);
     hb_subset_input_set_desubroutinize (input, subset_options.desubroutinize);
     hb_set_set (hb_subset_input_nameid_set (input), subset_options.name_ids);
+    hb_set_set (hb_subset_input_drop_tables_set (input), subset_options.drop_tables);
 
     hb_face_t *face = hb_font_get_face (font);
 
index a9b3fc7..1d7798b 100644 (file)
@@ -31,6 +31,8 @@
 #endif
 #include <hb-ot.h>
 
+#define DELIMITERS "<+>{},;&#\\xXuUnNiI\n\t\v\f\r "
+
 static struct supported_font_funcs_t {
        char name[4];
        void (*func) (hb_font_t *);
@@ -352,7 +354,7 @@ parse_unicodes (const char *name G_GNUC_UNUSED,
 
   while (s && *s)
   {
-    while (*s && strchr ("<+>{},;&#\\xXuUnNiI\n\t\v\f\r ", *s))
+    while (*s && strchr (DELIMITERS, *s))
       s++;
     if (!*s)
       break;
@@ -985,7 +987,7 @@ parse_nameids (const char *name G_GNUC_UNUSED,
 
   while (s && *s)
   {
-    while (*s && strchr ("<+>{},;&#\\xXuUnNiI\n\t\v\f\r ", *s))
+    while (*s && strchr (DELIMITERS, *s))
       s++;
     if (!*s)
       break;
@@ -1013,6 +1015,43 @@ parse_nameids (const char *name G_GNUC_UNUSED,
   return true;
 }
 
+static gboolean
+parse_drop_tables (const char *name G_GNUC_UNUSED,
+                   const char *arg,
+                   gpointer    data,
+                   GError    **error G_GNUC_UNUSED)
+{
+  subset_options_t *subset_opts = (subset_options_t *) data;
+
+  hb_set_clear (subset_opts->drop_tables);
+  char *s = (char *) arg;
+
+  while (s && *s)
+  {
+    while (*s && strchr (", ", *s))
+      s++;
+    if (!*s)
+      break;
+
+    char *p = s;
+    while (*p && !strchr (", ", *p))
+      p++;
+
+    if ((p - s) > 4) // Table tags are at most 4 bytes.
+    {
+      g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
+                   "Failed parsing table tag values at: '%s'", s);
+      return false;
+    }
+
+    hb_tag_t tag = hb_tag_from_string (s, p -s);
+    hb_set_add (subset_opts->drop_tables, tag);
+    s = p;
+  }
+
+  return true;
+}
+
 
 void
 subset_options_t::add_options (option_parser_t *parser)
@@ -1024,6 +1063,7 @@ subset_options_t::add_options (option_parser_t *parser)
     {"retain-gids", 0, 0, G_OPTION_ARG_NONE,  &this->retain_gids,   "If set don't renumber glyph ids in the subset.",   nullptr},
     {"desubroutinize", 0, 0, G_OPTION_ARG_NONE,  &this->desubroutinize,   "Remove CFF/CFF2 use of subroutines",   nullptr},
     {"name-IDs", 0, 0, G_OPTION_ARG_CALLBACK,  (gpointer) &parse_nameids,  "Subset specified nameids", "list of int numbers"},
+    {"drop-tables", 0, 0, G_OPTION_ARG_CALLBACK,  (gpointer) &parse_drop_tables,  "Drop the specified tables.", "list of string table tags."},
 
     {nullptr}
   };
@@ -1033,4 +1073,3 @@ subset_options_t::add_options (option_parser_t *parser)
          "Options subsetting",
          this);
 }
-
index 2691e22..3c3d32b 100644 (file)
@@ -678,6 +678,7 @@ struct subset_options_t : option_group_t
     retain_gids = false;
     desubroutinize = false;
     name_ids = hb_set_create ();
+    drop_tables = hb_set_create();
 
     add_options (parser);
   }
@@ -685,6 +686,7 @@ struct subset_options_t : option_group_t
   virtual ~subset_options_t ()
   {
     hb_set_destroy (name_ids);
+    hb_set_destroy (drop_tables);
   }
 
 
@@ -695,6 +697,7 @@ struct subset_options_t : option_group_t
   hb_bool_t retain_gids;
   hb_bool_t desubroutinize;
   hb_set_t *name_ids;
+  hb_set_t *drop_tables;
 };
 
 /* fallback implementation for scalbn()/scalbnf() for pre-2013 MSVC */