[gtk+] fontchooser: Set a fixed size on the preview cell
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] fontchooser: Set a fixed size on the preview cell
- Date: Thu, 22 Sep 2011 21:47:41 +0000 (UTC)
commit 1892c64accc3a5b8ef91b139597b076ea52515fc
Author: Benjamin Otte <otte redhat com>
Date: Thu Sep 22 18:00:37 2011 +0200
fontchooser: Set a fixed size on the preview cell
This way, all rows have the same height. It has 3 advantages:
1) No actual computation is necessary to compute the size of the cell.
This speeds up the list tremendously (filling out the list goes from
25s to 3s).
2) Buggy fonts don't mess up the list anymore with their weird sizes.
Instead, they are clipped / empty space is added.
3) Buggy fonts look more buggy. So their use is hopefully discouraged.
gtk/gtkfontchooserwidget.c | 55 +++++++++++++++++++++++++++++++++++++------
1 files changed, 47 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index ef0f525..d7c3acc 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -78,6 +78,7 @@ struct _GtkFontChooserWidgetPrivate
{
GtkWidget *search_entry;
GtkWidget *family_face_list;
+ GtkCellRenderer *family_face_cell;
GtkWidget *list_scrolled_window;
GtkWidget *empty_list;
GtkWidget *list_notebook;
@@ -826,9 +827,12 @@ gtk_font_chooser_widget_get_preview_attributes (GtkFontChooserWidget *font
attribute->end_index = first_line_len;
pango_attr_list_insert (attrs, attribute);
- attribute = pango_attr_font_desc_new (font_desc);
- attribute->start_index = first_line_len;
- pango_attr_list_insert (attrs, attribute);
+ if (font_desc)
+ {
+ attribute = pango_attr_font_desc_new (font_desc);
+ attribute->start_index = first_line_len;
+ pango_attr_list_insert (attrs, attribute);
+ }
attribute = pango_attr_size_new_absolute (gtk_font_chooser_widget_get_preview_text_height (fontchooser));
attribute->start_index = first_line_len;
@@ -873,13 +877,46 @@ gtk_font_chooser_widget_cell_data_func (GtkTreeViewColumn *column,
}
static void
+gtk_font_chooser_widget_set_cell_size (GtkFontChooserWidget *fontchooser)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+ PangoAttrList *attrs;
+ GtkRequisition size;
+
+ gtk_cell_renderer_set_fixed_size (priv->family_face_cell, -1, -1);
+
+ attrs = gtk_font_chooser_widget_get_preview_attributes (fontchooser,
+ NULL,
+ 1);
+
+ g_object_set (priv->family_face_cell,
+ "attributes", attrs,
+ "text", "x\nx",
+ NULL);
+
+ pango_attr_list_unref (attrs);
+
+ gtk_cell_renderer_get_preferred_size (priv->family_face_cell,
+ priv->family_face_list,
+ &size,
+ NULL);
+ gtk_cell_renderer_set_fixed_size (priv->family_face_cell, size.width, size.height);
+}
+
+static void
gtk_font_chooser_widget_bootstrap_fontlist (GtkFontChooserWidget *fontchooser)
{
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
GtkTreeView *treeview = GTK_TREE_VIEW (priv->family_face_list);
- GtkCellRenderer *cell;
GtkTreeViewColumn *col;
+ g_signal_connect_data (priv->family_face_list,
+ "style-updated",
+ G_CALLBACK (gtk_font_chooser_widget_set_cell_size),
+ fontchooser,
+ NULL,
+ G_CONNECT_AFTER | G_CONNECT_SWAPPED);
+
priv->model = GTK_TREE_MODEL (gtk_list_store_new (4,
PANGO_TYPE_FONT_FAMILY,
PANGO_TYPE_FONT_FACE,
@@ -898,14 +935,14 @@ gtk_font_chooser_widget_bootstrap_fontlist (GtkFontChooserWidget *fontchooser)
gtk_tree_view_set_rules_hint (treeview, TRUE);
gtk_tree_view_set_headers_visible (treeview, FALSE);
- cell = gtk_cell_renderer_text_new ();
- g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+ priv->family_face_cell = gtk_cell_renderer_text_new ();
+ g_object_set (priv->family_face_cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
col = gtk_tree_view_column_new ();
gtk_tree_view_column_set_title (col, _("Font Family"));
- gtk_tree_view_column_pack_start (col, cell, TRUE);
+ gtk_tree_view_column_pack_start (col, priv->family_face_cell, TRUE);
gtk_tree_view_column_set_cell_data_func (col,
- cell,
+ priv->family_face_cell,
gtk_font_chooser_widget_cell_data_func,
fontchooser,
NULL);
@@ -913,6 +950,8 @@ gtk_font_chooser_widget_bootstrap_fontlist (GtkFontChooserWidget *fontchooser)
gtk_tree_view_append_column (treeview, col);
gtk_font_chooser_widget_load_fonts (fontchooser);
+
+ gtk_font_chooser_widget_set_cell_size (fontchooser);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]