[hb-info] Flesh out

pull/4048/head
Behdad Esfahbod 2 years ago
parent ca903f7531
commit 1816d3664d
  1. 29
      util/face-options.hh
  2. 281
      util/font-options.hh
  3. 318
      util/hb-info.cc

@ -60,15 +60,12 @@ struct face_options_t
char *font_file = nullptr;
unsigned face_index = 0;
hb_bool_t list_tables = false;
hb_blob_t *blob = nullptr;
hb_face_t *face = nullptr;
};
static G_GNUC_NORETURN void _list_tables (hb_face_t *face);
face_options_t::cache_t face_options_t::cache {};
void
@ -124,31 +121,6 @@ face_options_t::post_parse (GError **error)
blob = cache.blob;
face = cache.face;
if (list_tables)
_list_tables (face);
}
static G_GNUC_NORETURN void _list_tables (hb_face_t *face)
{
unsigned count = hb_face_get_table_tags (face, 0, nullptr, nullptr);
hb_tag_t *tags = (hb_tag_t *) calloc (count, sizeof (hb_tag_t));
hb_face_get_table_tags (face, 0, &count, tags);
for (unsigned i = 0; i < count; i++)
{
hb_tag_t tag = tags[i];
hb_blob_t *blob = hb_face_reference_table (face, tag);
printf ("%c%c%c%c: %8u bytes\n", HB_UNTAG (tag), hb_blob_get_length (blob));
hb_blob_destroy (blob);
}
free (tags);
exit (0);
}
void
@ -158,7 +130,6 @@ face_options_t::add_options (option_parser_t *parser)
{
{"font-file", 0, 0, G_OPTION_ARG_STRING, &this->font_file, "Set font file-name", "filename"},
{"face-index", 0, 0, G_OPTION_ARG_INT, &this->face_index, "Set face index (default: 0)", "index"},
{"list-tables", 0, 0, G_OPTION_ARG_NONE, &this->list_tables, "List font tables and quit", nullptr},
{nullptr}
};
parser->add_group (entries,

@ -56,11 +56,7 @@ struct font_options_t : face_options_t
void post_parse (GError **error);
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;
unsigned int num_variations = 0;
#endif
@ -92,13 +88,6 @@ static struct supported_font_funcs_t {
};
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);
static G_GNUC_NORETURN void _list_glyphs (hb_font_t *font);
void
font_options_t::post_parse (GError **error)
{
@ -169,199 +158,9 @@ font_options_t::post_parse (GError **error)
hb_font_set_scale (old_font, scale_x * 2, scale_y * 2);
hb_font_destroy (old_font);
}
if (list_features)
_list_features (face);
#ifndef HB_NO_VAR
if (list_variations)
_list_variations (face);
#endif
if (list_unicodes)
_list_unicodes (font);
if (list_glyphs)
_list_glyphs (font);
}
static G_GNUC_NORETURN void
_list_features (hb_face_t *face)
{
hb_tag_t table_tags[] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS, HB_TAG_NONE};
auto language = hb_language_get_default ();
hb_set_t *features = hb_set_create ();
for (unsigned int i = 0; table_tags[i]; i++)
{
printf ("Table: %c%c%c%c\n", HB_UNTAG (table_tags[i]));
hb_tag_t script_array[32];
unsigned script_count = sizeof script_array / sizeof script_array[0];
unsigned script_offset = 0;
do
{
hb_ot_layout_table_get_script_tags (face, table_tags[i],
script_offset,
&script_count,
script_array);
for (unsigned script_index = 0; script_index < script_count; script_index++)
{
printf (" Script: %c%c%c%c\n", HB_UNTAG (script_array[script_index]));
hb_tag_t language_array[32];
unsigned language_count = sizeof language_array / sizeof language_array[0];
unsigned language_offset = 0;
do
{
hb_ot_layout_script_get_language_tags (face, table_tags[i],
script_offset + script_index,
language_offset,
&language_count,
language_array);
for (unsigned language_index = 0; language_index < language_count; language_index++)
{
printf (" Language: %c%c%c%c\n", HB_UNTAG (language_array[language_index]));
}
language_offset += language_count;
}
while (language_count == sizeof language_array / sizeof language_array[0]);
}
script_offset += script_count;
}
while (script_count == sizeof script_array / sizeof script_array[0]);
hb_set_clear (features);
hb_tag_t feature_array[32];
unsigned feature_count = sizeof feature_array / sizeof feature_array[0];
unsigned feature_offset = 0;
do
{
hb_ot_layout_table_get_feature_tags (face, table_tags[i],
feature_offset,
&feature_count,
feature_array);
for (unsigned feature_index = 0; feature_index < feature_count; feature_index++)
{
if (hb_set_has (features, feature_array[feature_index]))
continue;
hb_set_add (features, feature_array[feature_index]);
hb_ot_name_id_t label_id;
hb_ot_layout_feature_get_name_ids (face,
table_tags[i],
feature_offset + feature_index,
&label_id,
nullptr,
nullptr,
nullptr,
nullptr);
char name[64];
unsigned name_len = sizeof name;
hb_ot_name_get_utf8 (face, label_id,
language,
&name_len, name);
printf (" Feature: %c%c%c%c", HB_UNTAG (feature_array[feature_index]));
if (*name)
printf (" \"%s\"", name);
printf ("\n");
}
feature_offset += feature_count;
}
while (feature_count == sizeof feature_array / sizeof feature_array[0]);
}
hb_set_destroy (features);
exit (0);
}
#ifndef HB_NO_VAR
static G_GNUC_NORETURN void
_list_variations (hb_face_t *face)
{
hb_ot_var_axis_info_t *axes;
unsigned count = hb_ot_var_get_axis_infos (face, 0, nullptr, nullptr);
axes = (hb_ot_var_axis_info_t *) calloc (count, sizeof (hb_ot_var_axis_info_t));
hb_ot_var_get_axis_infos (face, 0, &count, axes);
auto language = hb_language_get_default ();
bool has_hidden = false;
printf ("Varitation axes:\n");
printf ("Tag: Minimum Default Maximum Name\n\n");
for (unsigned i = 0; i < count; i++)
{
const auto &axis = axes[i];
if (axis.flags & HB_OT_VAR_AXIS_FLAG_HIDDEN)
has_hidden = true;
char name[64];
unsigned name_len = sizeof name;
hb_ot_name_get_utf8 (face, axis.name_id,
language,
&name_len, name);
printf ("%c%c%c%c%s: %g %g %g %s\n",
HB_UNTAG (axis.tag),
axis.flags & HB_OT_VAR_AXIS_FLAG_HIDDEN ? "*" : "",
(double) axis.min_value,
(double) axis.default_value,
(double) axis.max_value,
name);
}
if (has_hidden)
printf ("\n[*] Hidden axis\n");
free (axes);
axes = nullptr;
count = hb_ot_var_get_named_instance_count (face);
if (count)
{
printf ("\n\nNamed instances: \n\n");
for (unsigned i = 0; i < count; i++)
{
char name[64];
unsigned name_len = sizeof name;
hb_ot_name_id_t name_id = hb_ot_var_named_instance_get_subfamily_name_id (face, i);
hb_ot_name_get_utf8 (face, name_id,
language,
&name_len, name);
unsigned coords_count = hb_ot_var_named_instance_get_design_coords (face, i, nullptr, nullptr);
float* coords;
coords = (float *) calloc (coords_count, sizeof (float));
hb_ot_var_named_instance_get_design_coords (face, i, &coords_count, coords);
printf ("%u. %-32s", i, name);
for (unsigned j = 0; j < coords_count; j++)
printf ("%g, ", (double) coords[j]);
printf ("\n");
free (coords);
}
}
exit(0);
}
static gboolean
parse_variations (const char *name G_GNUC_UNUSED,
const char *arg,
@ -406,82 +205,6 @@ 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];
hb_font_glyph_to_string (font, gid,
glyphname, sizeof glyphname);
printf ("U+%04X %s\n", u, glyphname);
}
hb_map_destroy (cmap);
/* List variation-selector sequences. */
hb_set_t *vars = hb_set_create ();
hb_face_collect_variation_selectors (face, vars);
for (hb_codepoint_t vs = HB_SET_VALUE_INVALID;
hb_set_next (vars, &vs);)
{
hb_set_clear (unicodes);
hb_face_collect_variation_unicodes (face, vs, unicodes);
for (hb_codepoint_t u = HB_SET_VALUE_INVALID;
hb_set_next (unicodes, &u);)
{
hb_codepoint_t gid = 0;
bool b = hb_font_get_variation_glyph (font, u, vs, &gid);
assert (b);
char glyphname[64];
hb_font_glyph_to_string (font, gid,
glyphname, sizeof glyphname);
printf ("U+%04X,U+%04X %s\n", vs, u, glyphname);
}
}
hb_set_destroy (vars);
hb_set_destroy (unicodes);
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];
hb_font_glyph_to_string (font, gid,
glyphname, sizeof glyphname);
printf ("%u %s\n", gid, glyphname);
}
exit(0);
}
static gboolean
parse_font_size (const char *name G_GNUC_UNUSED,
const char *arg,
@ -571,9 +294,6 @@ font_options_t::add_options (option_parser_t *parser)
{"sub-font", 0, G_OPTION_FLAG_HIDDEN,
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},
{"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,
@ -598,7 +318,6 @@ font_options_t::add_options (option_parser_t *parser)
GOptionEntry entries2[] =
{
{"list-variations", 0, 0, G_OPTION_ARG_NONE, &this->list_variations, "List available font variations and quit", nullptr},
{"named-instance", 0, 0, G_OPTION_ARG_INT, &this->named_instance, "Set named-instance index (default: none)", "index"},
{"variations", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_variations, variations_help, "list"},
{nullptr}

@ -36,11 +36,325 @@ struct info_t
{
void add_options (option_parser_t *parser)
{
GOptionEntry entries[] =
{
{"list-all", 0, 0, G_OPTION_ARG_NONE, &this->list_all, "List everything", nullptr},
{"list-tables", 0, 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr},
{"list-unicodes", 0, 0, G_OPTION_ARG_NONE, &this->list_unicodes, "List characters", nullptr},
{"list-glyphs", 0, 0, G_OPTION_ARG_NONE, &this->list_glyphs, "List glyphs", nullptr},
{"list-features", 0, 0, G_OPTION_ARG_NONE, &this->list_features, "List layout features", nullptr},
#ifndef HB_NO_VAR
{"list-variations",0, 0, G_OPTION_ARG_NONE, &this->list_variations, "List variations", nullptr},
#endif
{nullptr}
};
parser->add_group (entries,
"query",
"Query options:",
"Options to query the font instance",
this,
false /* We add below. */);
}
private:
hb_bool_t list_all;
hb_bool_t list_tables;
hb_bool_t list_unicodes;
hb_bool_t list_glyphs;
hb_bool_t list_features;
#ifndef HB_NO_VAR
hb_bool_t list_variations;
#endif
public:
void operator () (font_options_t *font_opts)
{
if (list_all)
{
list_tables =
list_unicodes =
list_glyphs =
list_features =
#ifndef HB_NO_VAR
list_variations =
#endif
true;
}
if (list_tables) _list_tables (font_opts->face);
if (list_unicodes) _list_unicodes (font_opts->font);
if (list_glyphs) _list_glyphs (font_opts->font);
if (list_features) _list_features (font_opts->face);
#ifndef HB_NO_VAR
if (list_variations) _list_variations (font_opts->face);
#endif
}
void _list_tables (hb_face_t *face)
{
unsigned count = hb_face_get_table_tags (face, 0, nullptr, nullptr);
hb_tag_t *tags = (hb_tag_t *) calloc (count, sizeof (hb_tag_t));
hb_face_get_table_tags (face, 0, &count, tags);
for (unsigned i = 0; i < count; i++)
{
hb_tag_t tag = tags[i];
hb_blob_t *blob = hb_face_reference_table (face, tag);
printf ("%c%c%c%c: %8u bytes\n", HB_UNTAG (tag), hb_blob_get_length (blob));
hb_blob_destroy (blob);
}
free (tags);
}
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];
hb_font_glyph_to_string (font, gid,
glyphname, sizeof glyphname);
printf ("U+%04X %s\n", u, glyphname);
}
hb_map_destroy (cmap);
/* List variation-selector sequences. */
hb_set_t *vars = hb_set_create ();
hb_face_collect_variation_selectors (face, vars);
for (hb_codepoint_t vs = HB_SET_VALUE_INVALID;
hb_set_next (vars, &vs);)
{
hb_set_clear (unicodes);
hb_face_collect_variation_unicodes (face, vs, unicodes);
for (hb_codepoint_t u = HB_SET_VALUE_INVALID;
hb_set_next (unicodes, &u);)
{
hb_codepoint_t gid = 0;
bool b = hb_font_get_variation_glyph (font, u, vs, &gid);
assert (b);
char glyphname[64];
hb_font_glyph_to_string (font, gid,
glyphname, sizeof glyphname);
printf ("U+%04X,U+%04X %s\n", vs, u, glyphname);
}
}
hb_set_destroy (vars);
hb_set_destroy (unicodes);
}
void operator () ()
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];
hb_font_glyph_to_string (font, gid,
glyphname, sizeof glyphname);
printf ("%u %s\n", gid, glyphname);
}
}
void
_list_features (hb_face_t *face)
{
hb_tag_t table_tags[] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS, HB_TAG_NONE};
auto language = hb_language_get_default ();
hb_set_t *features = hb_set_create ();
for (unsigned int i = 0; table_tags[i]; i++)
{
printf ("Table: %c%c%c%c\n", HB_UNTAG (table_tags[i]));
hb_tag_t script_array[32];
unsigned script_count = sizeof script_array / sizeof script_array[0];
unsigned script_offset = 0;
do
{
hb_ot_layout_table_get_script_tags (face, table_tags[i],
script_offset,
&script_count,
script_array);
for (unsigned script_index = 0; script_index < script_count; script_index++)
{
printf (" Script: %c%c%c%c\n", HB_UNTAG (script_array[script_index]));
hb_tag_t language_array[32];
unsigned language_count = sizeof language_array / sizeof language_array[0];
unsigned language_offset = 0;
do
{
hb_ot_layout_script_get_language_tags (face, table_tags[i],
script_offset + script_index,
language_offset,
&language_count,
language_array);
for (unsigned language_index = 0; language_index < language_count; language_index++)
{
printf (" Language: %c%c%c%c\n", HB_UNTAG (language_array[language_index]));
}
language_offset += language_count;
}
while (language_count == sizeof language_array / sizeof language_array[0]);
}
script_offset += script_count;
}
while (script_count == sizeof script_array / sizeof script_array[0]);
hb_set_clear (features);
hb_tag_t feature_array[32];
unsigned feature_count = sizeof feature_array / sizeof feature_array[0];
unsigned feature_offset = 0;
do
{
hb_ot_layout_table_get_feature_tags (face, table_tags[i],
feature_offset,
&feature_count,
feature_array);
for (unsigned feature_index = 0; feature_index < feature_count; feature_index++)
{
if (hb_set_has (features, feature_array[feature_index]))
continue;
hb_set_add (features, feature_array[feature_index]);
hb_ot_name_id_t label_id;
hb_ot_layout_feature_get_name_ids (face,
table_tags[i],
feature_offset + feature_index,
&label_id,
nullptr,
nullptr,
nullptr,
nullptr);
char name[64];
unsigned name_len = sizeof name;
hb_ot_name_get_utf8 (face, label_id,
language,
&name_len, name);
printf (" Feature: %c%c%c%c", HB_UNTAG (feature_array[feature_index]));
if (*name)
printf (" \"%s\"", name);
printf ("\n");
}
feature_offset += feature_count;
}
while (feature_count == sizeof feature_array / sizeof feature_array[0]);
}
hb_set_destroy (features);
}
#ifndef HB_NO_VAR
void
_list_variations (hb_face_t *face)
{
hb_ot_var_axis_info_t *axes;
unsigned count = hb_ot_var_get_axis_infos (face, 0, nullptr, nullptr);
axes = (hb_ot_var_axis_info_t *) calloc (count, sizeof (hb_ot_var_axis_info_t));
hb_ot_var_get_axis_infos (face, 0, &count, axes);
auto language = hb_language_get_default ();
bool has_hidden = false;
printf ("Varitation axes:\n");
printf ("Tag: Minimum Default Maximum Name\n\n");
for (unsigned i = 0; i < count; i++)
{
const auto &axis = axes[i];
if (axis.flags & HB_OT_VAR_AXIS_FLAG_HIDDEN)
has_hidden = true;
char name[64];
unsigned name_len = sizeof name;
hb_ot_name_get_utf8 (face, axis.name_id,
language,
&name_len, name);
printf ("%c%c%c%c%s: %g %g %g %s\n",
HB_UNTAG (axis.tag),
axis.flags & HB_OT_VAR_AXIS_FLAG_HIDDEN ? "*" : "",
(double) axis.min_value,
(double) axis.default_value,
(double) axis.max_value,
name);
}
if (has_hidden)
printf ("\n[*] Hidden axis\n");
free (axes);
axes = nullptr;
count = hb_ot_var_get_named_instance_count (face);
if (count)
{
printf ("\n\nNamed instances: \n\n");
for (unsigned i = 0; i < count; i++)
{
char name[64];
unsigned name_len = sizeof name;
hb_ot_name_id_t name_id = hb_ot_var_named_instance_get_subfamily_name_id (face, i);
hb_ot_name_get_utf8 (face, name_id,
language,
&name_len, name);
unsigned coords_count = hb_ot_var_named_instance_get_design_coords (face, i, nullptr, nullptr);
float* coords;
coords = (float *) calloc (coords_count, sizeof (float));
hb_ot_var_named_instance_get_design_coords (face, i, &coords_count, coords);
printf ("%u. %-32s", i, name);
for (unsigned j = 0; j < coords_count; j++)
printf ("%g, ", (double) coords[j]);
printf ("\n");
free (coords);
}
}
}
#endif
};
@ -56,7 +370,7 @@ struct main_font_t :
add_options ();
parse (&argc, &argv);
consumer_t::operator () ();
consumer_t::operator () (this);
return 0;
}

Loading…
Cancel
Save