[hb-info] Add --list-baselines

This commit is contained in:
Behdad Esfahbod 2023-01-22 15:11:50 -07:00
parent 9c62022ded
commit 4142a460af
1 changed files with 67 additions and 1 deletions

View File

@ -107,6 +107,7 @@ struct info_t
#ifdef HB_HAS_GOBJECT #ifdef HB_HAS_GOBJECT
{"list-style", 0, 0, G_OPTION_ARG_NONE, &this->list_style, "List style", nullptr}, {"list-style", 0, 0, G_OPTION_ARG_NONE, &this->list_style, "List style", nullptr},
{"list-metrics", 0, 0, G_OPTION_ARG_NONE, &this->list_metrics, "List metrics", nullptr}, {"list-metrics", 0, 0, G_OPTION_ARG_NONE, &this->list_metrics, "List metrics", nullptr},
{"list-baselines",0, 0, G_OPTION_ARG_NONE, &this->list_baselines, "List baselines", nullptr},
#endif #endif
{"list-tables", 'l', 0, G_OPTION_ARG_NONE, &this->list_tables, "List tables", nullptr}, {"list-tables", 'l', 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-unicodes", 0, 0, G_OPTION_ARG_NONE, &this->list_unicodes, "List characters", nullptr},
@ -172,6 +173,7 @@ struct info_t
#ifdef HB_HAS_GOBJECT #ifdef HB_HAS_GOBJECT
hb_bool_t list_style = false; hb_bool_t list_style = false;
hb_bool_t list_metrics = false; hb_bool_t list_metrics = false;
hb_bool_t list_baselines = false;
#endif #endif
hb_bool_t list_tables = false; hb_bool_t list_tables = false;
hb_bool_t list_unicodes = false; hb_bool_t list_unicodes = false;
@ -236,6 +238,7 @@ struct info_t
#ifdef HB_HAS_GOBJECT #ifdef HB_HAS_GOBJECT
list_style = list_style =
list_metrics = list_metrics =
list_baselines =
#endif #endif
list_tables = list_tables =
list_unicodes = list_unicodes =
@ -272,6 +275,7 @@ struct info_t
#ifdef HB_HAS_GOBJECT #ifdef HB_HAS_GOBJECT
if (list_style) _list_style (); if (list_style) _list_style ();
if (list_metrics) _list_metrics (); if (list_metrics) _list_metrics ();
if (list_baselines) _list_baselines ();
#endif #endif
if (list_tables) _list_tables (); if (list_tables) _list_tables ();
if (list_unicodes) _list_unicodes (); if (list_unicodes) _list_unicodes ();
@ -490,7 +494,6 @@ struct info_t
void _get_baseline () void _get_baseline ()
{ {
hb_tag_t script_tags[HB_OT_MAX_TAGS_PER_SCRIPT]; hb_tag_t script_tags[HB_OT_MAX_TAGS_PER_SCRIPT];
hb_tag_t language_tags[HB_OT_MAX_TAGS_PER_LANGUAGE]; hb_tag_t language_tags[HB_OT_MAX_TAGS_PER_LANGUAGE];
unsigned script_count = HB_OT_MAX_TAGS_PER_SCRIPT; unsigned script_count = HB_OT_MAX_TAGS_PER_SCRIPT;
@ -508,6 +511,7 @@ struct info_t
if (ot_language_str) if (ot_language_str)
language_tag = hb_tag_from_string (ot_language_str, -1); language_tag = hb_tag_from_string (ot_language_str, -1);
bool fallback = false; bool fallback = false;
for (char **p = get_baseline; *p; p++) for (char **p = get_baseline; *p; p++)
{ {
@ -645,6 +649,68 @@ struct info_t
printf ("\n[*] Fallback value\n"); printf ("\n[*] Fallback value\n");
} }
} }
void _list_baselines ()
{
hb_tag_t script_tags[HB_OT_MAX_TAGS_PER_SCRIPT];
hb_tag_t language_tags[HB_OT_MAX_TAGS_PER_LANGUAGE];
unsigned script_count = HB_OT_MAX_TAGS_PER_SCRIPT;
unsigned language_count = HB_OT_MAX_TAGS_PER_LANGUAGE;
hb_ot_tags_from_script_and_language (script, language,
&script_count, script_tags,
&language_count, language_tags);
hb_tag_t script_tag = script_count ? script_tags[script_count - 1] : HB_TAG_NONE;
hb_tag_t language_tag = language_count ? language_tags[0] : HB_TAG_NONE;
if (ot_script_str)
script_tag = hb_tag_from_string (ot_script_str, -1);
if (ot_language_str)
language_tag = hb_tag_from_string (ot_language_str, -1);
if (verbose)
{
separator ();
printf ("Baselines information:\n\n");
printf ("Tag: Name Value\n---------------------------------------------\n");
}
GEnumClass *enum_class = (GEnumClass *) g_type_class_ref ((GType) HB_GOBJECT_TYPE_OT_LAYOUT_BASELINE_TAG);
bool any_fallback = false;
unsigned count = enum_class->n_values;
const auto *entries = enum_class->values;
for (unsigned i = 0; i < count; i++)
{
bool fallback = false;
hb_position_t v;
if (!hb_ot_layout_get_baseline (font, (hb_ot_layout_baseline_tag_t) entries[i].value,
direction, script_tag, language_tag,
&v))
{
hb_ot_layout_get_baseline_with_fallback (font, (hb_ot_layout_baseline_tag_t) entries[i].value,
direction, script_tag, language_tag,
&v);
any_fallback = fallback = true;
}
printf ("%c%c%c%c", HB_UNTAG(entries[i].value));
if (verbose)
printf (": %-33s", entries[i].value_nick);
printf (" %d ", v);
if (fallback)
printf ("*");
printf ("\n");
}
if (verbose && any_fallback)
{
printf ("\n[*] Fallback value\n");
}
}
#endif #endif
void _list_tables () void _list_tables ()