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



commit 99a1e38ad04631d184ab82776b796e4f0682d693
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Jan 7 16:29:24 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.

 configure.ac                   | 49 +++++++++++++++++++++++++++++------------
 demos/gtk-demo/Makefile.am     | 18 +++++++++++++--
 demos/gtk-demo/font_features.c | 50 +++++++++++++++++++++++++++++-------------
 3 files changed, 86 insertions(+), 31 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 15e78306ff..64e7e668c0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1427,20 +1427,41 @@ if test x"$os_win32" = xyes; then
   GTK_EXTRA_CFLAGS="$msnative_struct"
 fi
 
-##################################################
-# Check for harfbuzz and pangoft2
-##################################################
-
-PKG_CHECK_MODULES(GTK_FONT_CHOOSER_WIDGET,
-                  harfbuzz >= 0.9 pangoft2,
-                  build_font_demo=yes,
-                  build_font_demo=no)
-AM_CONDITIONAL(BUILD_FONT_DEMO, [ test "x$build_font_demo" = xyes ])
-if test "x$build_font_demo" = xyes; then
-  AC_DEFINE([HAVE_HARFBUZZ], 1, [defines whether we have HarfBuzz])
-  AC_DEFINE([HAVE_PANGOFT], 1, [defines whether we have pangoft2])
-  GTK_DEP_CFLAGS="$GTK_DEP_CFLAGS $GTK_FONT_CHOOSER_WIDGET_CFLAGS"
-  GTK_DEP_LIBS="$GTK_DEP_LIBS $GTK_FONT_CHOOSER_WIDGET_LIBS"
+###################################################
+# Check for harfbuzz and pangoft2 and/or pangowin32
+###################################################
+
+
+PKG_CHECK_MODULES(PANGOFT,
+                  pangoft2,
+                  have_pangoft2=yes,
+                  have_pangoft2=no)
+
+PKG_CHECK_MODULES(PANGOWIN32,
+                  pangowin32 freetype2,
+                  have_pangowin32=yes,
+                  have_pangowin32=no)
+
+if test "x$have_pangoft2" = "xyes" -o "x$have_pangowin32" = "xyes"; then
+  PKG_CHECK_MODULES(GTK_FONT_CHOOSER_WIDGET,
+                    harfbuzz >= 0.9,
+                    build_font_demo=yes,
+                    build_font_demo=no)
+  AM_CONDITIONAL(BUILD_FONT_DEMO, [ test "x$build_font_demo" = xyes ])
+  if test "x$build_font_demo" = xyes; then
+    AC_DEFINE([HAVE_HARFBUZZ], 1, [defines whether we have HarfBuzz])
+       if test "x$have_pangoft2" = "xyes"; then
+      AC_DEFINE([HAVE_PANGOFT], 1, [defines whether we have pangoft2])
+      GTK_FONT_CHOOSER_WIDGET_CFLAGS="$GTK_FONT_CHOOSER_WIDGET_CFLAGS $PANGOFT_CFLAGS"
+      GTK_FONT_CHOOSER_WIDGET_LIBS="$GTK_FONT_CHOOSER_WIDGET_LIBS $PANGOFT_LIBS"
+    fi
+       if test "x$have_pangwin32" = "xyes"; then
+      GTK_FONT_CHOOSER_WIDGET_CFLAGS="$GTK_FONT_CHOOSER_WIDGET_CFLAGS $PANGOWIN32_CFLAGS"
+      GTK_FONT_CHOOSER_WIDGET_LIBS="$GTK_FONT_CHOOSER_WIDGET_LIBS $PANGOWIN32_LIBS"
+    fi
+    GTK_DEP_CFLAGS="$GTK_DEP_CFLAGS $GTK_FONT_CHOOSER_WIDGET_CFLAGS"
+    GTK_DEP_LIBS="$GTK_DEP_LIBS $GTK_FONT_CHOOSER_WIDGET_LIBS"
+  fi
 fi
 
 if $PKG_CONFIG --exists x11; then
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index c8529e5bf7..edec751e10 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -75,9 +75,15 @@ demos_base =                                 \
        tree_store.c
 
 demos_opt =
+extra_nodist_demo_sources =
 
 if BUILD_FONT_DEMO
 demos_opt += font_features.c
+
+extra_nodist_demo_sources +=   \
+       gtkpangofontutils.c     \
+       gtkpangofontutilsprivate.h
+
 endif
 
 if OS_UNIX
@@ -130,7 +136,15 @@ demos.h: $(demos) geninclude.pl
 demos.h.win32: $(demos_base) geninclude.pl
         $(AM_V_GEN) (here=`pwd` ; cd $(srcdir) && $(PERL) $$here/geninclude.pl $(demos_base)) > demos.h.win32
 
-nodist_gtk3_demo_SOURCES = demos.h
+font_features.c: gtkpangofontutils.c gtkpangofontutilsprivate.h
+
+gtkpangofontutils.c: $(top_srcdir)/gtk/gtkpangofontutils.c
+       $(AM_V_GEN) cp $< $@
+
+gtkpangofontutilsprivate.h: $(top_srcdir)/gtk/gtkpangofontutilsprivate.h
+       $(AM_V_GEN) cp $< $@
+
+nodist_gtk3_demo_SOURCES = demos.h $(extra_nodist_demo_sources)
 
 gtk3_demo_SOURCES =            \
        $(demos)                \
@@ -199,6 +213,6 @@ dist-hook: \
        $(top_builddir)/build/win32/vs9/gtk3-demo.vcproj        \
        $(top_builddir)/build/win32/vs9/gtk3-demo-application.vcproj
 
-DISTCLEANFILES = demos.h demos.h.win32
+DISTCLEANFILES = demos.h demos.h.win32 $(extra_nodist_demo_sources)
 
 -include $(top_srcdir)/git.mk
diff --git a/demos/gtk-demo/font_features.c b/demos/gtk-demo/font_features.c
index 761bf8f38f..2f075b2234 100644
--- a/demos/gtk-demo/font_features.c
+++ b/demos/gtk-demo/font_features.c
@@ -9,11 +9,12 @@
  */
 
 #include <gtk/gtk.h>
-#include <pango/pangofc-font.h>
 #include <hb.h>
 #include <hb-ot.h>
 #include <hb-ft.h>
 
+#include "gtkpangofontutilsprivate.h"
+
 static GtkWidget *label;
 static GtkWidget *settings;
 static GtkWidget *font;
@@ -117,18 +118,28 @@ update_display (void)
   g_free (font_settings);
 }
 
-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;
   PangoContext *context;
-  PangoFontMap *map;
 
   desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (font));
   context = gtk_widget_get_pango_context (font);
-  map = pango_context_get_font_map (context);
+  items.map = pango_context_get_font_map (context);
 
-  return pango_font_map_load_font (map, context, desc);
+  items.font = pango_font_map_load_font (items.map, context, desc);
+  items.ft_extra_items = _gtk_pango_font_init_extra_ft_items (items.font);
 }
 
 static struct { const char *name; hb_script_t script; } script_names[] = {
@@ -208,15 +219,17 @@ update_script_combo (void)
   hb_font_t *hb_font;
   gint i, j, k, l;
   FT_Face ft_face;
-  PangoFont *pango_font;
   GHashTable *tags;
   GHashTableIter iter;
   TagPair *pair;
 
   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);
@@ -267,8 +280,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))
@@ -345,7 +362,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;
 
@@ -363,8 +379,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)
@@ -400,8 +416,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);
 }
 
 static void


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