[gtk/wip/fanc999/fontchooser.win32: 1393/1393] demos/font_features.c: Support PangoWin32 Font as well



commit 0663bf94e5ec548ed655a18685caa17678d121e5
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Tue Apr 16 15:53:47 2019 +0800

    demos/font_features.c: Support PangoWin32 Font as well
    
    Also support PangoWin32 fonts for the font features demo, which will
    enable running on Windows even if PangoFT support is not enabled or is
    unused.
    
    Check for PangoWin32 as well in configure to see whether the font
    features demo will be built.  If either PangoFT2 or PangoWin32 is found
    along with HarfBuzz, build the font features demo.

 demos/gtk-demo/font_features.c | 82 ++++++++++++++++++++++++++++++++----------
 demos/gtk-demo/meson.build     | 14 ++++++--
 2 files changed, 74 insertions(+), 22 deletions(-)
---
diff --git a/demos/gtk-demo/font_features.c b/demos/gtk-demo/font_features.c
index 8299b6461c..c165623c56 100644
--- a/demos/gtk-demo/font_features.c
+++ b/demos/gtk-demo/font_features.c
@@ -11,8 +11,9 @@
  * axes are also offered for customization.
  */
 
+#include "config.h"
+
 #include <gtk/gtk.h>
-#include <pango/pangofc-font.h>
 #include <hb.h>
 #include <hb-ot.h>
 #include <hb-ft.h>
@@ -23,8 +24,15 @@
 
 #include "open-type-layout.h"
 #include "fontplane.h"
-#include "script-names.h"
-#include "language-names.h"
+
+#ifdef G_OS_WIN32
+extern GHashTable *
+gtk_font_chooser_widget_get_win32_locales (void);
+#else
+# include "script-names.h"
+# include "language-names.h"
+#endif
+#include "gtkpangofontutilsprivate.h"
 
 
 #define MAKE_TAG(a,b,c,d) (unsigned int)(((a) << 24) | ((b) << 16) | ((c) <<  8) | (d))
@@ -422,7 +430,17 @@ update_display (void)
   pango_attr_list_unref (attrs);
 }
 
-static PangoFont *
+typedef struct
+{
+  PangoContext *context;
+  PangoFontMap *map;
+  PangoFont    *font;
+  gpointer     *ft_extra_items;
+} demo_pango_items;
+
+static demo_pango_items items;
+
+static void
 get_pango_font (void)
 {
   PangoFontDescription *desc;
@@ -430,6 +448,9 @@ get_pango_font (void)
 
   desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (font));
   context = gtk_widget_get_pango_context (font);
+  items.map = pango_context_get_font_map (context);
+  items.font = pango_font_map_load_font (items.map, context, desc);
+  items.ft_extra_items = _gtk_pango_font_init_extra_ft_items (items.font);
 
   return pango_context_load_font (context, desc);
 }
@@ -485,7 +506,6 @@ update_script_combo (void)
   hb_font_t *hb_font;
   gint i, j, k;
   FT_Face ft_face;
-  PangoFont *pango_font;
   GHashTable *tags;
   GHashTableIter iter;
   TagPair *pair;
@@ -504,8 +524,10 @@ update_script_combo (void)
 
   store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
 
-  pango_font = get_pango_font ();
-  ft_face = pango_fc_font_lock_face (PANGO_FC_FONT (pango_font)),
+  get_pango_font ();
+  ft_face = _gtk_pango_font_get_ft_face (items.font,
+                                         items.map,
+                                         items.ft_extra_items);
   hb_font = hb_ft_font_create (ft_face, NULL);
 
   tags = g_hash_table_new_full (tag_pair_hash, tag_pair_equal, g_free, NULL);
@@ -549,8 +571,12 @@ update_script_combo (void)
       hb_face_destroy (hb_face);
     }
 
-  pango_fc_font_unlock_face (PANGO_FC_FONT (pango_font));
-  g_object_unref (pango_font);
+  _gtk_pango_font_release_ft_face (items.font, items.ft_extra_items);
+
+  if (_gtk_pango_font_release_ft_items (items.ft_extra_items))
+    g_free (items.ft_extra_items);
+
+  g_object_unref (items.font);
 
   g_hash_table_iter_init (&iter, tags);
   while (g_hash_table_iter_next (&iter, (gpointer *)&pair, NULL))
