From 4aa27ea1d50e2812707e2fe06247eb8410310979 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Sun, 21 Jan 2007 16:25:45 +0000 Subject: Render "loading..." text into a cairo surface instead of directly into the 2007-01-21 Carlos Garcia Campos * shell/ev-view-private.h: * shell/ev-view.c: (draw_loading_text), (ev_view_destroy), (ev_view_set_zoom): Render "loading..." text into a cairo surface instead of directly into the window so that fontconfig lock is only needed once and UI is not blocked. Change text color to #9B9B9B. Fixes bug #397356. svn path=/trunk/; revision=2240 --- (limited to 'shell') diff --git a/shell/ev-view-private.h b/shell/ev-view-private.h index eb7ec72..cdc6a96 100644 --- a/shell/ev-view-private.h +++ b/shell/ev-view-private.h @@ -117,6 +117,7 @@ struct _EvView { gboolean fullscreen; gboolean presentation; EvSizingMode sizing_mode; + cairo_surface_t *loading_text; /* Presentation */ EvPresentationState presentation_state; diff --git a/shell/ev-view.c b/shell/ev-view.c index 13f227e..cd6d27e 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -2771,55 +2771,69 @@ draw_loading_text (EvView *view, GdkRectangle *page_area, GdkRectangle *expose_area) { - const char *loading_text; - PangoLayout *layout; - PangoFontDescription *font_desc; - PangoRectangle logical_rect; - double real_scale; - int target_width; - + cairo_t *cr; + gint width, height; + /* Don't annoy users with loading messages during presentations. * FIXME: Temporary "workaround" for * http://bugzilla.gnome.org/show_bug.cgi?id=320352 */ if (view->presentation) return; - loading_text = _("Loading..."); - - ev_document_fc_mutex_lock (); - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (view), loading_text); - - font_desc = pango_font_description_new (); - - - /* We set the font to be 10 points, get the size, and scale appropriately */ - pango_font_description_set_size (font_desc, 10 * PANGO_SCALE); - pango_layout_set_font_description (layout, font_desc); - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - - /* Make sure we fit the middle of the page */ - target_width = MAX (page_area->width / 2, 1); - real_scale = ((double)target_width / (double) logical_rect.width) * (PANGO_SCALE * 10); - pango_font_description_set_size (font_desc, (int)real_scale); - pango_layout_set_font_description (layout, font_desc); - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - - gtk_paint_layout (GTK_WIDGET (view)->style, - GTK_WIDGET (view)->window, - GTK_WIDGET_STATE (view), - FALSE, - page_area, - GTK_WIDGET (view), - NULL, - page_area->x + (target_width/2), - page_area->y + (page_area->height - logical_rect.height) / 2, - layout); + if (!view->loading_text) { + const gchar *loading_text; + PangoLayout *layout; + PangoFontDescription *font_desc; + PangoRectangle logical_rect; + gdouble real_scale; + gint target_width; + + loading_text = _("Loading..."); - pango_font_description_free (font_desc); - g_object_unref (layout); + ev_document_fc_mutex_lock (); + + layout = gtk_widget_create_pango_layout (GTK_WIDGET (view), loading_text); + + font_desc = pango_font_description_new (); + + /* We set the font to be 10 points, get the size, and scale appropriately */ + pango_font_description_set_size (font_desc, 10 * PANGO_SCALE); + pango_layout_set_font_description (layout, font_desc); + pango_layout_get_pixel_extents (layout, NULL, &logical_rect); + + /* Make sure we fit the middle of the page */ + target_width = MAX (page_area->width / 2, 1); + real_scale = ((double)target_width / (double) logical_rect.width) * (PANGO_SCALE * 10); + pango_font_description_set_size (font_desc, (int)real_scale); + pango_layout_set_font_description (layout, font_desc); + pango_layout_get_pixel_extents (layout, NULL, &logical_rect); + + view->loading_text = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + logical_rect.width, + logical_rect.height); + cr = cairo_create (view->loading_text); + cairo_set_source_rgb (cr, + 155 / (double)255, + 155 / (double)255, + 155 / (double)255); + pango_cairo_show_layout (cr, layout); + cairo_destroy (cr); + + pango_font_description_free (font_desc); + g_object_unref (layout); + + ev_document_fc_mutex_unlock (); + } - ev_document_fc_mutex_unlock (); + width = cairo_image_surface_get_width (view->loading_text) / 2; + height = (page_area->height - cairo_image_surface_get_height (view->loading_text)) / 2; + + cr = gdk_cairo_create (GTK_WIDGET (view)->window); + cairo_set_source_surface (cr, view->loading_text, + page_area->x + width, + page_area->y + height); + cairo_paint (cr); + cairo_destroy (cr); } static void @@ -2990,6 +3004,11 @@ ev_view_destroy (GtkObject *object) view->selection_update_id = 0; } + if (view->loading_text) { + cairo_surface_destroy (view->loading_text); + view->loading_text = NULL; + } + ev_view_presentation_transition_stop (view); ev_view_set_scroll_adjustments (view, NULL, NULL); @@ -3494,6 +3513,11 @@ ev_view_set_zoom (EvView *view, if (ABS (view->scale - scale) < EPSILON) return; + if (view->loading_text) { + cairo_surface_destroy (view->loading_text); + view->loading_text = NULL; + } + view->scale = scale; view->pending_resize = TRUE; -- cgit v0.9.1