[gtk+] fontchooser: Introduce gtk_font_chooser_find_font()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] fontchooser: Introduce gtk_font_chooser_find_font()
- Date: Thu, 22 Sep 2011 21:45:50 +0000 (UTC)
commit 3af04c1dceb04f19c6988ff3b96e124887d23a80
Author: Benjamin Otte <otte redhat com>
Date: Tue Sep 20 02:54:42 2011 +0200
fontchooser: Introduce gtk_font_chooser_find_font()
... which looks up the font in the list of fonts. This then can be used
to select an actual font upon changes.
Also fixes cases where the get_family() and get_face() functions would
return outdated data when set_font() had been called.
gtk/gtkfontchooserwidget.c | 130 ++++++++++++++++++++------------------------
1 files changed, 60 insertions(+), 70 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index 012c85f..21e5f9a 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -874,6 +874,40 @@ gtk_font_chooser_widget_finalize (GObject *object)
G_OBJECT_CLASS (gtk_font_chooser_widget_parent_class)->finalize (object);
}
+static gboolean
+gtk_font_chooser_widget_find_font (GtkFontChooserWidget *fontchooser,
+ const PangoFontDescription *font_desc,
+ /* out arguments */
+ GtkTreeIter *iter,
+ PangoFontFamily **family,
+ PangoFontFace **face)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+ PangoFontDescription *desc;
+ gboolean valid;
+
+ for (valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->model), iter);
+ valid;
+ valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->model), iter))
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->model), iter,
+ FACE_COLUMN, face,
+ FAMILY_COLUMN, family,
+ FONT_DESC_COLUMN, &desc,
+ -1);
+
+ pango_font_description_merge_static (desc, font_desc, FALSE);
+ if (pango_font_description_equal (desc, font_desc))
+ break;
+
+ g_object_unref (face);
+ g_object_unref (family);
+ pango_font_description_free (desc);
+ }
+
+ return valid;
+}
+
static void
gtk_font_chooser_widget_screen_changed (GtkWidget *widget,
GdkScreen *previous_screen)
@@ -988,89 +1022,45 @@ static void
gtk_font_chooser_widget_select_font (GtkFontChooserWidget *fontchooser)
{
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
- const PangoFontDescription *desc;
- const gchar *family_name;
- gint font_size;
- gboolean font_size_is_absolute;
GtkTreeIter iter;
- gboolean valid;
- gboolean found = FALSE;
-
- desc = priv->font_desc;
- g_assert (desc != NULL);
-
- font_size = pango_font_description_get_size (desc);
- font_size_is_absolute = pango_font_description_get_size_is_absolute (desc);
- family_name = pango_font_description_get_family (desc);
- /* We make sure the filter is clear */
- gtk_entry_set_text (GTK_ENTRY (priv->search_entry), "");
-
- if (!family_name)
- goto deselect;
+ if (priv->family)
+ g_object_unref (priv->family);
+ if (priv->face)
+ g_object_unref (priv->face);
- /* We find the matching family/face */
- for (valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->filter_model), &iter);
- valid;
- valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->filter_model), &iter))
+ if (gtk_font_chooser_widget_find_font (fontchooser,
+ priv->font_desc,
+ &iter,
+ &priv->family,
+ &priv->face))
{
- PangoFontFace *face;
- PangoFontDescription *tmp_desc;
-
- gtk_tree_model_get (GTK_TREE_MODEL (priv->filter_model), &iter,
- FACE_COLUMN, &face,
- -1);
-
- tmp_desc = pango_font_face_describe (face);
- if (font_size_is_absolute)
- pango_font_description_set_absolute_size (tmp_desc, font_size);
- else
- pango_font_description_set_size (tmp_desc, font_size);
+ GtkTreeIter filter_iter;
- if (pango_font_description_equal (desc, tmp_desc))
+ if (gtk_tree_model_filter_convert_child_iter_to_iter (GTK_TREE_MODEL_FILTER (priv->filter_model),
+ &filter_iter,
+ &iter))
{
- GtkTreePath *path;
-
- if (font_size)
- {
- if (font_size_is_absolute)
- font_size *= PANGO_SCALE;
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->size_spin),
- font_size / PANGO_SCALE);
- }
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter_model), &iter);
-
- if (path)
- {
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->family_face_list),
+ GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter_model), &filter_iter);
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->family_face_list),
+ path,
+ NULL,
+ FALSE);
+ gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->family_face_list),
path,
NULL,
- FALSE);
- gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->family_face_list),
- path,
- NULL,
- FALSE,
- 0.5,
- 0.5);
- gtk_tree_path_free (path);
- }
-
- found = TRUE;
+ FALSE,
+ 0.5,
+ 0.5);
+ gtk_tree_path_free (path);
}
-
- g_object_unref (face);
- pango_font_description_free (tmp_desc);
-
- if (found)
- break;
}
-
-deselect:
- if (!found)
+ else
{
gtk_tree_selection_unselect_all
(gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->family_face_list)));
+ priv->face = NULL;
+ priv->family = NULL;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]