summaryrefslogtreecommitdiffstats
path: root/src/ui/cache/svg_preview_cache.cpp
diff options
context:
space:
mode:
authorMartin Owens <doctormo@gmail.com>2014-03-27 01:33:44 +0000
committerMartin Owens <doctormo@gmail.com>2014-03-27 01:33:44 +0000
commit5a4fb2325f60d292b47330f540b26a3279341c90 (patch)
treed2aa7967be25450b83e625025366c618101ae49f /src/ui/cache/svg_preview_cache.cpp
parentThe Polar Arrange Tab of the Arrange Dialog now hides the parametric (diff)
parentRemove Snap menu item and improve grid menu item text (diff)
downloadinkscape-5a4fb2325f60d292b47330f540b26a3279341c90.tar.gz
inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.zip
Commit a merge to trunk, with probabal errors
(bzr r11073.1.36)
Diffstat (limited to 'src/ui/cache/svg_preview_cache.cpp')
-rw-r--r--src/ui/cache/svg_preview_cache.cpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/ui/cache/svg_preview_cache.cpp b/src/ui/cache/svg_preview_cache.cpp
index f8a806a13..f1d6304cb 100644
--- a/src/ui/cache/svg_preview_cache.cpp
+++ b/src/ui/cache/svg_preview_cache.cpp
@@ -19,7 +19,6 @@
# include "config.h"
#endif
-#include <glib.h>
#include <gtk/gtk.h>
#include <2geom/transforms.h>
#include "sp-namedview.h"
@@ -34,7 +33,7 @@
#include "ui/cache/svg_preview_cache.h"
-GdkPixbuf* render_pixbuf(Inkscape::Drawing &drawing, double scale_factor, const Geom::Rect& dbox, unsigned psize)
+GdkPixbuf* render_pixbuf(Inkscape::Drawing &drawing, double scale_factor, Geom::Rect const &dbox, unsigned psize)
{
Geom::Affine t(Geom::Scale(scale_factor, scale_factor));
drawing.root()->setTransform(Geom::Scale(scale_factor));
@@ -57,18 +56,12 @@ GdkPixbuf* render_pixbuf(Inkscape::Drawing &drawing, double scale_factor, const
/* Render */
cairo_surface_t *s = cairo_image_surface_create(
CAIRO_FORMAT_ARGB32, psize, psize);
- Inkscape::DrawingContext ct(s, area.min());
+ Inkscape::DrawingContext dc(s, area.min());
- drawing.render(ct, area, Inkscape::DrawingItem::RENDER_BYPASS_CACHE);
+ drawing.render(dc, area, Inkscape::DrawingItem::RENDER_BYPASS_CACHE);
cairo_surface_flush(s);
- GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(cairo_image_surface_get_data(s),
- GDK_COLORSPACE_RGB,
- TRUE,
- 8, psize, psize, cairo_image_surface_get_stride(s),
- ink_cairo_pixbuf_cleanup, s);
- convert_pixbuf_argb32_to_normal(pixbuf);
-
+ GdkPixbuf* pixbuf = ink_pixbuf_create_from_cairo_surface(s);
return pixbuf;
}
@@ -82,6 +75,12 @@ SvgPreview::SvgPreview()
SvgPreview::~SvgPreview()
{
+ for (std::map<Glib::ustring, GdkPixbuf *>::iterator i = _pixmap_cache.begin();
+ i != _pixmap_cache.end(); ++i)
+ {
+ g_object_unref(i->second);
+ i->second = NULL;
+ }
}
Glib::ustring SvgPreview::cache_key(gchar const *uri, gchar const *name, unsigned psize) const {
@@ -103,6 +102,7 @@ GdkPixbuf* SvgPreview::get_preview_from_cache(const Glib::ustring& key) {
}
void SvgPreview::set_preview_in_cache(const Glib::ustring& key, GdkPixbuf* px) {
+ g_object_ref(px);
_pixmap_cache[key] = px;
}
@@ -121,6 +121,16 @@ GdkPixbuf* SvgPreview::get_preview(const gchar* uri, const gchar* id, Inkscape::
return px;
}
+void SvgPreview::remove_preview_from_cache(const Glib::ustring& key) {
+ std::map<Glib::ustring, GdkPixbuf *>::iterator found = _pixmap_cache.find(key);
+ if ( found != _pixmap_cache.end() ) {
+ g_object_unref(found->second);
+ found->second = NULL;
+ _pixmap_cache.erase(key);
+ }
+}
+
+
}
}
}