[pango/variation-coords: 2/3] pango-list: Optionally show variations



commit af22e10dc8772fe55f1633b3e412cb6c49ddff5b
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jul 25 08:02:50 2019 -0400

    pango-list: Optionally show variations

 utils/pango-list.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
---
diff --git a/utils/pango-list.c b/utils/pango-list.c
index c0f0d4ae..56f80bbc 100644
--- a/utils/pango-list.c
+++ b/utils/pango-list.c
@@ -22,6 +22,7 @@
 
 #include "config.h"
 #include <pango/pangocairo.h>
+#include <harfbuzz/hb-ot.h>
 #include <glib/gstdio.h>
 #include <stdlib.h>
 
@@ -31,9 +32,11 @@ main (int    argc,
 {
   gboolean opt_verbose = FALSE;
   gboolean opt_metrics = FALSE;
+  gboolean opt_variations = FALSE;
   GOptionEntry entries[] = {
     {"verbose", 0, 0, G_OPTION_ARG_NONE,    &opt_verbose, "Print verbose information", NULL },
     {"metrics", 0, 0, G_OPTION_ARG_NONE,    &opt_metrics, "Print font metrics", NULL },
+    {"variations", 0, 0, G_OPTION_ARG_NONE,    &opt_variations, "Print font variations", NULL },
     { NULL, }
   };
   GOptionContext *context;
@@ -133,6 +136,44 @@ main (int    argc,
               pango_font_metrics_unref (metrics);
             }
 
+          if (opt_variations &&
+              pango_font_family_is_variable (families[i]))
+            {
+              PangoFont *font;
+              hb_font_t *hb_font;
+              const int *coords;
+              unsigned int length;
+
+              pango_font_description_set_absolute_size (desc, 10 * PANGO_SCALE);
+
+              font = pango_context_load_font (ctx, desc);
+              hb_font = pango_font_get_hb_font (font);
+              coords = hb_font_get_var_coords_normalized (hb_font, &length);
+              if (coords)
+                {
+                  hb_face_t *hb_face = hb_font_get_face (hb_font);
+                  hb_ot_var_axis_info_t *axes;
+                  unsigned int n_axes;
+                  int i;
+
+                  axes = g_new (hb_ot_var_axis_info_t, length);
+                  n_axes = length;
+
+                  hb_ot_var_get_axis_infos (hb_face, 0, &n_axes, axes);
+
+                  for (i = 0; i < length; i++)
+                    {
+                      char name[20];
+                      unsigned int namelen = 20;
+
+                      hb_ot_name_get_utf8 (hb_face, axes[i].name_id, HB_LANGUAGE_INVALID, &namelen, name);
+
+                      g_print ("    %s: %d (%g - %g, %g)\n", name, coords[i], axes[i].min_value, 
axes[i].max_value, axes[i].default_value);
+                    }
+                  g_free (axes);
+                }
+            }
+
          g_free (desc_str);
          pango_font_description_free (desc);
        }


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