[pango/simple-fontmap: 22/22] pango-list: Show origin of aliases




commit 83e358fe068fac42525edb273c5349ffa00cfd61
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Dec 29 13:03:55 2021 -0500

    pango-list: Show origin of aliases
    
    When showing a font description for faces, show
    the original family name of generic aliases. This
    is much more useful.

 utils/pango-list.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 49 insertions(+), 8 deletions(-)
---
diff --git a/utils/pango-list.c b/utils/pango-list.c
index 39aa6adc..3d976f7a 100644
--- a/utils/pango-list.c
+++ b/utils/pango-list.c
@@ -42,6 +42,31 @@ denorm_coord (hb_ot_var_axis_info_t *axis, int coord)
     return coord * (axis->max_value - axis->default_value) / 16384.f + axis->default_value;
 }
 
+static char *
+get_name_from_hb_face (hb_face_t       *face,
+                       hb_ot_name_id_t  name_id,
+                       hb_ot_name_id_t  fallback_id)
+{
+  char buf[256];
+  unsigned int len;
+  hb_language_t language;
+
+  language = hb_language_from_string ("en", -1);
+
+  len = sizeof (buf);
+  if (hb_ot_name_get_utf8 (face, name_id, language, &len, buf) > 0)
+    return g_strdup (buf);
+
+  if (fallback_id != HB_OT_NAME_ID_INVALID)
+    {
+      len = sizeof (buf);
+      if (hb_ot_name_get_utf8 (face, fallback_id, language, &len, buf) > 0)
+        return g_strdup (buf);
+    }
+
+  return g_strdup ("Unnamed");
+}
+
 int
 main (int    argc,
       char **argv)
@@ -139,16 +164,32 @@ main (int    argc,
         }
 
       for (j = 0; j < n_faces; j++)
-       {
-         const char *face_name = pango_font_face_get_face_name (faces[j]);
-         gboolean is_synth = pango_font_face_is_synthesized (faces[j]);
-         const char *synth_str = is_synth ? "*" : "";
+        {
+          const char *face_name = pango_font_face_get_face_name (faces[j]);
+          gboolean is_synth = pango_font_face_is_synthesized (faces[j]);
+          const char *synth_str = is_synth ? "*" : "";
           gboolean is_variable = pango_font_face_is_variable (faces[j]);
-         const char *variable_str = is_variable ? "@" : "";
-         PangoFontDescription *desc = pango_font_face_describe (faces[j]);
-         char *desc_str = pango_font_description_to_string (desc);
+          const char *variable_str = is_variable ? "@" : "";
+          PangoFontDescription *desc;
+          char *desc_str;
+
+          desc = pango_font_face_describe (faces[j]);
+
+          if (pango_font_face_is_synthesized (faces[j]) && PANGO_IS_HB_FACE (faces[j]))
+            {
+              hb_face_t *hbface = pango_hb_face_get_hb_face (PANGO_HB_FACE (faces[j]));
+              char *family = get_name_from_hb_face (hbface,
+                                                    HB_OT_NAME_ID_TYPOGRAPHIC_FAMILY,
+                                                    HB_OT_NAME_ID_FONT_FAMILY);
+
+              pango_font_description_set_family (desc, family);
+
+              g_free (family);
+            }
+
+          desc_str = pango_font_description_to_string (desc);
 
-         g_print ("  %s%s%s: %*s%s\n", synth_str, variable_str, face_name,
+          g_print ("  %s%s%s: %*s%s\n", synth_str, variable_str, face_name,
                    width - (int)strlen (face_name) - (int)strlen (synth_str), "", desc_str);
 
           pango_font_description_set_absolute_size (desc, 10 * PANGO_SCALE);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]