summaryrefslogtreecommitdiff
path: root/utils/pango-list.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-07-25 08:02:50 -0400
committerMatthias Clasen <mclasen@redhat.com>2019-07-25 14:18:05 -0400
commit6ed798e20ea0fd96e1b545ed3c98a7f700249076 (patch)
treeb08324c3df3d79295aaf19f143696ab44da1c6da /utils/pango-list.c
parentae818835a87193cce38b821bf53dd89f98d4ee52 (diff)
downloadpango-6ed798e20ea0fd96e1b545ed3c98a7f700249076.tar.gz
pango-list: Optionally show variations
This is not perfect; we really need harfbuzz api to get design coords of a hb_font_t.
Diffstat (limited to 'utils/pango-list.c')
-rw-r--r--utils/pango-list.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/utils/pango-list.c b/utils/pango-list.c
index c0f0d4ae..b3688233 100644
--- a/utils/pango-list.c
+++ b/utils/pango-list.c
@@ -22,18 +22,33 @@
#include "config.h"
#include <pango/pangocairo.h>
+#include <harfbuzz/hb-ot.h>
#include <glib/gstdio.h>
#include <stdlib.h>
+/* FIXME: This doesn't work if the font has an avar table */
+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);
+ else
+ return axis->default_value + r * (axis->max_value - axis->default_value);
+}
+
int
main (int argc,
char **argv)
{
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 +148,49 @@ 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: %g (%g - %g, %g)\n",
+ name,
+ denorm_coord (&axes[i], 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);
}