Pierre Carrier e570d00
diff -up ./src/ApvlvFile.cpp.old ./src/ApvlvFile.cpp
Pierre Carrier e570d00
--- ./src/ApvlvFile.cpp.old	2011-08-02 03:14:08.000000000 +0400
Pierre Carrier e570d00
+++ ./src/ApvlvFile.cpp	2011-08-02 03:16:32.000000000 +0400
Pierre Carrier e570d00
@@ -28,6 +28,7 @@
Pierre Carrier e570d00
 #include "ApvlvFile.hpp"
Pierre Carrier e570d00
 #include "ApvlvUtil.hpp"
Pierre Carrier e570d00
 #include "ApvlvView.hpp"
Pierre Carrier e570d00
+#include "poppler_page_render_to_pixbuf.c"
Pierre Carrier e570d00
 
Pierre Carrier e570d00
 #include <iostream>
Pierre Carrier e570d00
 #include <fstream>
Pierre Carrier e570d00
Pierre Carrier e570d00
diff -up /dev/null ./src/poppler_page_render_to_pixbuf.c
Pierre Carrier e570d00
--- ./src/poppler_page_render_to_pixbuf.c.new	2011-08-02 00:58:46.000000000 +0400
Pierre Carrier e570d00
+++ ./src/poppler_page_render_to_pixbuf.c	2011-08-02 03:28:02.000000000 +0400
Pierre Carrier e570d00
@@ -0,0 +1,136 @@
Pierre Carrier e570d00
+#if POPPLER_CHECK_VERSION(0, 17, 0)
Pierre Carrier e570d00
+typedef bool GBool;
Pierre Carrier e570d00
+#define gTrue true
Pierre Carrier e570d00
+#define gFalse false
Pierre Carrier e570d00
+
Pierre Carrier e570d00
+static void
Pierre Carrier e570d00
+copy_cairo_surface_to_pixbuf (cairo_surface_t *surface,
Pierre Carrier e570d00
+			      GdkPixbuf       *pixbuf)
Pierre Carrier e570d00
+{
Pierre Carrier e570d00
+  int cairo_width, cairo_height, cairo_rowstride;
Pierre Carrier e570d00
+  unsigned char *pixbuf_data, *dst, *cairo_data;
Pierre Carrier e570d00
+  int pixbuf_rowstride, pixbuf_n_channels;
Pierre Carrier e570d00
+  unsigned int *src;
Pierre Carrier e570d00
+  int x, y;
Pierre Carrier e570d00
+
Pierre Carrier e570d00
+  cairo_width = cairo_image_surface_get_width (surface);
Pierre Carrier e570d00
+  cairo_height = cairo_image_surface_get_height (surface);
Pierre Carrier e570d00
+  cairo_rowstride = cairo_image_surface_get_stride (surface);
Pierre Carrier e570d00
+  cairo_data = cairo_image_surface_get_data (surface);
Pierre Carrier e570d00
+
Pierre Carrier e570d00
+  pixbuf_data = gdk_pixbuf_get_pixels (pixbuf);
Pierre Carrier e570d00
+  pixbuf_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
Pierre Carrier e570d00
+  pixbuf_n_channels = gdk_pixbuf_get_n_channels (pixbuf);
Pierre Carrier e570d00
+
Pierre Carrier e570d00
+  if (cairo_width > gdk_pixbuf_get_width (pixbuf))
Pierre Carrier e570d00
+    cairo_width = gdk_pixbuf_get_width (pixbuf);
Pierre Carrier e570d00
+  if (cairo_height > gdk_pixbuf_get_height (pixbuf))
Pierre Carrier e570d00
+    cairo_height = gdk_pixbuf_get_height (pixbuf);
Pierre Carrier e570d00
+  for (y = 0; y < cairo_height; y++)
Pierre Carrier e570d00
+    {
Pierre Carrier e570d00
+      src = (unsigned int *) (cairo_data + y * cairo_rowstride);
Pierre Carrier e570d00
+      dst = pixbuf_data + y * pixbuf_rowstride;
Pierre Carrier e570d00
+      for (x = 0; x < cairo_width; x++) 
Pierre Carrier e570d00
+	{
Pierre Carrier e570d00
+	  dst[0] = (*src >> 16) & 0xff;
Pierre Carrier e570d00
+	  dst[1] = (*src >> 8) & 0xff; 
Pierre Carrier e570d00
+	  dst[2] = (*src >> 0) & 0xff;
Pierre Carrier e570d00
+	  if (pixbuf_n_channels == 4)
Pierre Carrier e570d00
+	      dst[3] = (*src >> 24) & 0xff;
Pierre Carrier e570d00
+	  dst += pixbuf_n_channels;
Pierre Carrier e570d00
+	  src++;
Pierre Carrier e570d00
+	}
Pierre Carrier e570d00
+    }
Pierre Carrier e570d00
+}
Pierre Carrier e570d00
+
Pierre Carrier e570d00
+static void
Pierre Carrier e570d00
+_poppler_page_render_to_pixbuf (PopplerPage *page,
Pierre Carrier e570d00
+				int src_x, int src_y,
Pierre Carrier e570d00
+				int src_width, int src_height,
Pierre Carrier e570d00
+				double scale,
Pierre Carrier e570d00
+				int rotation,
Pierre Carrier e570d00
+				GBool printing,
Pierre Carrier e570d00
+				GdkPixbuf *pixbuf)
Pierre Carrier e570d00
+{
Pierre Carrier e570d00
+  cairo_t *cr;
Pierre Carrier e570d00
+  cairo_surface_t *surface;
Pierre Carrier e570d00
+
Pierre Carrier e570d00
+  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
Pierre Carrier e570d00
+					src_width, src_height);
Pierre Carrier e570d00
+  cr = cairo_create (surface);
Pierre Carrier e570d00
+  cairo_save (cr);
Pierre Carrier e570d00
+  switch (rotation) {
Pierre Carrier e570d00
+  case 90:
Pierre Carrier e570d00
+	  cairo_translate (cr, src_x + src_width, -src_y);
Pierre Carrier e570d00
+	  break;
Pierre Carrier e570d00
+  case 180:
Pierre Carrier e570d00
+	  cairo_translate (cr, src_x + src_width, src_y + src_height);
Pierre Carrier e570d00
+	  break;
Pierre Carrier e570d00
+  case 270:
Pierre Carrier e570d00
+	  cairo_translate (cr, -src_x, src_y + src_height);
Pierre Carrier e570d00
+	  break;
Pierre Carrier e570d00
+  default:
Pierre Carrier e570d00
+	  cairo_translate (cr, -src_x, -src_y);
Pierre Carrier e570d00
+  }
Pierre Carrier e570d00
+
Pierre Carrier e570d00
+  if (scale != 1.0)
Pierre Carrier e570d00
+	  cairo_scale (cr, scale, scale);
Pierre Carrier e570d00
+
Pierre Carrier e570d00
+  if (rotation != 0)
Pierre Carrier e570d00
+	  cairo_rotate (cr, rotation * G_PI / 180.0);
Pierre Carrier e570d00
+
Pierre Carrier e570d00
+  if (printing)
Pierre Carrier e570d00
+	  poppler_page_render_for_printing (page, cr);
Pierre Carrier e570d00
+  else
Pierre Carrier e570d00
+	  poppler_page_render (page, cr);
Pierre Carrier e570d00
+  cairo_restore (cr);
Pierre Carrier e570d00
+
Pierre Carrier e570d00
+  cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
Pierre Carrier e570d00
+  cairo_set_source_rgb (cr, 1., 1., 1.);
Pierre Carrier e570d00
+  cairo_paint (cr);
Pierre Carrier e570d00
+
Pierre Carrier e570d00
+  cairo_destroy (cr);
Pierre Carrier e570d00
+
Pierre Carrier e570d00
+  copy_cairo_surface_to_pixbuf (surface, pixbuf);
Pierre Carrier e570d00
+  cairo_surface_destroy (surface);
Pierre Carrier e570d00
+}
Pierre Carrier e570d00
+
Pierre Carrier e570d00
+/**
Pierre Carrier e570d00
+ * poppler_page_render_to_pixbuf:
Pierre Carrier e570d00
+ * @page: the page to render from
Pierre Carrier e570d00
+ * @src_x: x coordinate of upper left corner  
Pierre Carrier e570d00
+ * @src_y: y coordinate of upper left corner  
Pierre Carrier e570d00
+ * @src_width: width of rectangle to render  
Pierre Carrier e570d00
+ * @src_height: height of rectangle to render
Pierre Carrier e570d00
+ * @scale: scale specified as pixels per point
Pierre Carrier e570d00
+ * @rotation: rotate the document by the specified degree
Pierre Carrier e570d00
+ * @pixbuf: pixbuf to render into
Pierre Carrier e570d00
+ *
Pierre Carrier e570d00
+ * First scale the document to match the specified pixels per point,
Pierre Carrier e570d00
+ * then render the rectangle given by the upper left corner at
Pierre Carrier e570d00
+ * (src_x, src_y) and src_width and src_height.
Pierre Carrier e570d00
+ * This function is for rendering a page that will be displayed.
Pierre Carrier e570d00
+ * If you want to render a page that will be printed use
Pierre Carrier e570d00
+ * poppler_page_render_to_pixbuf_for_printing() instead
Pierre Carrier e570d00
+ *
Pierre Carrier e570d00
+ * Deprecated: 0.16
Pierre Carrier e570d00
+ **/
Pierre Carrier e570d00
+void
Pierre Carrier e570d00
+poppler_page_render_to_pixbuf (PopplerPage *page,
Pierre Carrier e570d00
+			       int src_x, int src_y,
Pierre Carrier e570d00
+			       int src_width, int src_height,
Pierre Carrier e570d00
+			       double scale,
Pierre Carrier e570d00
+			       int rotation,
Pierre Carrier e570d00
+			       GdkPixbuf *pixbuf)
Pierre Carrier e570d00
+{
Pierre Carrier e570d00
+  g_return_if_fail (POPPLER_IS_PAGE (page));
Pierre Carrier e570d00
+  g_return_if_fail (scale > 0.0);
Pierre Carrier e570d00
+  g_return_if_fail (pixbuf != NULL);
Pierre Carrier e570d00
+
Pierre Carrier e570d00
+  _poppler_page_render_to_pixbuf (page, src_x, src_y,
Pierre Carrier e570d00
+				  src_width, src_height,
Pierre Carrier e570d00
+				  scale, rotation,
Pierre Carrier e570d00
+				  gFalse,
Pierre Carrier e570d00
+				  pixbuf);
Pierre Carrier e570d00
+}
Pierre Carrier e570d00
+#endif