static GdkPixbuf *
get_thumbnail (PopplerDocument *doc,
               gint             page_num,
               gint             preferred_size)
{
    PopplerPage *page;
    GdkPixbuf   *pixbuf;

    page = poppler_document_get_page (doc, page_num);

    if (! page)
        return NULL;

    /* XXX: Remove conditional when we depend on poppler 0.8.0, but also
     * add configure check to make sure POPPLER_WITH_GDK is enabled!
     */
#ifdef POPPLER_WITH_GDK
    pixbuf = poppler_page_get_thumbnail_pixbuf (page);
#else
    pixbuf = poppler_page_get_thumbnail (page);
#endif


    if (! pixbuf)
    {
        gdouble width;
        gdouble height;
        gdouble scale;

        poppler_page_get_size (page, &width, &height);

        scale = (gdouble) preferred_size / MAX (width, height);

        width  *= scale;
        height *= scale;

        pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
                                 width, height);

        poppler_page_render_to_pixbuf (page,
                                       0, 0, width, height, scale, 0, pixbuf);
    }

    g_object_unref (page);

    return pixbuf;
}
Beispiel #2
0
static void
pgd_page_set_page (PgdPageDemo *demo,
		   PopplerPage *page)
{
#ifdef POPPLER_WITH_GDK
	GdkPixbuf *thumbnail;
#else
	cairo_surface_t *thumbnail;
#endif
	gchar     *str;

	str = page ? g_strdup_printf ("%d", poppler_page_get_index (page)) : NULL;
	gtk_label_set_text (GTK_LABEL (demo->index), str);
	g_free (str);

	if (page) {
		str = poppler_page_get_label (page);
		gtk_label_set_text (GTK_LABEL (demo->label), str);
		g_free (str);
	} else {
		gtk_label_set_text (GTK_LABEL (demo->label), NULL);
	}

	if (page) {
		gdouble width, height;

		poppler_page_get_size (page, &width, &height);
		str = g_strdup_printf ("%.2f x %.2f", width, height);
		gtk_label_set_text (GTK_LABEL (demo->size), str);
		g_free (str);
	} else {
		gtk_label_set_text (GTK_LABEL (demo->size), NULL);
	}

	str = page ? g_strdup_printf ("%.2f seconds", poppler_page_get_duration (page)) : NULL;
	gtk_label_set_text (GTK_LABEL (demo->duration), str);
	g_free (str);

#ifdef POPPLER_WITH_GDK
	thumbnail = page ? poppler_page_get_thumbnail_pixbuf (page) : NULL;
#else
	thumbnail = page ? poppler_page_get_thumbnail (page) : NULL;
#endif
	if (thumbnail) {
		gint width, height;
		
		poppler_page_get_thumbnail_size (page, &width, &height);
		str = g_strdup_printf ("%d x %d", width, height);
		gtk_label_set_text (GTK_LABEL (demo->thumbnail_size), str);
		g_free (str);
		
#ifdef POPPLER_WITH_GDK
		gtk_image_set_from_pixbuf (GTK_IMAGE (demo->thumbnail), thumbnail);
		g_object_unref (thumbnail);
#else
		image_set_from_surface (GTK_IMAGE (demo->thumbnail), thumbnail);
		cairo_surface_destroy (thumbnail);
#endif
	} else {
		str = g_strdup ("<i>No thumbnail found</i>");
		gtk_label_set_markup (GTK_LABEL (demo->thumbnail_size), str);
		g_free (str);

		gtk_image_set_from_icon_name (GTK_IMAGE (demo->thumbnail),
					      "image-missing",
					      GTK_ICON_SIZE_DIALOG);
	}
}