[gtk/wip/fanc999/fontchooser.win32.gtk3: 2/3] gtk/gtkfontfeatures.c: Add support for PangoWin32Font->FT_Face



commit 741dfaf231c801f364c2ed29720180dbf091e845
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Wed Dec 26 18:21:02 2018 +0800

    gtk/gtkfontfeatures.c: Add support for PangoWin32Font->FT_Face
    
    This is so that we can turn the LOGFONT that is retrieved from the
    PangoFont so that we can load it with FreeType and feed it to HarfBuzz.
    
    There is ongoing work in Pango to do shaping on all supported platforms
    using HarfBuzz, but since this is GTK+-3.24.x, we will still need to
    support the code path without it as well.  PangoWin32 also needs to be
    updated to apply the updates here to the PangoFont in question,
    otherwise we will only be able to view the OpenType tags that are
    tweakable.

 gtk/gtkfontchooserwidget.c   |  9 +++++---
 gtk/gtkfontfeatures.c        | 53 +++++++++++++++++++++++++++++++++++++++-----
 gtk/gtkfontfeaturesprivate.h |  7 ++++--
 3 files changed, 58 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index 20d6380af9..6040fd9ce8 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -713,7 +713,7 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
 
   gtk_widget_init_template (GTK_WIDGET (fontchooser));
 
-#if defined(HAVE_HARFBUZZ) && defined (HAVE_PANGOFT)
+#ifdef HAVE_HARFBUZZ
   priv->axes = g_hash_table_new_full (axis_hash, axis_equal, NULL, axis_free);
 #endif
 
@@ -754,7 +754,7 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
 
   /* Load data and set initial style-dependent parameters */
   gtk_font_chooser_widget_load_fonts (fontchooser, TRUE);
-#if defined(HAVE_HARFBUZZ) && defined (HAVE_PANGOFT)
+#ifdef HAVE_HARFBUZZ
   gtk_font_chooser_widget_populate_features (fontchooser);
 #endif
   gtk_font_chooser_widget_set_cell_size (fontchooser);
@@ -1063,6 +1063,9 @@ gtk_font_chooser_widget_finalize (GObject *object)
 
   g_free (priv->font_features);
 
+  if (priv->ft_ext_items)
+    gtk_font_chooser_widget_release_extra_ft_items (fontchooser);
+
   G_OBJECT_CLASS (gtk_font_chooser_widget_parent_class)->finalize (object);
 }
 
