[gtk+/wip/matthiasc/font-variations: 11/13] font chooser: Show the font name on the tweak page



commit 71f2f2be678b69da002214e75f1582af47be0c3f
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Dec 29 23:49:03 2017 -0500

    font chooser: Show the font name on the tweak page
    
    This was the intention from the start, I just forgot.

 gtk/gtkfontchooserwidget.c     |   47 ++++++++++++++++++++++++++++++++++++++++
 gtk/ui/gtkfontchooserwidget.ui |   10 ++++++++
 2 files changed, 57 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index d91c8d1..4f117d5 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -136,6 +136,7 @@ struct _GtkFontChooserWidgetPrivate
 
   GtkWidget       *preview;
   GtkWidget       *preview2;
+  GtkWidget       *font_name_label;
   gchar           *preview_text;
   gboolean         show_preview_entry;
 
@@ -669,6 +670,7 @@ gtk_font_chooser_widget_update_preview_attributes (GtkFontChooserWidget *fontcho
     pango_attr_list_insert (attrs, pango_attr_language_new (priv->font_language));
 
   gtk_entry_set_attributes (GTK_ENTRY (priv->preview), attrs);
+
   pango_attr_list_unref (attrs);
 }
 
@@ -802,6 +804,7 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, axis_grid);
   gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, feature_box);
   gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, feature_language_combo);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, font_name_label);
 
   gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, filter_popover);
   gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, script_filter_revealer);
@@ -2029,6 +2032,49 @@ gtk_font_chooser_widget_set_font (GtkFontChooserWidget *fontchooser,
 }
 
 static void
+gtk_font_chooser_widget_update_font_name (GtkFontChooserWidget *fontchooser,
+                                          GtkTreeSelection     *selection)
+{
+  GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  PangoFontFamily *family;
+  PangoFontFace *face;
+  GtkDelayedFontDescription *desc;
+  const PangoFontDescription *font_desc;
+  PangoAttrList *attrs;
+  const char *fam_name;
+  const char *face_name;
+  char *title;
+
+  gtk_tree_selection_get_selected (selection, &model, &iter);
+  gtk_tree_model_get (model, &iter,
+                      FAMILY_COLUMN, &family,
+                      FACE_COLUMN, &face,
+                      FONT_DESC_COLUMN, &desc,
+                      -1);
+
+  fam_name = pango_font_family_get_name (family);
+  face_name = pango_font_face_get_face_name (face);
+  font_desc = gtk_delayed_font_description_get (desc);
+
+  g_object_unref (family);
+  g_object_unref (face);
+
+  if (priv->level == GTK_FONT_CHOOSER_LEVEL_FAMILY)
+    title = g_strdup (fam_name);
+  else
+    title = g_strconcat (fam_name, " ", face_name, NULL);
+
+  attrs = gtk_font_chooser_widget_get_preview_attributes (fontchooser, font_desc);
+  gtk_label_set_attributes (GTK_LABEL (priv->font_name_label), attrs);
+  pango_attr_list_unref (attrs);
+
+  gtk_label_set_label (GTK_LABEL (priv->font_name_label), title);
+  g_free (title);
+}
+
+static void
 selection_changed (GtkTreeSelection     *selection,
                    GtkFontChooserWidget *fontchooser)
 {
@@ -2039,6 +2085,7 @@ selection_changed (GtkTreeSelection     *selection,
 
   if (gtk_tree_selection_count_selected_rows (selection) > 0)
     {
+      gtk_font_chooser_widget_update_font_name (fontchooser, selection);
       g_simple_action_set_enabled (G_SIMPLE_ACTION (priv->tweak_action), TRUE);
     }
   else
diff --git a/gtk/ui/gtkfontchooserwidget.ui b/gtk/ui/gtkfontchooserwidget.ui
index 70fa80f..b35f500 100644
--- a/gtk/ui/gtkfontchooserwidget.ui
+++ b/gtk/ui/gtkfontchooserwidget.ui
@@ -226,6 +226,16 @@
             <property name="orientation">vertical</property>
             <property name="spacing">6</property>
             <child>
+              <object class="GtkLabel" id="font_name_label">
+                <property name="margin-top">6</property>
+                <property name="margin-bottom">6</property>
+                <property name="margin-start">12</property>
+                <property name="margin-end">12</property>
+                <property name="ellipsize">end</property>
+                <property name="xalign">0</property>
+              </object>
+            </child>
+            <child>
               <object class="GtkEntry" id="preview2">
                 <property name="can-focus">1</property>
                 <property name="placeholder-text" translatable="yes">Preview text</property>


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