+/* in pango units */
+static int
+gtk_font_chooser_widget_get_preview_text_height (GtkFontChooserWidget *fontchooser)
+{
+ GtkWidget *treeview = fontchooser->priv->family_face_list;
+ double dpi, font_size;
+
+ dpi = gdk_screen_get_resolution (gtk_widget_get_screen (treeview));
+ gtk_style_context_get (gtk_widget_get_style_context (treeview),
+ gtk_widget_get_state_flags (treeview),
+ "font-size", &font_size,
+ NULL);
+
+ return (dpi < 0.0 ? 96.0 : dpi) / 72.0 * PANGO_SCALE_X_LARGE * font_size * PANGO_SCALE;
+}
+
+static PangoAttrList *
+gtk_font_chooser_widget_get_preview_attributes (GtkFontChooserWidget *fontchooser,
+ const PangoFontDescription *font_desc,
+ gsize first_line_len)
+{
+ PangoAttribute *attribute;
+ PangoAttrList *attrs;
+
+ attrs = pango_attr_list_new ();
+
+ attribute = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
+ attribute->end_index = first_line_len;
+ pango_attr_list_insert (attrs, attribute);
+
+ attribute = pango_attr_scale_new (PANGO_SCALE_SMALL);
+ attribute->end_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_fallback_new (FALSE);
+ 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;
+ pango_attr_list_insert (attrs, attribute);
+
+ return attrs;
+}
+
+static void
+gtk_font_chooser_widget_cell_data_func (GtkTreeViewColumn *column,
+ GtkCellRenderer *cell,
+ GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ gpointer user_data)
+{
+ GtkFontChooserWidget *fontchooser = user_data;
+ PangoFontDescription *font_desc;
+ PangoAttrList *attrs;
+ char *to_string, *text;
+ gsize first_line_len;
+
+ font_desc = tree_model_get_font_description (tree_model, iter);
+
+ to_string = pango_font_description_to_string (font_desc);
+
+ text = g_strconcat (to_string, "\n", fontchooser->priv->preview_text, NULL);
+ first_line_len = strlen (to_string) + 1;
+
+ attrs = gtk_font_chooser_widget_get_preview_attributes (fontchooser,
+ font_desc,
+ first_line_len);
+
+ g_object_set (cell,
+ "attributes", attrs,
+ "text", text,
+ NULL);
+
+ pango_font_description_free (font_desc);
+ pango_attr_list_unref (attrs);
+ g_free (to_string);
+ g_free (text);
+}
+
+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);
+}
+