[hb-shape/view] Add --list-unicodes

This commit is contained in:
Behdad Esfahbod 2023-01-18 19:39:30 -07:00
parent 13c70066de
commit bf8bb9fb83
1 changed files with 37 additions and 0 deletions

View File

@ -57,6 +57,7 @@ struct font_options_t : face_options_t
hb_bool_t sub_font = false;
hb_bool_t list_features = false;
hb_bool_t list_unicodes = false;
#ifndef HB_NO_VAR
hb_bool_t list_variations = false;
hb_variation_t *variations = nullptr;
@ -94,6 +95,7 @@ static G_GNUC_NORETURN void _list_features (hb_face_t *face);
#ifndef HB_NO_VAR
static G_GNUC_NORETURN void _list_variations (hb_face_t *face);
#endif
static G_GNUC_NORETURN void _list_unicodes (hb_font_t *font);
void
font_options_t::post_parse (GError **error)
@ -173,6 +175,9 @@ font_options_t::post_parse (GError **error)
if (list_variations)
_list_variations (face);
#endif
if (list_unicodes)
_list_unicodes (font);
}
static G_GNUC_NORETURN void
@ -396,6 +401,37 @@ parse_variations (const char *name G_GNUC_UNUSED,
}
#endif
static G_GNUC_NORETURN void
_list_unicodes (hb_font_t *font)
{
hb_face_t *face = hb_font_get_face (font);
hb_set_t *unicodes = hb_set_create ();
hb_map_t *cmap = hb_map_create ();
hb_face_collect_nominal_glyph_mapping (face, cmap, unicodes);
for (hb_codepoint_t u = HB_SET_VALUE_INVALID;
hb_set_next (unicodes, &u);)
{
hb_codepoint_t gid = hb_map_get (cmap, u);
char glyphname[64];
if (!hb_font_get_glyph_name (font, gid,
glyphname, sizeof glyphname))
snprintf (glyphname, sizeof glyphname, "gid%d", gid);
printf ("U+%04X %s\n", u, glyphname);
}
hb_map_destroy (cmap);
hb_set_destroy (unicodes);
/* TODO: List variation-selector sequences. */
exit(0);
}
static gboolean
parse_font_size (const char *name G_GNUC_UNUSED,
const char *arg,
@ -486,6 +522,7 @@ font_options_t::add_options (option_parser_t *parser)
G_OPTION_ARG_NONE, &this->sub_font, "Create a sub-font (default: false)", "boolean"},
{"ft-load-flags", 0, 0, G_OPTION_ARG_INT, &this->ft_load_flags, "Set FreeType load-flags (default: 2)", "integer"},
{"list-features", 0, 0, G_OPTION_ARG_NONE, &this->list_features, "List available font features and quit", nullptr},
{"list-unicodes", 0, 0, G_OPTION_ARG_NONE, &this->list_unicodes, "List available characters in the font and quit", nullptr},
{nullptr}
};
parser->add_group (entries,