summaryrefslogtreecommitdiffstats
path: root/src/ui/cache/svg_preview_cache.cpp
diff options
context:
space:
mode:
authorAndrew Higginson <at.higginson@gmail.com>2011-12-27 21:04:47 +0000
committerAndrew <at.higginson@gmail.com>2011-12-27 21:04:47 +0000
commit80960b623a99aae1402ab651b2974ef544ed3b03 (patch)
treeba49d42c2789e9e11f805e2d5263e10f9fedeef8 /src/ui/cache/svg_preview_cache.cpp
parenttry to fix bug (diff)
parentGDL: Cherry-pick upstream patch 73852 (2011-03-23) - Add missing return value. (diff)
downloadinkscape-80960b623a99aae1402ab651b2974ef544ed3b03.tar.gz
inkscape-80960b623a99aae1402ab651b2974ef544ed3b03.zip
merged with trunk so I can build again...
(bzr r10092.1.36)
Diffstat (limited to 'src/ui/cache/svg_preview_cache.cpp')
-rw-r--r--src/ui/cache/svg_preview_cache.cpp92
1 files changed, 40 insertions, 52 deletions
diff --git a/src/ui/cache/svg_preview_cache.cpp b/src/ui/cache/svg_preview_cache.cpp
index a7ad1701d..f8a806a13 100644
--- a/src/ui/cache/svg_preview_cache.cpp
+++ b/src/ui/cache/svg_preview_cache.cpp
@@ -19,78 +19,55 @@
# include "config.h"
#endif
-#include <glib/gmem.h>
+#include <glib.h>
#include <gtk/gtk.h>
+#include <2geom/transforms.h>
#include "sp-namedview.h"
#include "selection.h"
#include "inkscape.h"
#include "sp-rect.h"
#include "document-private.h"
-#include "display/nr-arena.h"
-#include "display/nr-arena-item.h"
+#include "display/cairo-utils.h"
+#include "display/drawing-context.h"
+#include "display/drawing-item.h"
+#include "display/drawing.h"
#include "ui/cache/svg_preview_cache.h"
-GdkPixbuf* render_pixbuf(NRArenaItem* root, double scale_factor, const Geom::Rect& dbox, unsigned psize) {
- NRGC gc(NULL);
-
+GdkPixbuf* render_pixbuf(Inkscape::Drawing &drawing, double scale_factor, const Geom::Rect& dbox, unsigned psize)
+{
Geom::Affine t(Geom::Scale(scale_factor, scale_factor));
- nr_arena_item_set_transform(root, t);
+ drawing.root()->setTransform(Geom::Scale(scale_factor));
- gc.transform.setIdentity();
- nr_arena_item_invoke_update( root, NULL, &gc,
- NR_ARENA_ITEM_STATE_ALL,
- NR_ARENA_ITEM_STATE_NONE );
+ Geom::IntRect ibox = (dbox * Geom::Scale(scale_factor)).roundOutwards();
- /* 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);
+ drawing.update(ibox);
/* Find visible area */
- int width = ibox.x1 - ibox.x0;
- int height = ibox.y1 - ibox.y0;
+ int width = ibox.width();
+ int height = ibox.height();
int dx = psize;
int dy = psize;
dx = (dx - width)/2; // watch out for size, since 'unsigned'-'signed' can cause problems if the result is negative
dy = (dy - height)/2;
- NRRectL area;
- area.x0 = ibox.x0 - dx;
- area.y0 = ibox.y0 - dy;
- area.x1 = area.x0 + psize;
- area.y1 = area.y0 + psize;
+ Geom::IntRect area = Geom::IntRect::from_xywh(
+ ibox.min() - Geom::IntPoint(dx, dy), Geom::IntPoint(psize, 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);
+ /* Render */
+ cairo_surface_t *s = cairo_image_surface_create(
+ CAIRO_FORMAT_ARGB32, psize, psize);
+ Inkscape::DrawingContext ct(s, area.min());
- /* Set up pixblock */
- guchar *px = g_new(guchar, 4 * psize * psize);
- memset(px, 0x00, 4 * psize * psize);
+ drawing.render(ct, area, Inkscape::DrawingItem::RENDER_BYPASS_CACHE);
+ cairo_surface_flush(s);
- /* 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,
- NR_ARENA_ITEM_RENDER_NO_CACHE );
- nr_pixblock_release(&B);
-
- 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,
- NULL);
+ 8, psize, psize, cairo_image_surface_get_stride(s),
+ ink_cairo_pixbuf_cleanup, s);
+ convert_pixbuf_argb32_to_normal(pixbuf);
return pixbuf;
}
@@ -129,7 +106,7 @@ void SvgPreview::set_preview_in_cache(const Glib::ustring& key, GdkPixbuf* px) {
_pixmap_cache[key] = px;
}
-GdkPixbuf* SvgPreview::get_preview(const gchar* uri, const gchar* id, NRArenaItem */*root*/,
+GdkPixbuf* SvgPreview::get_preview(const gchar* uri, const gchar* id, Inkscape::DrawingItem */*root*/,
double /*scale_factor*/, unsigned int psize) {
// First try looking up the cached preview in the cache map
Glib::ustring key = cache_key(uri, id, psize);
@@ -144,6 +121,17 @@ GdkPixbuf* SvgPreview::get_preview(const gchar* uri, const gchar* id, NRArenaIte
return px;
}
-};
-};
-};
+}
+}
+}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :