+ DviDocument *dvi_document = DVI_DOCUMENT (document);
+ GdkPixbuf *pixbuf;
+ GdkPixbuf *border_pixbuf;
+ GdkPixbuf *rotated_pixbuf;
+ gint thumb_width, thumb_height;
+ gint proposed_width, proposed_height;
+
+ dvi_document_thumbnails_get_dimensions (document, page, width, &thumb_width, &thumb_height);
+
+ g_mutex_lock (dvi_context_mutex);
+
+ mdvi_setpage(dvi_document->context, page);
+
+ mdvi_set_shrink (dvi_document->context,
+ (int)dvi_document->base_width * dvi_document->params->hshrink / thumb_width,
+ (int)dvi_document->base_height * dvi_document->params->vshrink / thumb_height);
+
+ proposed_width = dvi_document->context->dvi_page_w * dvi_document->context->params.conv;
+ proposed_height = dvi_document->context->dvi_page_h * dvi_document->context->params.vconv;
+
+ if (border) {
+ mdvi_pixbuf_device_set_margins (&dvi_document->context->device,
+ MAX (thumb_width - proposed_width, 0) / 2,
+ MAX (thumb_height - proposed_height, 0) / 2);
+ } else {
+ mdvi_pixbuf_device_set_margins (&dvi_document->context->device,
+ MAX (thumb_width - proposed_width - 2, 0) / 2,
+ MAX (thumb_height - proposed_height - 2, 0) / 2);
+ }
+
+
+ mdvi_pixbuf_device_render (dvi_document->context);
+ pixbuf = mdvi_pixbuf_device_get_pixbuf (&dvi_document->context->device);
+
+ g_mutex_unlock (dvi_context_mutex);
+
+ if (border) {
+ border_pixbuf = ev_document_misc_get_thumbnail_frame (thumb_width, thumb_height, NULL);
+ gdk_pixbuf_copy_area (pixbuf, 0, 0,
+ thumb_width - 2, thumb_height - 2,
+ border_pixbuf, 2, 2);
+ g_object_unref (pixbuf);
+ pixbuf = border_pixbuf;
+ }
+
+
+ rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, rotation);
+ g_object_unref (pixbuf);