diff --git a/gtk/gtkfontsel.c b/gtk/gtkfontsel.c index 60acecf7d..99b39797e 100644 --- a/gtk/gtkfontsel.c +++ b/gtk/gtkfontsel.c @@ -184,6 +184,7 @@ typedef struct PangoFontMap *font_map; /* the fonts listed are from this map... */ guint font_map_serial;/* ...in this state */ guint preview_idle; + gboolean styles_pending; /* preview_idle also lists the styles */ gint64 preview_done; /* when the last preview was made... */ gint64 preview_time; /* ...and how long that took */ } GtkFontSelectionPrivate; @@ -859,8 +860,10 @@ gtk_font_selection_select_font (GtkTreeSelection *selection, gtk_entry_set_text (GTK_ENTRY (fontsel->font_entry), family_name); #endif - gtk_font_selection_show_available_styles (fontsel); - gtk_font_selection_select_best_style (fontsel, TRUE); + /* Listing the styles takes long with many fonts; it is done with + * the preview (see gtk_font_selection_load_font()). */ + GET_PRIV (fontsel)->styles_pending = TRUE; + gtk_font_selection_load_font (fontsel); } g_object_unref (family); @@ -1002,6 +1005,7 @@ gtk_font_selection_show_available_styles (GtkFontSelection *fontsel) PangoFontFace *match_face = NULL; model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (fontsel->face_list))); + GET_PRIV (fontsel)->styles_pending = FALSE; if (fontsel->face) old_desc = pango_font_face_describe (fontsel->face); @@ -1250,6 +1254,16 @@ gtk_font_selection_preview_timeout (gpointer data) gint64 start = g_get_monotonic_time (); priv->preview_idle = 0; + if (priv->styles_pending) + { + gtk_font_selection_show_available_styles (fontsel); + gtk_font_selection_select_best_style (fontsel, TRUE); + if (priv->preview_idle) + { + g_source_remove (priv->preview_idle); + priv->preview_idle = 0; + } + } gtk_font_selection_update_preview (fontsel); priv->preview_done = g_get_monotonic_time (); @@ -1258,6 +1272,19 @@ gtk_font_selection_preview_timeout (gpointer data) return FALSE; } +/* Brings the styles and the preview up to date now. */ +static void +gtk_font_selection_flush (GtkFontSelection *fontsel) +{ + GtkFontSelectionPrivate *priv = GET_PRIV (fontsel); + + if (priv->preview_idle) + { + g_source_remove (priv->preview_idle); + gtk_font_selection_preview_timeout (fontsel); + } +} + static void gtk_font_selection_load_font (GtkFontSelection *fontsel) { @@ -1287,6 +1314,8 @@ gtk_font_selection_get_font_description (GtkFontSelection *fontsel) { PangoFontDescription *font_desc; + gtk_font_selection_flush (fontsel); + if (fontsel->face) { font_desc = pango_font_face_describe (fontsel->face); @@ -1486,6 +1515,8 @@ gtk_font_selection_get_face (GtkFontSelection *fontsel) { g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); + gtk_font_selection_flush (fontsel); + return fontsel->face; }