[gtk+/wip/fontfeatures] wip: dump font info



commit 324ca87151a3f92a7bbd63350daa472b008d29c7
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jul 1 23:32:14 2015 -0700

    wip: dump font info

 demos/gtk-demo/font_features.c |   77 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 76 insertions(+), 1 deletions(-)
---
diff --git a/demos/gtk-demo/font_features.c b/demos/gtk-demo/font_features.c
index 4d953f0..519b076 100644
--- a/demos/gtk-demo/font_features.c
+++ b/demos/gtk-demo/font_features.c
@@ -6,6 +6,9 @@
  */
 
 #include <gtk/gtk.h>
+#include <pango/pangofc-fontmap.h>
+#include <harfbuzz/hb.h>
+#include <harfbuzz/hb-ot.h>
 
 static GtkWidget *label;
 static GtkWidget *settings;
@@ -20,6 +23,62 @@ static GtkWidget *entry;
 static GtkWidget *toggle[24];
 
 static void
+dump_tag (guint32 tag)
+{
+  g_print ("%c%c%c%c", tag >> 24, (tag >> 16) & 0xff, (tag >> 8) & 0xff, tag &0xff);
+}
+
+static void
+dump_info_for_language (hb_face_t *hb_face, guint32 table, guint sidx, guint32 script, guint lidx, guint32 
language)
+{
+  guint count;
+  guint32 *features;
+  gint i;
+
+  count = hb_ot_layout_language_get_feature_tags (hb_face, table, sidx, lidx, 0, NULL, NULL);
+  features = g_new (guint32, count + 1);
+  hb_ot_layout_language_get_feature_tags (hb_face, table, sidx, lidx, 0, &count, features);
+  for (i = 0; i < count; i++)
+    {
+      dump_tag (table); g_print (" ");
+      dump_tag (script); g_print (" ");
+      dump_tag (language); g_print (" ");
+      dump_tag (features[i]); g_print ("\n");
+    }
+  g_free (features);
+}
+
+static void
+dump_info_for_script (hb_face_t *hb_face, guint32 table, guint idx, guint32 script)
+{
+  guint count;
+  guint32 *languages;
+  gint i;
+
+  count = hb_ot_layout_script_get_language_tags (hb_face, table, idx, 0, NULL, NULL);
+  languages = g_new (guint32, count + 1);
+  hb_ot_layout_script_get_language_tags (hb_face, table, idx, 0, &count, languages);
+  for (i = 0; i < count; i++)
+    dump_info_for_language (hb_face, table, idx, script, i, languages[i]);
+  g_free (languages);
+}
+
+static void
+dump_info (hb_face_t *hb_face, guint32 table)
+{
+  guint count;
+  guint32 *scripts;
+  gint i;
+
+  count = hb_ot_layout_table_get_script_tags (hb_face, table, 0, NULL, NULL);
+  scripts = g_new (guint32, count + 1);
+  hb_ot_layout_table_get_script_tags (hb_face, table, 0, &count, scripts);
+  for (i = 0; i < count; i++)
+    dump_info_for_script (hb_face, table, i, scripts[i]);
+  g_free (scripts);
+}
+
+static void
 update (void)
 {
   GString *s;
@@ -28,9 +87,25 @@ update (void)
   const char *text;
   gboolean has_feature;
   int i;
+  PangoFontDescription *pfd;
+  PangoFcFont *fc_font;
+  FT_Face ft_face;
+  hb_face_t *hb_face;
 
-  text = gtk_entry_get_text (GTK_ENTRY (entry));
+  pfd = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (font));
+
+  fc_font = PANGO_FC_FONT (pango_font_map_load_font (pango_cairo_font_map_get_default (),
+                                                     gtk_widget_get_pango_context (font),
+                                                     pfd));
+  ft_face = pango_fc_font_lock_face (fc_font);
+  hb_face = hb_ft_face_create_cached (ft_face);
+
+  dump_info (hb_face, HB_OT_TAG_GPOS);
+  dump_info (hb_face, HB_OT_TAG_GSUB);
 
+  pango_font_description_free (pfd);
+
+  text = gtk_entry_get_text (GTK_ENTRY (entry));
   font_desc = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (font));
 
   s = g_string_new ("");


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