@@ -563,7 +589,16 @@ update_script_combo (void)
         langname = NC_("Language", "Default");
       else
         {
+#ifdef G_OS_WIN32
+          GHashTable *ht_win32_languages = NULL;
+          hb_language_t lang;
+
+          ht_win32_languages = _gtk_font_chooser_widget_get_win32_locales ();
+          lang = hb_ot_tag_to_language (pair->lang_tag);
+          langname = g_hash_table_lookup (ht_win32_languages, lang);
+#else
           langname = get_language_name_for_tag (pair->lang_tag);
+#endif
           if (!langname)
             {
               hb_tag_to_string (pair->lang_tag, langbuf);
@@ -606,7 +641,6 @@ update_features (void)
   GtkTreeModel *model;
   GtkTreeIter iter;
   guint script_index, lang_index;
-  PangoFont *pango_font;
   FT_Face ft_face;
   hb_font_t *hb_font;
   GList *l;
@@ -631,8 +665,8 @@ update_features (void)
                       2, &lang_index,
                       -1);
 
-  pango_font = get_pango_font ();
-  ft_face = pango_fc_font_lock_face (PANGO_FC_FONT (pango_font)),
+  get_pango_font ();
+  ft_face = _gtk_pango_font_get_ft_face (items.font, items.map, items.ft_extra_items);
   hb_font = hb_ft_font_create (ft_face, NULL);
 
   if (hb_font)
@@ -719,8 +753,12 @@ update_features (void)
       hb_face_destroy (hb_face);
     }
 
-  pango_fc_font_unlock_face (PANGO_FC_FONT (pango_font));
-  g_object_unref (pango_font);
+  _gtk_pango_font_release_ft_face (items.font, items.ft_extra_items);
+
+  if (_gtk_pango_font_release_ft_items (items.ft_extra_items))
+    g_free (items.ft_extra_items);
+
+  g_object_unref (items.font);
 }
 
 #define FixedToFloat(f) (((float)(f))/65536.0)
@@ -1519,7 +1557,6 @@ static void
 update_font_variations (void)
 {
   GtkWidget *child, *next;
-  PangoFont *pango_font;
   FT_Face ft_face;
   FT_MM_Var *ft_mm_var;
   FT_Error ret;
@@ -1537,8 +1574,10 @@ update_font_variations (void)
   g_hash_table_remove_all (axes);
   g_hash_table_remove_all (instances);
 
-  pango_font = get_pango_font ();
-  ft_face = pango_fc_font_lock_face (PANGO_FC_FONT (pango_font)),
+  get_pango_font ();
+  ft_face = _gtk_pango_font_get_ft_face (items.font,
+                                         items.map,
+                                         items.ft_extra_items);
 
   ret = FT_Get_MM_Var (ft_face, &ft_mm_var);
   if (ret == 0)
@@ -1592,8 +1631,13 @@ update_font_variations (void)
       free (ft_mm_var);
     }
 
-  pango_fc_font_unlock_face (PANGO_FC_FONT (pango_font));
-  g_object_unref (pango_font);
+  _gtk_pango_font_release_ft_face (items.font, items.ft_extra_items);
+
+  if (_gtk_pango_font_release_ft_items (items.ft_extra_items))
+    g_free (items.ft_extra_items);
+
+  g_object_unref (items.font);
+
 }
 
 static void
diff --git a/demos/gtk-demo/meson.build b/demos/gtk-demo/meson.build
index aba44c976c..d5f2082c6d 100644
--- a/demos/gtk-demo/meson.build
+++ b/demos/gtk-demo/meson.build
@@ -86,10 +86,18 @@ extra_demo_sources = files(['main.c',
                             'bluroverlay.c',
                             'demotaggedentry.c'])
 
-if harfbuzz_dep.found() and pangoft_dep.found()
+if build_with_harfbuzz
   demos += files('font_features.c')
-  extra_demo_sources += files(['script-names.c', 'language-names.c'])
-  gtkdemo_deps += [ harfbuzz_dep, ]
+  extra_demo_sources += files('../../gtk/gtkpangofontutils.c')
+  gtkdemo_deps += [ harfbuzz_dep ]
+  if pangoft_dep.found()
+    gtkdemo_deps += [ pangoft_dep ]
+  endif
+  if os_win32
+    gtkdemo_deps += [ ft2_dep ]
+  else
+    extra_demo_sources += files(['script-names.c', 'language-names.c'])
+  endif
 endif
 
 if os_unix


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