Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 377063 | Differences between
and this patch

Collapse All | Expand All

(-)poppler.override (+153 lines)
Lines 257-262 Link Here
257
    #define PYGDK_TYPE_REGION (pygdk_region_get_type ())
257
    #define PYGDK_TYPE_REGION (pygdk_region_get_type ())
258
#endif /* GDK_TYPE_REGION */
258
#endif /* GDK_TYPE_REGION */
259
259
260
static void
261
copy_cairo_surface_to_pixbuf (cairo_surface_t *surface,
262
			      GdkPixbuf       *pixbuf)
263
{
264
  int cairo_width, cairo_height, cairo_rowstride;
265
  unsigned char *pixbuf_data, *dst, *cairo_data;
266
  int pixbuf_rowstride, pixbuf_n_channels;
267
  unsigned int *src;
268
  int x, y;
269
270
  cairo_width = cairo_image_surface_get_width (surface);
271
  cairo_height = cairo_image_surface_get_height (surface);
272
  cairo_rowstride = cairo_image_surface_get_stride (surface);
273
  cairo_data = cairo_image_surface_get_data (surface);
274
275
  pixbuf_data = gdk_pixbuf_get_pixels (pixbuf);
276
  pixbuf_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
277
  pixbuf_n_channels = gdk_pixbuf_get_n_channels (pixbuf);
278
279
  if (cairo_width > gdk_pixbuf_get_width (pixbuf))
280
    cairo_width = gdk_pixbuf_get_width (pixbuf);
281
  if (cairo_height > gdk_pixbuf_get_height (pixbuf))
282
    cairo_height = gdk_pixbuf_get_height (pixbuf);
283
  for (y = 0; y < cairo_height; y++)
284
    {
285
      src = (unsigned int *) (cairo_data + y * cairo_rowstride);
286
      dst = pixbuf_data + y * pixbuf_rowstride;
287
      for (x = 0; x < cairo_width; x++) 
288
	{
289
	  dst[0] = (*src >> 16) & 0xff;
290
	  dst[1] = (*src >> 8) & 0xff; 
291
	  dst[2] = (*src >> 0) & 0xff;
292
	  if (pixbuf_n_channels == 4)
293
	      dst[3] = (*src >> 24) & 0xff;
294
	  dst += pixbuf_n_channels;
295
	  src++;
296
	}
297
    }
298
}	
299
300
static void
301
_poppler_page_render_to_pixbuf (PopplerPage *page,
302
				int src_x, int src_y,
303
				int src_width, int src_height,
304
				double scale,
305
				int rotation,
306
				gboolean printing,
307
				GdkPixbuf *pixbuf)
308
{
309
  cairo_t *cr;
310
  cairo_surface_t *surface;
311
312
  if (scale <= 0.0) return;
313
314
  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
315
					src_width, src_height);
316
  cr = cairo_create (surface);
317
  cairo_save (cr);
318
  switch (rotation) {
319
  case 90:
320
	  cairo_translate (cr, src_x + src_width, -src_y);
321
	  break;
322
  case 180:
323
	  cairo_translate (cr, src_x + src_width, src_y + src_height);
324
	  break;
325
  case 270:
326
	  cairo_translate (cr, -src_x, src_y + src_height);
327
	  break;
328
  default:
329
	  cairo_translate (cr, -src_x, -src_y);
330
  }
331
332
  if (scale != 1.0)
333
	  cairo_scale (cr, scale, scale);
334
335
  if (rotation != 0)
336
	  cairo_rotate (cr, rotation * G_PI / 180.0);
337
338
  if (printing)
339
	  poppler_page_render_for_printing (page, cr);
340
  else
341
	  poppler_page_render (page, cr);
342
  cairo_restore (cr);
343
344
  cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
345
  cairo_set_source_rgb (cr, 1., 1., 1.);
346
  cairo_paint (cr);
347
348
  cairo_destroy (cr);
349
350
  copy_cairo_surface_to_pixbuf (surface, pixbuf);
351
  cairo_surface_destroy (surface);
352
}
353
260
%%
354
%%
261
init
355
init
262
356
Lines 600-602 Link Here
600
    return PycairoSurface_FromSurface(surface, NULL, NULL);
694
    return PycairoSurface_FromSurface(surface, NULL, NULL);
601
#endif
695
#endif
602
}
696
}
697
%%
698
override poppler_page_render_to_pixbuf kwargs
699
static PyObject *
700
_wrap_poppler_page_render_to_pixbuf(PyGObject *self,
701
                                    PyObject *args,
702
                                    PyObject *kwargs)
703
{
704
    static char *kwlist[] = { "src_x", "src_y", "src_width",
705
                              "src_height", "scale", "rotation", "pixbuf", NULL };
706
    int src_x, src_y, src_width, src_height, rotation;
707
    double scale;
708
    PyGObject *pixbuf;
709
710
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
711
                                     "iiiidiO!:Poppler.Page.render_to_pixbuf",
712
                                     kwlist, &src_x, &src_y, &src_width,
713
                                     &src_height, &scale, &rotation, &PyGdkPixbuf_Type, &pixbuf))
714
        return NULL;
715
716
    pyg_begin_allow_threads;
717
718
    _poppler_page_render_to_pixbuf(POPPLER_PAGE(self->obj), src_x, src_y,
719
                                   src_width, src_height, scale,
720
                                   rotation, FALSE, GDK_PIXBUF(pixbuf->obj));
721
722
    pyg_end_allow_threads;
723
    Py_INCREF(Py_None);
724
    return Py_None;
725
}
726
%%
727
override poppler_page_render_to_pixbuf_for_printing kwargs
728
static PyObject *
729
_wrap_poppler_page_render_to_pixbuf_for_printing(PyGObject *self,
730
                                                 PyObject *args,
731
                                                 PyObject *kwargs)
732
{
733
    static char *kwlist[] = { "src_x", "src_y", "src_width",
734
                              "src_height", "scale", "rotation", "pixbuf", NULL };
735
    int src_x, src_y, src_width, src_height, rotation;
736
    double scale;
737
    PyGObject *pixbuf;
738
739
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
740
                                     "iiiidiO!:Poppler.Page.render_to_pixbuf_for_printing",
741
                                     kwlist, &src_x, &src_y, &src_width,
742
                                     &src_height, &scale, &rotation, &PyGdkPixbuf_Type, &pixbuf))
743
        return NULL;
744
745
    pyg_begin_allow_threads;
746
747
    _poppler_page_render_to_pixbuf(POPPLER_PAGE(self->obj),
748
                                   src_x, src_y, src_width,
749
                                   src_height, scale,
750
                                   rotation, TRUE, GDK_PIXBUF(pixbuf->obj));
751
752
    pyg_end_allow_threads;
753
    Py_INCREF(Py_None);
754
    return Py_None;
755
}

Return to bug 377063