]> www.fi.muni.cz Git - evince.git/commitdiff
Render "loading..." text into a cairo surface instead of directly into the
authorCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 21 Jan 2007 16:25:45 +0000 (16:25 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Sun, 21 Jan 2007 16:25:45 +0000 (16:25 +0000)
2007-01-21  Carlos Garcia Campos  <carlosgc@gnome.org>
* 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

ChangeLog
shell/ev-view-private.h
shell/ev-view.c

index e272e8caf9885958d60758a5dba313dd77c68374..da5758b280080d4bdf3c32ea8be98023544f758f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-01-21  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * 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.
+
 2007-01-19  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-stock-icons.c: (ev_stock_icons_init):
index eb7ec7269e7eeb6680fc0db1682ae39e54231425..cdc6a96cbc80b3165ebe9f904fff8144529978fc 100644 (file)
@@ -117,6 +117,7 @@ struct _EvView {
        gboolean fullscreen;
        gboolean presentation;
        EvSizingMode sizing_mode;
+       cairo_surface_t *loading_text;
 
        /* Presentation */
        EvPresentationState presentation_state;
index 13f227e775dac343ca8550e2dbcc6f5039fb55b7..cd6d27ec202a98524839300783124de7b4e13f73 100644 (file)
@@ -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;