Switched to poppler's cairo backend.
authorTilman Sauerbeck <tilman@code-monkey.de>
Wed, 8 Aug 2007 11:03:53 +0000 (13:03 +0200)
committerTilman Sauerbeck <tilman@code-monkey.de>
Wed, 8 Aug 2007 11:03:53 +0000 (13:03 +0200)
Also put the rendered output in a scrolled window.

src/rakt-window.c

index 13b35d8c7a39dc6900b5b9f1b2ae782235a18d06..9f25fb882fa5900d2fa87498623aef26b1a8c05f 100644 (file)
@@ -38,9 +38,9 @@ typedef struct {
        GtkAction *action_prev;
        GtkAction *action_next;
 
-       GtkWidget *image;
-       GdkPixbuf *pixbuf;
+       GtkWidget *drawing_area;
        PopplerDocument *document;
+       PopplerPage *page;
        gint page_no;
 } RaktWindowPriv;
 
@@ -133,7 +133,6 @@ static void
 render_page (RaktWindow *window)
 {
        RaktWindowPriv *priv;
-       PopplerPage *page;
        double tmpw, tmph;
        int width, height, n_pages;
 
@@ -143,20 +142,15 @@ render_page (RaktWindow *window)
        gtk_action_set_sensitive (priv->action_prev, priv->page_no > 0);
        gtk_action_set_sensitive (priv->action_next, priv->page_no < n_pages - 1);
 
-       page = poppler_document_get_page (priv->document, priv->page_no);
-
-       poppler_page_get_size (page, &tmpw, &tmph);
+       priv->page = poppler_document_get_page (priv->document, priv->page_no);
 
-       width = (int) tmpw;
-       height = (int) tmph;
+       poppler_page_get_size (priv->page, &tmpw, &tmph);
 
-       priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
-                                      width, height);
+       width = (int) (tmpw + 0.5);
+       height = (int) (tmph + 0.5);
 
-       poppler_page_render_to_pixbuf (page, 0, 0, width, height, 1.0, 0,
-                                      priv->pixbuf);
-       gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), priv->pixbuf);
-       gtk_widget_show (priv->image);
+       gtk_widget_set_size_request (priv->drawing_area, width, height);
+       gtk_widget_queue_draw_area (priv->drawing_area, 0, 0, width, height);
 }
 
 static void
@@ -216,6 +210,27 @@ window_create_menu (RaktWindow *window)
        gtk_action_set_sensitive (priv->action_next, false);
 }
 
+static gboolean
+on_expose_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
+{
+       RaktWindowPriv *priv;
+       cairo_t *cr;
+
+       priv = GET_PRIV (user_data);
+
+       cr = gdk_cairo_create (priv->drawing_area->window);
+
+       cairo_set_source_rgb (cr, 255, 255, 255);
+       cairo_paint (cr);
+
+       if (priv->page)
+               poppler_page_render (priv->page, cr);
+
+       cairo_destroy (cr);
+
+       return FALSE;
+}
+
 static gboolean
 on_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
 {
@@ -228,6 +243,7 @@ static void
 rakt_window_init (RaktWindow *window)
 {
        RaktWindowPriv *priv;
+       GtkWidget *scrolled;
 
        priv = GET_PRIV (window);
 
@@ -240,9 +256,23 @@ rakt_window_init (RaktWindow *window)
 
        window_create_menu (window);
 
-       priv->image = gtk_image_new ();
+       priv->drawing_area = gtk_drawing_area_new ();
+       gtk_widget_show (priv->drawing_area);
+
+       g_signal_connect (priv->drawing_area, "expose-event",
+                         G_CALLBACK (on_expose_event), window);
+
+       scrolled = gtk_scrolled_window_new (NULL, NULL);
+
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+                                       GTK_POLICY_AUTOMATIC,
+                                       GTK_POLICY_AUTOMATIC);
+
+       gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
+                                              priv->drawing_area);
+       gtk_widget_show (scrolled);
 
-       gtk_box_pack_start (GTK_BOX (priv->content_vbox), priv->image,
+       gtk_box_pack_start (GTK_BOX (priv->content_vbox), scrolled,
                            TRUE, TRUE, 0);
 
        g_signal_connect (GTK_WINDOW (window), "delete-event",