[pango/simple-fontmap: 9/9] pango-list: Add a --fontmap option




commit acb4e84e9011292df96fe6edc10c9bfa9b58af56
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Dec 21 23:18:09 2021 -0500

    pango-list: Add a --fontmap option
    
    This lets us test the new fc fontmap implementation.

 utils/meson.build  |  3 ++-
 utils/pango-list.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 71 insertions(+), 10 deletions(-)
---
diff --git a/utils/meson.build b/utils/meson.build
index 6d06dbec..c76d35be 100644
--- a/utils/meson.build
+++ b/utils/meson.build
@@ -67,7 +67,8 @@ if cairo_dep.found()
   pango_list_deps = [
     pango_deps,
     libpango_dep,
-    libpangocairo_dep
+    libpangocairo_dep,
+    libpangoft2_dep
   ]
 
   pango_list = executable('pango-list', pango_list_sources,
diff --git a/utils/pango-list.c b/utils/pango-list.c
index 82a5647c..ba657fd3 100644
--- a/utils/pango-list.c
+++ b/utils/pango-list.c
@@ -22,6 +22,8 @@
 
 #include "config.h"
 #include <pango/pangocairo.h>
+#include <pango/pangofc-fontmap2.h>
+#include <pango/pango-hbface-private.h>
 #include <hb-ot.h>
 #include <glib/gstdio.h>
 #include <stdlib.h>
@@ -31,12 +33,12 @@
 static float
 denorm_coord (hb_ot_var_axis_info_t *axis, int coord)
 {
-  float r = coord / 16384.0;
-
-  if (coord < 0)
-    return axis->default_value + r * (axis->default_value - axis->min_value);
+  if (coord == 0)
+    return axis->default_value;
+  else if (coord < 0)
+    return coord * (axis->default_value - axis->min_value) / 16384.f + axis->default_value;
   else
-    return axis->default_value + r * (axis->max_value - axis->default_value);
+    return coord * (axis->max_value - axis->default_value) / 16384.f + axis->default_value;
 }
 
 int
@@ -47,11 +49,13 @@ main (int    argc,
   gboolean opt_metrics = FALSE;
   gboolean opt_variations = FALSE;
   gboolean opt_version = FALSE;
+  const char *opt_fontmap = NULL;
   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 },
     { "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Show version" },
+    { "fontmap", 0, 0, G_OPTION_ARG_STRING, &opt_fontmap, "Select fontmap, fc2 or default", "NAME" },
     { NULL, }
   };
   GOptionContext *context;
@@ -86,7 +90,10 @@ main (int    argc,
     }
 
   /* Use PangoCairo to get default fontmap so it works on every platform. */
-  fontmap = pango_cairo_font_map_get_default ();
+  if (g_strcmp0 (opt_fontmap, "fc2") == 0)
+    fontmap = PANGO_FONT_MAP (pango_fc_font_map2_new ());
+  else
+    fontmap = pango_cairo_font_map_get_default ();
   ctx = pango_font_map_create_context (fontmap);
 
   if (opt_verbose)
@@ -139,11 +146,12 @@ main (int    argc,
          g_print ("  %s%s: %*s%s\n", synth_str, face_name,
                    width - (int)strlen (face_name) - (int)strlen (synth_str), "", desc_str);
 
+          pango_font_description_set_absolute_size (desc, 10 * PANGO_SCALE);
+
           if (opt_metrics)
             {
               PangoFontMetrics *metrics;
 
-              pango_font_description_set_absolute_size (desc, 10 * PANGO_SCALE);
               metrics = pango_context_get_metrics (ctx, desc, pango_language_from_string ("en-us"));
               g_print ("    (a %d d %d h %d cw %d dw %d u %d %d s %d %d)\n",
                        pango_font_metrics_get_ascent (metrics),
@@ -165,12 +173,33 @@ main (int    argc,
               hb_font_t *hb_font;
               const int *coords;
               unsigned int length;
+              int instance_id = -1;
 
-              pango_font_description_set_absolute_size (desc, 10 * PANGO_SCALE);
+              /* set variations here, to make the fontmap prefer the variable family
+               * over a non-variable one.
+               */
+              pango_font_description_set_variations (desc, "@");
 
               font = pango_context_load_font (ctx, desc);
               hb_font = pango_font_get_hb_font (font);
+              if (PANGO_IS_HB_FONT (font))
+                {
+                  PangoHbFace *hbface = (PangoHbFace *)faces[j];
+                  instance_id = hbface->instance_id;
+                }
+              else if (PANGO_IS_FC_FONT (font))
+                {
+                  int index;
+                  FcPattern *pattern = pango_fc_font_get_pattern (PANGO_FC_FONT (font));
+                  FcPatternGetInteger (pattern, FC_INDEX, 0, (int *)&index);
+                  instance_id = (index >> 16) - 1;
+                }
+
+              if (instance_id != -1)
+                g_print ("    Instance %d\n", instance_id);
+
               coords = hb_font_get_var_coords_normalized (hb_font, &length);
+
               if (coords)
                 {
                   hb_face_t *hb_face = hb_font_get_face (hb_font);
@@ -192,13 +221,44 @@ main (int    argc,
 
                       g_print ("    %s: %g (%g - %g, %g)\n",
                                name,
-                               denorm_coord (&axes[i], coords[i]),
+                               denorm_coord (&axes[i], coords[axes[i].axis_index]),
                                axes[i].min_value,
                                axes[i].max_value,
                                axes[i].default_value);
                     }
                   g_free (axes);
                 }
+
+              g_object_unref (font);
+            }
+
+          if (opt_verbose)
+            {
+              if (PANGO_IS_HB_FACE (faces[j]))
+                {
+                  PangoHbFace *hbface = (PangoHbFace *)faces[j];
+
+                  if (hbface->file)
+                    g_print ("    %d %s\n", hbface->index, hbface->file);
+                }
+              else
+                {
+                  PangoFont *font;
+
+                  font = pango_context_load_font (ctx, desc);
+                  if (PANGO_IS_FC_FONT (font))
+                    {
+                      FcPattern *pattern;
+                      const char *file;
+                      int index;
+
+                      pattern = pango_fc_font_get_pattern (PANGO_FC_FONT (font));
+                      FcPatternGetString (pattern, FC_FILE, 0, (FcChar8 **)&file);
+                      FcPatternGetInteger (pattern, FC_INDEX, 0, &index);
+                      g_print ("    %d %s\n", index, file);
+                    }
+                  g_object_unref (font);
+                }
             }
 
          g_free (desc_str);


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