diff --git a/util/hb-subset.cc b/util/hb-subset.cc index 5fe322237..27cbc47d6 100644 --- a/util/hb-subset.cc +++ b/util/hb-subset.cc @@ -134,9 +134,6 @@ struct subset_main_t : option_parser_t, face_options_t, output_options_t void add_options (); - public: - void post_parse (GError **error); - protected: static gboolean collect_face (const char *name, @@ -153,9 +150,6 @@ struct subset_main_t : option_parser_t, face_options_t, output_options_t unsigned num_iterations = 1; hb_subset_input_t *input = nullptr; - - /* Internal, ouch. */ - GString *glyph_names = nullptr; }; static gboolean @@ -223,13 +217,37 @@ parse_glyphs (const char *name G_GNUC_UNUSED, GError **error G_GNUC_UNUSED) { subset_main_t *subset_main = (subset_main_t *) data; + hb_set_t *gids = hb_subset_input_glyph_set (subset_main->input); - if (!subset_main->glyph_names) - subset_main->glyph_names = g_string_new (nullptr); - else - g_string_append_c (subset_main->glyph_names, ' '); + const char *p = arg; + const char *p_end = arg + strlen (arg); - g_string_append (subset_main->glyph_names, arg); + hb_font_t *font = hb_font_create (subset_main->face); + while (p < p_end) + { + while (p < p_end && (*p == ' ' || *p == ',')) + p++; + + const char *end = p; + while (end < p_end && *end != ' ' && *end != ',') + end++; + + if (p < end) + { + hb_codepoint_t gid; + if (!hb_font_get_glyph_from_name (font, p, end - p, &gid)) + { + g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, + "Failed parsing glyph name: '%s'", p); + return false; + } + + hb_set_add (gids, gid); + } + + p = end + 1; + } + hb_font_destroy (font); return true; } @@ -731,51 +749,6 @@ subset_main_t::add_options () option_parser_t::add_options (); } -void -subset_main_t::post_parse (GError **error) -{ - /* This WILL get called multiple times. Oh well... */ - - if (glyph_names) - { - char *p = glyph_names->str; - char *p_end = p + glyph_names->len; - - hb_set_t *gids = hb_subset_input_glyph_set (input); - - hb_font_t *font = hb_font_create (face); - while (p < p_end) - { - while (p < p_end && (*p == ' ' || *p == ',')) - p++; - - char *end = p; - while (end < p_end && *end != ' ' && *end != ',') - end++; - *end = '\0'; - - if (p < end) - { - hb_codepoint_t gid; - if (!hb_font_get_glyph_from_name (font, p, -1, &gid)) - { - g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, - "Failed parsing glyph name: '%s'", p); - return; - } - - hb_set_add (gids, gid); - } - - p = end + 1; - } - hb_font_destroy (font); - - g_string_free (glyph_names, false); - glyph_names = nullptr; - } -} - int main (int argc, char **argv) {