summaryrefslogtreecommitdiffstats
path: root/src/ui/cache/svg_preview_cache.h
diff options
context:
space:
mode:
authorBryce Harrington <bryce@bryceharrington.org>2007-02-20 07:28:05 +0000
committerbryce <bryce@users.sourceforge.net>2007-02-20 07:28:05 +0000
commita883506dfc9b0f30197d82354d5332446e4325ba (patch)
tree2009a2a33fabb45afe958b804bae63d2d567c490 /src/ui/cache/svg_preview_cache.h
parentPartial fix for bug 980157. (diff)
downloadinkscape-a883506dfc9b0f30197d82354d5332446e4325ba.tar.gz
inkscape-a883506dfc9b0f30197d82354d5332446e4325ba.zip
Moving functions from svg_preview_cache.h to a new .cpp
(bzr r2402)
Diffstat (limited to 'src/ui/cache/svg_preview_cache.h')
-rw-r--r--src/ui/cache/svg_preview_cache.h138
1 files changed, 70 insertions, 68 deletions
diff --git a/src/ui/cache/svg_preview_cache.h b/src/ui/cache/svg_preview_cache.h
index 7b802fee3..2d84b7273 100644
--- a/src/ui/cache/svg_preview_cache.h
+++ b/src/ui/cache/svg_preview_cache.h
@@ -1,3 +1,6 @@
+#ifndef __SVG_PREVIEW_CACHE_H__
+#define __SVG_PREVIEW_CACHE_H__
+
/** \file
* SPIcon: Generic icon widget
*/
@@ -8,71 +11,70 @@
*
*/
-GdkPixbuf* get_pixbuf(GdkPixbuf* pixbuf) {
- return pixbuf;
-}
-
-GdkPixbuf* render_pixbuf(NRArenaItem* root, double scale_factor, const NR::Rect& dbox, unsigned psize) {
- NRGC gc(NULL);
- NRMatrix t;
-
- nr_matrix_set_scale(&t, scale_factor, scale_factor);
- nr_arena_item_set_transform(root, &t);
-
- nr_matrix_set_identity(&gc.transform);
- nr_arena_item_invoke_update( root, NULL, &gc,
- NR_ARENA_ITEM_STATE_ALL,
- NR_ARENA_ITEM_STATE_NONE );
-
- /* Item integer bbox in points */
- NRRectL ibox;
- ibox.x0 = (int) floor(scale_factor * dbox.min()[NR::X] + 0.5);
- ibox.y0 = (int) floor(scale_factor * dbox.min()[NR::Y] + 0.5);
- ibox.x1 = (int) floor(scale_factor * dbox.max()[NR::X] + 0.5);
- ibox.y1 = (int) floor(scale_factor * dbox.max()[NR::Y] + 0.5);
-
- /* Find visible area */
- int width = ibox.x1 - ibox.x0;
- int height = ibox.y1 - ibox.y0;
- 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;
-
- /* 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( root, &ua, &B,
- NR_ARENA_ITEM_RENDER_NO_CACHE );
- nr_pixblock_release(&B);
-
- GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(px,
- GDK_COLORSPACE_RGB,
- TRUE,
- 8, psize, psize, psize * 4,
- (GdkPixbufDestroyNotify)g_free,
- NULL);
-
- return pixbuf;
-}
+GdkPixbuf* render_pixbuf(NRArenaItem* root, double scale_factor, const NR::Rect& dbox, unsigned psize);
+
+namespace Inkscape {
+namespace UI {
+namespace Cache {
+
+class SvgPreview {
+ protected:
+ std::map<Glib::ustring, GdkPixbuf*> _pixmap_cache;
+
+ public:
+ SvgPreview() {}
+ ~SvgPreview() {}
+
+ Glib::ustring cache_key(gchar const *name, unsigned psize) const {
+ Glib::ustring key = name;
+ key += ":";
+ key += psize;
+ return key;
+ }
+
+ GdkPixbuf* get_preview_from_cache(const Glib::ustring& key) {
+ std::map<Glib::ustring, GdkPixbuf *>::iterator found = _pixmap_cache.find(key);
+ if ( found != _pixmap_cache.end() ) {
+ return found->second;
+ }
+ return NULL;
+ }
+
+ void set_preview_in_cache(const Glib::ustring& key, GdkPixbuf* px) {
+ _pixmap_cache[key] = px;
+ }
+
+ GdkPixbuf* get_preview(const gchar* id, NRArenaItem *root, double scale_factor, unsigned int psize) {
+ // First try looking up the cached preview in the cache map
+ Glib::ustring key = cache_key(id, psize);
+ GdkPixbuf* px = get_preview_from_cache(key);
+
+ if (px == NULL) {
+/*
+ px = render_pixbuf(root, scale_factor, dbox, psize);
+ set_preview_in_cache(key, px);
+*/
+ }
+
+ }
+};
+
+}; // namespace Cache
+}; // namespace UI
+}; // namespace Inkscape
+
+
+
+#endif // __SVG_PREVIEW_CACHE_H__
+/*
+ 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:encoding=utf-8:textwidth=99 :
+
+