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

This commit is contained in:
Behdad Esfahbod 2023-01-18 19:43:33 -07:00
parent bf8bb9fb83
commit 8564d2266b
1 changed files with 27 additions and 1 deletions

View File

@ -58,6 +58,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;
hb_bool_t list_glyphs = false;
#ifndef HB_NO_VAR
hb_bool_t list_variations = false;
hb_variation_t *variations = nullptr;
@ -96,6 +97,7 @@ static G_GNUC_NORETURN void _list_features (hb_face_t *face);
static G_GNUC_NORETURN void _list_variations (hb_face_t *face);
#endif
static G_GNUC_NORETURN void _list_unicodes (hb_font_t *font);
static G_GNUC_NORETURN void _list_glyphs (hb_font_t *font);
void
font_options_t::post_parse (GError **error)
@ -178,6 +180,9 @@ font_options_t::post_parse (GError **error)
if (list_unicodes)
_list_unicodes (font);
if (list_glyphs)
_list_glyphs (font);
}
static G_GNUC_NORETURN void
@ -419,7 +424,7 @@ _list_unicodes (hb_font_t *font)
char glyphname[64];
if (!hb_font_get_glyph_name (font, gid,
glyphname, sizeof glyphname))
snprintf (glyphname, sizeof glyphname, "gid%d", gid);
snprintf (glyphname, sizeof glyphname, "gid%u", gid);
printf ("U+%04X %s\n", u, glyphname);
}
@ -432,6 +437,26 @@ _list_unicodes (hb_font_t *font)
exit(0);
}
static G_GNUC_NORETURN void
_list_glyphs (hb_font_t *font)
{
hb_face_t *face = hb_font_get_face (font);
unsigned num_glyphs = hb_face_get_glyph_count (face);
for (hb_codepoint_t gid = 0; gid < num_glyphs; gid++)
{
char glyphname[64];
if (!hb_font_get_glyph_name (font, gid,
glyphname, sizeof glyphname))
snprintf (glyphname, sizeof glyphname, "gid%u", gid);
printf ("%u %s\n", gid, glyphname);
}
exit(0);
}
static gboolean
parse_font_size (const char *name G_GNUC_UNUSED,
const char *arg,
@ -523,6 +548,7 @@ font_options_t::add_options (option_parser_t *parser)
{"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},
{"list-glyphs", 0, 0, G_OPTION_ARG_NONE, &this->list_glyphs, "List available glyphs in the font and quit", nullptr},
{nullptr}
};
parser->add_group (entries,