@@ -1379,7 +1382,7 @@ gtk_font_chooser_widget_merge_font_desc (GtkFontChooserWidget       *fontchooser
 
       gtk_font_chooser_widget_update_marks (fontchooser);
 
-#if defined(HAVE_HARFBUZZ) && defined (HAVE_PANGOFT)
+#ifdef HAVE_HARFBUZZ
       if (gtk_font_chooser_widget_update_font_features (fontchooser))
         has_tweak = TRUE;
       if (gtk_font_chooser_widget_update_font_variations (fontchooser))
diff --git a/gtk/gtkfontfeatures.c b/gtk/gtkfontfeatures.c
index 4133405527..dc3031839d 100644
--- a/gtk/gtkfontfeatures.c
+++ b/gtk/gtkfontfeatures.c
@@ -33,8 +33,8 @@
 #include "gtkradiobutton.h"
 #include "gtkgesturemultipress.h"
 
-#if defined (HAVE_HARFBUZZ) && defined (HAVE_PANGOFT)
-#include <pango/pangofc-font.h>
+#ifdef HAVE_HARFBUZZ
+
 #include <hb.h>
 #include <hb-ot.h>
 #include <hb-ft.h>
@@ -46,6 +46,9 @@
 #include "script-names.h"
 #include "open-type-layout.h"
 
+/* Do the PangoFont->FT_Face conversion... */
+#include "gtk-pangofont-ftface-util.c"
+
 static void update_font_features (GtkFontChooserWidget *fontchooser);
 
 guint
@@ -85,6 +88,42 @@ axis_remove (gpointer key,
   gtk_widget_destroy (a->spin);
 }
 
+static FT_Face
+get_ft_face_from_pango_font (GtkFontChooserWidget *fontchooser,
+                             PangoFont            *font)
+{
+  GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+  PangoFontMap *font_map = NULL;
+
+  if (priv->ft_ext_items == NULL)
+    priv->ft_ext_items = FT_EXT_ITEM_INIT (font);
+
+  if (priv->font_map != NULL)
+    font_map = priv->font_map;
+  else
+    font_map = pango_cairo_font_map_get_default ();
+
+  return FT_FACE_FROM_PANGO_FONT (priv->ft_ext_items, font, font_map);
+}
+
+static void
+release_ft_face_from_pango_font (GtkFontChooserWidget *fontchooser,
+                                 PangoFont            *font)
+{
+  GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+
+  PANGO_FONT_RELEASE_FT_FACE (priv->ft_ext_items, font);
+}
+
+void
+gtk_font_chooser_widget_release_extra_ft_items (GtkFontChooserWidget *fontchooser)
+{
+  GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+
+  if (RELEASE_EXTRA_FT_ITEMS (priv->ft_ext_items))
+    priv->ft_ext_items = NULL;
+}
+
 /* OpenType variations */
 
 #define FixedToFloat(f) (((float)(f))/65536.0)
@@ -241,6 +280,7 @@ gtk_font_chooser_widget_update_font_variations (GtkFontChooserWidget *fontchoose
   FT_MM_Var *ft_mm_var;
   FT_Error ret;
   gboolean has_axis = FALSE;
+  PangoFontMap *font_map = NULL;
 
   if (priv->updating_variations)
     return FALSE;
@@ -254,7 +294,7 @@ gtk_font_chooser_widget_update_font_variations (GtkFontChooserWidget *fontchoose
   pango_font = pango_context_load_font (gtk_widget_get_pango_context (GTK_WIDGET (fontchooser)),
                                         priv->font_desc);
 
-  ft_face = pango_fc_font_lock_face (PANGO_FC_FONT (pango_font));
+  ft_face = get_ft_face_from_pango_font (fontchooser, pango_font);
 
   ret = FT_Get_MM_Var (ft_face, &ft_mm_var);
   if (ret == 0)
@@ -286,7 +326,7 @@ gtk_font_chooser_widget_update_font_variations (GtkFontChooserWidget *fontchoose
       free (ft_mm_var);
     }
 
-  pango_fc_font_unlock_face (PANGO_FC_FONT (pango_font));
+  release_ft_face_from_pango_font (fontchooser, pango_font);
 
   g_object_unref (pango_font);
 
@@ -775,6 +815,7 @@ gtk_font_chooser_widget_update_font_features (GtkFontChooserWidget *fontchooser)
   int i, j;
   GList *l;
   gboolean has_feature = FALSE;
+  PangoFontMap *font_map = NULL;
 
   for (l = priv->feature_items; l; l = l->next)
     {
@@ -789,7 +830,7 @@ gtk_font_chooser_widget_update_font_features (GtkFontChooserWidget *fontchooser)
   pango_font = pango_context_load_font (gtk_widget_get_pango_context (GTK_WIDGET (fontchooser)),
                                         priv->font_desc);
 
-  ft_face = pango_fc_font_lock_face (PANGO_FC_FONT (pango_font));
+  ft_face = get_ft_face_from_pango_font (fontchooser, pango_font);
 
   hb_font = hb_ft_font_create (ft_face, NULL);
 
@@ -850,7 +891,7 @@ gtk_font_chooser_widget_update_font_features (GtkFontChooserWidget *fontchooser)
       hb_face_destroy (hb_face);
     }
 
-  pango_fc_font_unlock_face (PANGO_FC_FONT (pango_font));
+  release_ft_face_from_pango_font (fontchooser, pango_font);
 
   g_object_unref (pango_font);
 
diff --git a/gtk/gtkfontfeaturesprivate.h b/gtk/gtkfontfeaturesprivate.h
index d24c0ba31b..1801423066 100644
--- a/gtk/gtkfontfeaturesprivate.h
+++ b/gtk/gtkfontfeaturesprivate.h
@@ -70,6 +70,8 @@ struct _GtkFontChooserWidgetPrivate
   GList *feature_items;
 
   GAction *tweak_action;
+
+  gpointer ft_ext_items;
 };
 
 typedef struct {
@@ -87,6 +89,7 @@ void        gtk_font_chooser_widget_take_font_desc            (GtkFontChooserWid
 gboolean    gtk_font_chooser_widget_update_font_features      (GtkFontChooserWidget *fontchooser);
 gboolean    gtk_font_chooser_widget_update_font_variations    (GtkFontChooserWidget *fontchooser);
 void        gtk_font_chooser_widget_update_preview_attributes (GtkFontChooserWidget *fontchooser);
+void        gtk_font_chooser_widget_release_extra_ft_items    (GtkFontChooserWidget *fontchooser);
 
-gboolean    output_cb (GtkSpinButton *spin,
-                       gpointer       data);
+gboolean    output_cb              (GtkSpinButton *spin,
+                                    gpointer       data);


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