]> www.fi.muni.cz Git - evince.git/blobdiff - backend/dvi/cairo-device.c
Added. Returns whether the animation has everything necessary to run. Do
[evince.git] / backend / dvi / cairo-device.c
index 19006d2e36818660d412fecd657d2218ce6d3532..b8ec39e6877c904b8a9ff0f69635a52c8ce6c362 100644 (file)
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#include <config.h>
+
 #include <gdk/gdkcolor.h>
+#ifdef HAVE_SPECTRE
+#include <libspectre/spectre.h>
+#endif
+
 #include "cairo-device.h"
 
 typedef struct {
@@ -116,6 +122,73 @@ dvi_cairo_draw_rule (DviContext *dvi,
        cairo_restore (cairo_device->cr);
 }
 
+#ifdef HAVE_SPECTRE
+static void
+dvi_cairo_draw_ps (DviContext *dvi,
+                  const char *filename,
+                  int         x,
+                  int         y,
+                  Uint        width,
+                  Uint        height)
+{
+       DviCairoDevice       *cairo_device;
+       unsigned char        *data = NULL;
+       int                   row_length;
+       SpectreDocument      *psdoc;
+       SpectreRenderContext *rc;
+       int                   w, h;
+       SpectreStatus         status;
+       cairo_surface_t      *image;
+
+       cairo_device = (DviCairoDevice *) dvi->device.device_data;
+
+       psdoc = spectre_document_new ();
+       spectre_document_load (psdoc, filename);
+       if (spectre_document_status (psdoc)) {
+               spectre_document_free (psdoc);
+               return;
+       }
+
+       spectre_document_get_page_size (psdoc, &w, &h);
+
+       rc = spectre_render_context_new ();
+       spectre_render_context_set_scale (rc,
+                                         (double)width / w,
+                                         (double)height / h);
+       spectre_document_render_full (psdoc, rc, &data, &row_length);   
+       status = spectre_document_status (psdoc);
+
+       spectre_render_context_free (rc);
+       spectre_document_free (psdoc);
+
+       if (status) {
+               g_warning ("Error rendering PS document %s: %s\n",
+                          filename, spectre_status_to_string (status));
+               free (data);
+               
+               return;
+       }
+
+       image = cairo_image_surface_create_for_data ((unsigned char *)data,
+                                                    CAIRO_FORMAT_RGB24,
+                                                    width, height,
+                                                    row_length);
+
+       cairo_save (cairo_device->cr);
+
+       cairo_translate (cairo_device->cr,
+                        x + cairo_device->xmargin,
+                        y + cairo_device->ymargin);
+       cairo_set_source_surface (cairo_device->cr, image, 0, 0); 
+       cairo_paint (cairo_device->cr);
+
+       cairo_restore (cairo_device->cr);
+
+       cairo_surface_destroy (image);
+       free (data);
+}
+#endif /* HAVE_SPECTRE */
+
 static int
 dvi_cairo_alloc_colors (void  *device_data,
                        Ulong *pixels,
@@ -208,6 +281,11 @@ mdvi_cairo_device_init (DviDevice *device)
        device->free_image = dvi_cairo_free_image;
        device->put_pixel = dvi_cairo_put_pixel;
        device->set_color = dvi_cairo_set_color;
+#ifdef HAVE_SPECTRE
+       device->draw_ps = dvi_cairo_draw_ps;
+#else
+       device->draw_ps = NULL;
+#endif
        device->refresh = NULL;
 }