summaryrefslogtreecommitdiffstats
path: root/src/ui/cache/svg_preview_cache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/cache/svg_preview_cache.cpp')
-rw-r--r--src/ui/cache/svg_preview_cache.cpp43
1 files changed, 16 insertions, 27 deletions
diff --git a/src/ui/cache/svg_preview_cache.cpp b/src/ui/cache/svg_preview_cache.cpp
index d4c8d0d0c..aead24236 100644
--- a/src/ui/cache/svg_preview_cache.cpp
+++ b/src/ui/cache/svg_preview_cache.cpp
@@ -28,7 +28,7 @@
#include "document-private.h"
#include "display/nr-arena.h"
#include "display/nr-arena-item.h"
-#include "libnr/nr-pixblock.h"
+#include "display/cairo-utils.h"
#include "ui/cache/svg_preview_cache.h"
@@ -45,10 +45,10 @@ GdkPixbuf* render_pixbuf(NRArenaItem* root, double scale_factor, const Geom::Rec
/* Item integer bbox in points */
NRRectL ibox;
- ibox.x0 = (int) floor(scale_factor * dbox.min()[Geom::X] + 0.5);
- ibox.y0 = (int) floor(scale_factor * dbox.min()[Geom::Y] + 0.5);
- ibox.x1 = (int) floor(scale_factor * dbox.max()[Geom::X] + 0.5);
- ibox.y1 = (int) floor(scale_factor * dbox.max()[Geom::Y] + 0.5);
+ ibox.x0 = floor(scale_factor * dbox.min()[Geom::X]);
+ ibox.y0 = floor(scale_factor * dbox.min()[Geom::Y]);
+ ibox.x1 = ceil(scale_factor * dbox.max()[Geom::X]);
+ ibox.y1 = ceil(scale_factor * dbox.max()[Geom::Y]);
/* Find visible area */
int width = ibox.x1 - ibox.x0;
@@ -64,34 +64,23 @@ GdkPixbuf* render_pixbuf(NRArenaItem* root, double scale_factor, const Geom::Rec
area.x1 = area.x0 + psize;
area.y1 = area.y0 + psize;
- /* Actual renderable area */
- NRRectL ua;
- ua.x0 = std::max(ibox.x0, area.x0);
- ua.y0 = std::max(ibox.y0, area.y0);
- ua.x1 = std::min(ibox.x1, area.x1);
- ua.y1 = std::min(ibox.y1, area.y1);
-
- /* Set up pixblock */
- guchar *px = g_new(guchar, 4 * psize * psize);
- memset(px, 0x00, 4 * psize * psize);
-
/* Render */
- NRPixBlock B;
- nr_pixblock_setup_extern( &B, NR_PIXBLOCK_MODE_R8G8B8A8N,
- ua.x0, ua.y0, ua.x1, ua.y1,
- px + 4 * psize * (ua.y0 - area.y0) +
- 4 * (ua.x0 - area.x0),
- 4 * psize, FALSE, FALSE );
- nr_arena_item_invoke_render(NULL, root, &ua, &B,
+ cairo_surface_t *s = cairo_image_surface_create(
+ CAIRO_FORMAT_ARGB32, psize, psize);
+ cairo_t *ct = cairo_create(s);
+
+ nr_arena_item_invoke_render(ct, root, &area, NULL,
NR_ARENA_ITEM_RENDER_NO_CACHE );
- nr_pixblock_release(&B);
+ cairo_surface_flush(s);
+ cairo_destroy(ct);
- GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(px,
+ GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(cairo_image_surface_get_data(s),
GDK_COLORSPACE_RGB,
TRUE,
- 8, psize, psize, psize * 4,
- (GdkPixbufDestroyNotify)g_free,
+ 8, psize, psize, cairo_image_surface_get_stride(s),
+ (GdkPixbufDestroyNotify)cairo_surface_destroy,
NULL);
+ convert_pixbuf_argb32_to_normal(pixbuf);
return pixbuf;
}