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




commit 1554fe3aaeeb72d0445bffd1ddd54366bf6bca48
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 | 55 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 48 insertions(+), 7 deletions(-)
---
diff --git a/utils/pango-list.c b/utils/pango-list.c
index 2b59c4e0..f82c916d 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,14 +164,30 @@ 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,
                    width - (int)strlen (face_name) - (int)strlen (synth_str) - (int)strlen (variable_str), 
"", desc_str);


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