From 55f7e59c13b6fb502a0cfbbe811f2f3f90cc6f80 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Tue, 29 Jun 2010 23:05:56 +0200 Subject: Fix icons (bzr r9508.1.7) --- src/widgets/icon.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'src/widgets/icon.cpp') diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 5d91d3532..51bdfef66 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -913,6 +913,7 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, { bool const dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpSvg"); guchar *px = NULL; + int w, h, stride; if (doc) { SPObject *object = doc->getObjectById(name); @@ -1010,19 +1011,59 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, g_message( " area --'%s' (%f,%f)-(%f,%f)", name, (double)area.x0, (double)area.y0, (double)area.x1, (double)area.y1 ); g_message( " ua --'%s' (%f,%f)-(%f,%f)", name, (double)ua.x0, (double)ua.y0, (double)ua.x1, (double)ua.y1 ); } + + w = ua.x1 - ua.x0; + h = ua.y1 - ua.y0; + stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, w); + /* Set up pixblock */ - px = g_new(guchar, 4 * psize * psize); - memset(px, 0x00, 4 * psize * psize); + px = g_new(guchar, stride * h); + memset(px, 0x00, stride * h); + /* Render */ + cairo_surface_t *s = cairo_image_surface_create_for_data(px, + CAIRO_FORMAT_ARGB32, w, h, stride); + cairo_t *ct = cairo_create(s); + 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_invoke_render(ct, root, &ua, &B, NR_ARENA_ITEM_RENDER_NO_CACHE ); nr_pixblock_release(&B); + cairo_destroy(ct); + cairo_surface_destroy(s); + + // convert to GdkPixbuf format + guint32 *ipx = reinterpret_cast(px); + for (int i = 0; i < h; ++i) { + for (int j = 0; j < w; ++j) { + int index = i * stride / 4 + j; + guint32 c = ipx[index]; + guint32 o = 0; + guint32 a = (c & 0xff000000) >> 24; + if (a != 0) { + // extract color components + guint32 r = (c & 0x00ff0000) >> 16; + guint32 g = (c & 0x0000ff00) >> 8; + guint32 b = (c & 0x000000ff); + // unpremultiply; adding a/2 gives correct rounding + r = (r * 255 + a/2) / a; + b = (b * 255 + a/2) / a; + g = (g * 255 + a/2) / a; + // combine into output +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + o = (r) | (g << 8) | (b << 16) | (a << 24); +#else + o = (r << 24) | (g << 16) | (b << 8) | (a); +#endif + } + ipx[index] = o; + } + } if ( Inkscape::Preferences::get()->getBool("/debug/icons/overlaySvg") ) { sp_icon_overlay_pixels( px, psize, psize, 4 * psize, 0x00, 0x00, 0xff ); -- cgit v1.2.3 From 13b15b7b977eecbededd1734f5ab001f0c44d21f Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Wed, 30 Jun 2010 00:41:48 +0200 Subject: Consolidate Cairo utils in display/cairo-utils.h. Fix icons harder. (bzr r9508.1.8) --- src/widgets/icon.cpp | 65 ++++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 45 deletions(-) (limited to 'src/widgets/icon.cpp') diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 51bdfef66..1eb3ef0ab 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -25,6 +25,7 @@ #include "inkscape.h" #include "document.h" #include "sp-item.h" +#include "display/cairo-utils.h" #include "display/nr-arena.h" #include "display/nr-arena-item.h" #include "io/sys.h" @@ -909,11 +910,11 @@ GdkPixbuf *sp_icon_image_load_pixmap(gchar const *name, unsigned /*lsize*/, unsi // takes doc, root, icon, and icon name to produce pixels extern "C" guchar * sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, - gchar const *name, unsigned psize ) + gchar const *name, unsigned psize, + unsigned &stride) { bool const dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpSvg"); guchar *px = NULL; - int w, h, stride; if (doc) { SPObject *object = doc->getObjectById(name); @@ -1012,25 +1013,23 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, g_message( " ua --'%s' (%f,%f)-(%f,%f)", name, (double)ua.x0, (double)ua.y0, (double)ua.x1, (double)ua.y1 ); } - w = ua.x1 - ua.x0; - h = ua.y1 - ua.y0; - stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, w); + stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, psize); /* Set up pixblock */ - px = g_new(guchar, stride * h); - memset(px, 0x00, stride * h); + px = g_new(guchar, stride * psize); + memset(px, 0x00, stride * psize); /* Render */ cairo_surface_t *s = cairo_image_surface_create_for_data(px, - CAIRO_FORMAT_ARGB32, w, h, stride); + CAIRO_FORMAT_ARGB32, psize, psize, stride); cairo_t *ct = cairo_create(s); 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) + + px + stride * (ua.y0 - area.y0) + 4 * (ua.x0 - area.x0), - 4 * psize, FALSE, FALSE ); + stride, FALSE, FALSE ); nr_arena_item_invoke_render(ct, root, &ua, &B, NR_ARENA_ITEM_RENDER_NO_CACHE ); nr_pixblock_release(&B); @@ -1038,35 +1037,10 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, cairo_surface_destroy(s); // convert to GdkPixbuf format - guint32 *ipx = reinterpret_cast(px); - for (int i = 0; i < h; ++i) { - for (int j = 0; j < w; ++j) { - int index = i * stride / 4 + j; - guint32 c = ipx[index]; - guint32 o = 0; - guint32 a = (c & 0xff000000) >> 24; - if (a != 0) { - // extract color components - guint32 r = (c & 0x00ff0000) >> 16; - guint32 g = (c & 0x0000ff00) >> 8; - guint32 b = (c & 0x000000ff); - // unpremultiply; adding a/2 gives correct rounding - r = (r * 255 + a/2) / a; - b = (b * 255 + a/2) / a; - g = (g * 255 + a/2) / a; - // combine into output -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - o = (r) | (g << 8) | (b << 16) | (a << 24); -#else - o = (r << 24) | (g << 16) | (b << 8) | (a); -#endif - } - ipx[index] = o; - } - } + convert_pixels_argb32_to_pixbuf(px, psize, psize, stride); if ( Inkscape::Preferences::get()->getBool("/debug/icons/overlaySvg") ) { - sp_icon_overlay_pixels( px, psize, psize, 4 * psize, 0x00, 0x00, 0xff ); + sp_icon_overlay_pixels( px, psize, psize, stride, 0x00, 0x00, 0xff ); } } } @@ -1119,8 +1093,7 @@ static std::list &icons_svg_paths() } // this function renders icons from icons.svg and returns the pixels. -static guchar *load_svg_pixels(gchar const *name, - unsigned /*lsize*/, unsigned psize) +static guchar *load_svg_pixels(gchar const *name, unsigned psize, unsigned &stride) { SPDocument *doc = NULL; NRArenaItem *root = NULL; @@ -1197,7 +1170,7 @@ static guchar *load_svg_pixels(gchar const *name, continue; } - px = sp_icon_doc_icon( doc, root, name, psize ); + px = sp_icon_doc_icon( doc, root, name, psize, stride); // if (px) { // g_message("Found icon %s in %s", name, doc_filename); // } @@ -1251,19 +1224,20 @@ bool prerender_icon(gchar const *name, GtkIconSize lsize, unsigned psize) if (dump) { g_message("prerender_icon [%s] %d:%d", name, lsize, psize); } - guchar* px = load_svg_pixels(name, lsize, psize); + unsigned stride; + guchar* px = load_svg_pixels(name, psize, stride); if ( !px ) { // check for a fallback name if ( legacyNames.find(name) != legacyNames.end() ) { if ( dump ) { g_message("load_svg_pixels([%s]=%s, %d, %d)", name, legacyNames[name].c_str(), lsize, psize); } - px = load_svg_pixels(legacyNames[name].c_str(), lsize, psize); + px = load_svg_pixels(legacyNames[name].c_str(), psize, stride); } } if (px) { GdkPixbuf* pb = gdk_pixbuf_new_from_data( px, GDK_COLORSPACE_RGB, TRUE, 8, - psize, psize, psize * 4, + psize, psize, stride, reinterpret_cast(g_free), NULL ); pb_cache[key] = pb; addToIconSet(pb, name, lsize, psize); @@ -1289,10 +1263,11 @@ static GdkPixbuf *sp_icon_image_load_svg(gchar const *name, GtkIconSize lsize, u // did we already load this icon at this scale/size? GdkPixbuf* pb = get_cached_pixbuf(key); if (!pb) { - guchar *px = load_svg_pixels(name, lsize, psize); + unsigned stride; + guchar *px = load_svg_pixels(name, psize, stride); if (px) { pb = gdk_pixbuf_new_from_data(px, GDK_COLORSPACE_RGB, TRUE, 8, - psize, psize, psize * 4, + psize, psize, stride, (GdkPixbufDestroyNotify)g_free, NULL); pb_cache[key] = pb; addToIconSet(pb, name, lsize, psize); -- cgit v1.2.3 From 30884b9e814d7baaa2299803e8cb76cf203ca084 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Wed, 4 Aug 2010 05:45:58 +0200 Subject: Wholesale cruft removal part 1 (bzr r9508.1.44) --- src/widgets/icon.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'src/widgets/icon.cpp') diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 1eb3ef0ab..4ba86b295 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -1024,15 +1024,8 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, CAIRO_FORMAT_ARGB32, psize, psize, stride); cairo_t *ct = cairo_create(s); - NRPixBlock B; - nr_pixblock_setup_extern( &B, NR_PIXBLOCK_MODE_R8G8B8A8N, - ua.x0, ua.y0, ua.x1, ua.y1, - px + stride * (ua.y0 - area.y0) + - 4 * (ua.x0 - area.x0), - stride, FALSE, FALSE ); - nr_arena_item_invoke_render(ct, root, &ua, &B, + nr_arena_item_invoke_render(ct, root, &ua, NULL, NR_ARENA_ITEM_RENDER_NO_CACHE ); - nr_pixblock_release(&B); cairo_destroy(ct); cairo_surface_destroy(s); -- cgit v1.2.3 From 2f3d79db2fad212c8aa1bff7bb13132a34541aff Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sun, 15 Aug 2010 03:19:33 +0200 Subject: Make nr_arena_invoke_render expect an already transformed context, to remove a limitation to integer translations imposed by NRRectL (bzr r9508.1.68) --- src/widgets/icon.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/widgets/icon.cpp') diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 4ba86b295..d8f451ed7 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -1023,6 +1023,7 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, cairo_surface_t *s = cairo_image_surface_create_for_data(px, CAIRO_FORMAT_ARGB32, psize, psize, stride); cairo_t *ct = cairo_create(s); + cairo_translate(ct, -ua.x0, -ua.y0); nr_arena_item_invoke_render(ct, root, &ua, NULL, NR_ARENA_ITEM_RENDER_NO_CACHE ); -- cgit v1.2.3 From 2402528197627887e374dd2a4269dfdeb19acc58 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Wed, 15 Jun 2011 01:13:10 +0100 Subject: Clean up deprecated GTK_WIDGET API (bzr r10302.1.2) --- src/widgets/icon.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/widgets/icon.cpp') diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index c2634f6a1..b1d5c73bb 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -176,7 +176,7 @@ void IconImpl::classInit(SPIconClass *klass) void IconImpl::init(SPIcon *icon) { - GTK_WIDGET_FLAGS(icon) |= GTK_NO_WINDOW; + gtk_widget_set_has_window (GTK_WIDGET (icon), FALSE); icon->lsize = Inkscape::ICON_SIZE_BUTTON; icon->psize = 0; icon->name = 0; @@ -224,14 +224,14 @@ void IconImpl::sizeAllocate(GtkWidget *widget, GtkAllocation *allocation) { widget->allocation = *allocation; - if (GTK_WIDGET_DRAWABLE(widget)) { + if (gtk_widget_is_drawable(widget)) { gtk_widget_queue_draw(widget); } } int IconImpl::expose(GtkWidget *widget, GdkEventExpose *event) { - if ( GTK_WIDGET_DRAWABLE(widget) ) { + if ( gtk_widget_is_drawable(widget) ) { SPIcon *icon = SP_ICON(widget); if ( !icon->pb ) { fetchPixbuf( icon ); @@ -995,13 +995,13 @@ void IconImpl::paint(SPIcon *icon, GdkRectangle const */*area*/) bool unref_image = false; /* copied from the expose function of GtkImage */ - if (GTK_WIDGET_STATE (icon) != GTK_STATE_NORMAL && image) { + if (gtk_widget_get_state (GTK_WIDGET(icon)) != GTK_STATE_NORMAL && image) { GtkIconSource *source = gtk_icon_source_new(); gtk_icon_source_set_pixbuf(source, icon->pb); gtk_icon_source_set_size(source, GTK_ICON_SIZE_SMALL_TOOLBAR); // note: this is boilerplate and not used gtk_icon_source_set_size_wildcarded(source, FALSE); image = gtk_style_render_icon (widget.style, source, gtk_widget_get_direction(&widget), - (GtkStateType) GTK_WIDGET_STATE(&widget), (GtkIconSize)-1, &widget, "gtk-image"); + (GtkStateType) gtk_widget_get_state(&widget), (GtkIconSize)-1, &widget, "gtk-image"); gtk_icon_source_free(source); unref_image = true; } -- cgit v1.2.3 From ab143333746e25648b253f13c0539adff089b1b6 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Fri, 24 Jun 2011 00:22:07 +0200 Subject: Remove more of libnr (bzr r10347.1.2) --- src/widgets/icon.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/widgets/icon.cpp') diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 450c5f0d9..95cb23a22 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -23,6 +23,7 @@ #include #include #include +#include <2geom/transforms.h> #include "path-prefix.h" #include "preferences.h" -- cgit v1.2.3 From 2be2cf32db0668dc64512a98f6c2394152bd10cc Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 16 Jul 2011 00:42:39 -0700 Subject: Cleanup of oudated/redundant SP_ITEM() macro use. (bzr r10461) --- src/widgets/icon.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/widgets/icon.cpp') diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 95cb23a22..6110e6011 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -34,6 +34,7 @@ #include "display/nr-arena.h" #include "display/nr-arena-item.h" #include "io/sys.h" +#include "sp-root.h" #include "icon.h" @@ -1085,9 +1086,10 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, if (doc) { SPObject *object = doc->getObjectById(name); if (object && SP_IS_ITEM(object)) { - /* Find bbox in document */ - Geom::Affine const i2doc(SP_ITEM(object)->i2doc_affine()); - Geom::OptRect dbox = SP_ITEM(object)->getBounds(i2doc); + SPItem *item = SP_ITEM(object); + // Find bbox in document + Geom::Affine const i2doc(item->i2doc_affine()); + Geom::OptRect dbox = item->getBounds(i2doc); if ( object->parent == NULL ) { @@ -1294,7 +1296,7 @@ guchar *IconImpl::load_svg_pixels(std::list const &names, // fixme: Memory manage root if needed (Lauris) // This needs to be fixed indeed; this leads to a memory leak of a few megabytes these days // because shapes are being rendered which are not being freed - NRArenaItem *root = SP_ITEM(doc->getRoot())->invoke_show( arena, visionkey, SP_ITEM_SHOW_DISPLAY ); + NRArenaItem *root = doc->getRoot()->invoke_show( arena, visionkey, SP_ITEM_SHOW_DISPLAY ); // store into the cache info = new SVGDocCache(doc, root); -- cgit v1.2.3 From 328fad57dbfb65e3bd31062021d5cc3081e68515 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Fri, 22 Jul 2011 04:09:27 +0200 Subject: Replace direct use of Cairo contexts and surfaces in the rendering tree with wrappers which keep some extra information about the surface, amd NRRect and NRRectL use with Geom::Rect and Geom::IntRect. Should simplify implementing filter primitive subregions. (bzr r10347.1.17) --- src/widgets/icon.cpp | 66 +++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 34 deletions(-) (limited to 'src/widgets/icon.cpp') diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 95cb23a22..bb2029bcf 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -31,6 +31,7 @@ #include "document.h" #include "sp-item.h" #include "display/cairo-utils.h" +#include "display/drawing-context.h" #include "display/nr-arena.h" #include "display/nr-arena-item.h" #include "io/sys.h" @@ -1073,6 +1074,19 @@ GdkPixbuf *IconImpl::loadPixmap(gchar const *name, unsigned /*lsize*/, unsigned return pb; } +static Geom::IntRect round_rect(Geom::Rect const &r) +{ + using Geom::X; + using Geom::Y; + Geom::IntPoint a, b; + a[X] = round(r.left()); + a[Y] = round(r.top()); + b[X] = round(r.right()); + b[Y] = round(r.bottom()); + Geom::IntRect ret(a, b); + return ret; +} + // takes doc, root, icon, and icon name to produce pixels extern "C" guchar * sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, @@ -1102,23 +1116,20 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, double sf = 1.0; nr_arena_item_set_transform(root, (Geom::Affine)Geom::Scale(sf, sf)); gc.transform.setIdentity(); - nr_arena_item_invoke_update( root, NULL, &gc, + nr_arena_item_invoke_update( root, Geom::IntRect::infinite(), &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE ); /* Item integer bbox in points */ - NRRectL ibox; - ibox.x0 = (int) floor(sf * dbox->min()[Geom::X] + 0.5); - ibox.y0 = (int) floor(sf * dbox->min()[Geom::Y] + 0.5); - ibox.x1 = (int) floor(sf * dbox->max()[Geom::X] + 0.5); - ibox.y1 = (int) floor(sf * dbox->max()[Geom::Y] + 0.5); + // NOTE: previously, each rect coordinate was rounded using floor(c + 0.5) + Geom::IntRect ibox = round_rect(*dbox); if ( dump ) { - g_message( " box --'%s' (%f,%f)-(%f,%f)", name, (double)ibox.x0, (double)ibox.y0, (double)ibox.x1, (double)ibox.y1 ); + g_message( " box --'%s' (%f,%f)-(%f,%f)", name, (double)ibox.left(), (double)ibox.top(), (double)ibox.right(), (double)ibox.bottom() ); } /* Find button visible area */ - int width = ibox.x1 - ibox.x0; - int height = ibox.y1 - ibox.y0; + int width = ibox.width(); + int height = ibox.height(); if ( dump ) { g_message( " vis --'%s' (%d,%d)", name, width, height ); @@ -1134,49 +1145,38 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, nr_arena_item_set_transform(root, (Geom::Affine)Geom::Scale(sf, sf)); gc.transform.setIdentity(); - nr_arena_item_invoke_update( root, NULL, &gc, + nr_arena_item_invoke_update( root, Geom::IntRect::infinite(), &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE ); - /* Item integer bbox in points */ - ibox.x0 = (int) floor(sf * dbox->min()[Geom::X] + 0.5); - ibox.y0 = (int) floor(sf * dbox->min()[Geom::Y] + 0.5); - ibox.x1 = (int) floor(sf * dbox->max()[Geom::X] + 0.5); - ibox.y1 = (int) floor(sf * dbox->max()[Geom::Y] + 0.5); + ibox = round_rect(*dbox * Geom::Scale(sf)); if ( dump ) { - g_message( " box2 --'%s' (%f,%f)-(%f,%f)", name, (double)ibox.x0, (double)ibox.y0, (double)ibox.x1, (double)ibox.y1 ); + g_message( " box2 --'%s' (%f,%f)-(%f,%f)", name, (double)ibox.left(), (double)ibox.top(), (double)ibox.right(), (double)ibox.bottom() ); } /* Find button visible area */ - width = ibox.x1 - ibox.x0; - height = ibox.y1 - ibox.y0; + width = ibox.width(); + height = ibox.height(); if ( dump ) { g_message( " vis2 --'%s' (%d,%d)", name, width, height ); } } } + Geom::IntPoint pdim(psize, psize); int dx, dy; //dx = (psize - width) / 2; //dy = (psize - height) / 2; dx=dy=psize; dx=(dx-width)/2; // watch out for psize, 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), pdim); /* Actual renderable area */ - NRRectL ua; - ua.x0 = MAX(ibox.x0, area.x0); - ua.y0 = MAX(ibox.y0, area.y0); - ua.x1 = MIN(ibox.x1, area.x1); - ua.y1 = MIN(ibox.y1, area.y1); + Geom::IntRect ua = *Geom::intersect(ibox, area); if ( dump ) { - g_message( " area --'%s' (%f,%f)-(%f,%f)", name, (double)area.x0, (double)area.y0, (double)area.x1, (double)area.y1 ); - g_message( " ua --'%s' (%f,%f)-(%f,%f)", name, (double)ua.x0, (double)ua.y0, (double)ua.x1, (double)ua.y1 ); + g_message( " area --'%s' (%f,%f)-(%f,%f)", name, (double)area.left(), (double)area.top(), (double)area.right(), (double)area.bottom() ); + g_message( " ua --'%s' (%f,%f)-(%f,%f)", name, (double)ua.left(), (double)ua.top(), (double)ua.right(), (double)ua.bottom() ); } stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, psize); @@ -1188,12 +1188,10 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, /* Render */ cairo_surface_t *s = cairo_image_surface_create_for_data(px, CAIRO_FORMAT_ARGB32, psize, psize, stride); - cairo_t *ct = cairo_create(s); - cairo_translate(ct, -ua.x0, -ua.y0); + Inkscape::DrawingContext ct(s, ua.min()); - nr_arena_item_invoke_render(ct, root, &ua, NULL, + nr_arena_item_invoke_render(ct, root, ua, NR_ARENA_ITEM_RENDER_NO_CACHE ); - cairo_destroy(ct); cairo_surface_destroy(s); // convert to GdkPixbuf format -- cgit v1.2.3 From 4dd33aa4d5c57706c7f64f63391174954160a308 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 6 Aug 2011 14:18:32 +0200 Subject: Rewrite NRArenaItem hierarchy into C++ (bzr r10347.1.21) --- src/widgets/icon.cpp | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'src/widgets/icon.cpp') diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index c6823e2d8..fea825444 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -32,8 +32,8 @@ #include "sp-item.h" #include "display/cairo-utils.h" #include "display/drawing-context.h" +#include "display/drawing-item.h" #include "display/nr-arena.h" -#include "display/nr-arena-item.h" #include "io/sys.h" #include "sp-root.h" @@ -1090,7 +1090,7 @@ static Geom::IntRect round_rect(Geom::Rect const &r) // takes doc, root, icon, and icon name to produce pixels extern "C" guchar * -sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, +sp_icon_doc_icon( SPDocument *doc, Inkscape::DrawingItem *root, gchar const *name, unsigned psize, unsigned &stride) { @@ -1113,14 +1113,10 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, /* This is in document coordinates, i.e. pixels */ if ( dbox ) { - NRGC gc(NULL); /* Update to renderable state */ double sf = 1.0; - nr_arena_item_set_transform(root, (Geom::Affine)Geom::Scale(sf, sf)); - gc.transform.setIdentity(); - nr_arena_item_invoke_update( root, Geom::IntRect::infinite(), &gc, - NR_ARENA_ITEM_STATE_ALL, - NR_ARENA_ITEM_STATE_NONE ); + root->setTransform(Geom::Scale(sf)); + root->update(); /* Item integer bbox in points */ // NOTE: previously, each rect coordinate was rounded using floor(c + 0.5) Geom::IntRect ibox = round_rect(*dbox); @@ -1145,11 +1141,8 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, } sf = (double)psize / (double)block; - nr_arena_item_set_transform(root, (Geom::Affine)Geom::Scale(sf, sf)); - gc.transform.setIdentity(); - nr_arena_item_invoke_update( root, Geom::IntRect::infinite(), &gc, - NR_ARENA_ITEM_STATE_ALL, - NR_ARENA_ITEM_STATE_NONE ); + root->setTransform(Geom::Scale(sf)); + root->update(); ibox = round_rect(*dbox * Geom::Scale(sf)); if ( dump ) { @@ -1192,8 +1185,7 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, CAIRO_FORMAT_ARGB32, psize, psize, stride); Inkscape::DrawingContext ct(s, ua.min()); - nr_arena_item_invoke_render(ct, root, ua, - NR_ARENA_ITEM_RENDER_NO_CACHE ); + root->render(ct, ua, Inkscape::DrawingItem::RENDER_BYPASS_CACHE); cairo_surface_destroy(s); // convert to GdkPixbuf format @@ -1214,9 +1206,9 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, class SVGDocCache { public: - SVGDocCache( SPDocument *doc, NRArenaItem *root ) : doc(doc), root(root) {} + SVGDocCache( SPDocument *doc, Inkscape::DrawingItem *root ) : doc(doc), root(root) {} SPDocument *doc; - NRArenaItem *root; + Inkscape::DrawingItem *root; }; static std::map doc_cache; @@ -1294,7 +1286,7 @@ guchar *IconImpl::load_svg_pixels(std::list const &names, // fixme: Memory manage root if needed (Lauris) // This needs to be fixed indeed; this leads to a memory leak of a few megabytes these days // because shapes are being rendered which are not being freed - NRArenaItem *root = doc->getRoot()->invoke_show( arena, visionkey, SP_ITEM_SHOW_DISPLAY ); + Inkscape::DrawingItem *root = doc->getRoot()->invoke_show( arena, visionkey, SP_ITEM_SHOW_DISPLAY ); // store into the cache info = new SVGDocCache(doc, root); -- cgit v1.2.3 From 75976ea07dba9b97186667524d0a76603de416af Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sun, 7 Aug 2011 12:53:12 +0200 Subject: Rewrite NRArena -> Inkscape::Drawing. Call render and update methods on the Drawing rather than on the root DrawingItem. (bzr r10347.1.25) --- src/widgets/icon.cpp | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'src/widgets/icon.cpp') diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index fea825444..a57b56b5c 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -33,7 +33,7 @@ #include "display/cairo-utils.h" #include "display/drawing-context.h" #include "display/drawing-item.h" -#include "display/nr-arena.h" +#include "display/drawing.h" #include "io/sys.h" #include "sp-root.h" @@ -1088,9 +1088,9 @@ static Geom::IntRect round_rect(Geom::Rect const &r) return ret; } -// takes doc, root, icon, and icon name to produce pixels +// takes doc, drawing, icon, and icon name to produce pixels extern "C" guchar * -sp_icon_doc_icon( SPDocument *doc, Inkscape::DrawingItem *root, +sp_icon_doc_icon( SPDocument *doc, Inkscape::Drawing &drawing, gchar const *name, unsigned psize, unsigned &stride) { @@ -1115,8 +1115,8 @@ sp_icon_doc_icon( SPDocument *doc, Inkscape::DrawingItem *root, if ( dbox ) { /* Update to renderable state */ double sf = 1.0; - root->setTransform(Geom::Scale(sf)); - root->update(); + drawing.root()->setTransform(Geom::Scale(sf)); + drawing.update(); /* Item integer bbox in points */ // NOTE: previously, each rect coordinate was rounded using floor(c + 0.5) Geom::IntRect ibox = round_rect(*dbox); @@ -1141,8 +1141,8 @@ sp_icon_doc_icon( SPDocument *doc, Inkscape::DrawingItem *root, } sf = (double)psize / (double)block; - root->setTransform(Geom::Scale(sf)); - root->update(); + drawing.root()->setTransform(Geom::Scale(sf)); + drawing.update(); ibox = round_rect(*dbox * Geom::Scale(sf)); if ( dump ) { @@ -1185,7 +1185,7 @@ sp_icon_doc_icon( SPDocument *doc, Inkscape::DrawingItem *root, CAIRO_FORMAT_ARGB32, psize, psize, stride); Inkscape::DrawingContext ct(s, ua.min()); - root->render(ct, ua, Inkscape::DrawingItem::RENDER_BYPASS_CACHE); + drawing.render(ct, ua); cairo_surface_destroy(s); // convert to GdkPixbuf format @@ -1206,9 +1206,21 @@ sp_icon_doc_icon( SPDocument *doc, Inkscape::DrawingItem *root, class SVGDocCache { public: - SVGDocCache( SPDocument *doc, Inkscape::DrawingItem *root ) : doc(doc), root(root) {} + SVGDocCache( SPDocument *doc ) + : doc(doc) + , visionkey(SPItem::display_key_new(1)) + { + doc->doRef(); + doc->ensureUpToDate(); + drawing.setRoot(doc->getRoot()->invoke_show(drawing, visionkey, SP_ITEM_SHOW_DISPLAY )); + } + ~SVGDocCache() { + doc->getRoot()->invoke_hide(visionkey); + doc->doUnref(); + } SPDocument *doc; - Inkscape::DrawingItem *root; + Inkscape::Drawing drawing; + unsigned visionkey; }; static std::map doc_cache; @@ -1275,27 +1287,14 @@ guchar *IconImpl::load_svg_pixels(std::list const &names, if ( dump ) { g_message("Loaded icon file %s", doc_filename); } - // prep the document - doc->ensureUpToDate(); - - // Create new arena - NRArena *arena = NRArena::create(); - - // Create ArenaItem and set transform - unsigned visionkey = SPItem::display_key_new(1); - // fixme: Memory manage root if needed (Lauris) - // This needs to be fixed indeed; this leads to a memory leak of a few megabytes these days - // because shapes are being rendered which are not being freed - Inkscape::DrawingItem *root = doc->getRoot()->invoke_show( arena, visionkey, SP_ITEM_SHOW_DISPLAY ); - // store into the cache - info = new SVGDocCache(doc, root); + info = new SVGDocCache(doc); doc_cache[key] = info; } } if (info) { for (std::list::const_iterator it = names.begin(); !px && (it != names.end()); ++it ) { - px = sp_icon_doc_icon( info->doc, info->root, it->c_str(), psize, stride ); + px = sp_icon_doc_icon( info->doc, info->drawing, it->c_str(), psize, stride ); } } } -- cgit v1.2.3 From 72cc39b9f0b340548f395c7f61ca9662b34aea09 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 27 Aug 2011 11:04:37 +0200 Subject: Refactor SPItem bounding box methods: remove NRRect usage and make code using them more obvious. Fix filter region computation. (bzr r10582.1.1) --- src/widgets/icon.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/widgets/icon.cpp') diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index a57b56b5c..9540b59d6 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -1102,8 +1102,7 @@ sp_icon_doc_icon( SPDocument *doc, Inkscape::Drawing &drawing, if (object && SP_IS_ITEM(object)) { SPItem *item = SP_ITEM(object); // Find bbox in document - Geom::Affine const i2doc(item->i2doc_affine()); - Geom::OptRect dbox = item->getBounds(i2doc); + Geom::OptRect dbox = item->documentVisualBounds(); if ( object->parent == NULL ) { -- cgit v1.2.3 From 4e51446f417ad82d2cdac758d0c5ce908ff88038 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Thu, 8 Dec 2011 11:53:54 +0000 Subject: Switch to top-level glib headers. Thanks to DimStar for patch Fixed bugs: - https://launchpad.net/bugs/898538 (bzr r10762) --- src/widgets/icon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets/icon.cpp') diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 9540b59d6..09caaa7f1 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -17,7 +17,7 @@ #endif #include -#include +#include #include #include #include -- cgit v1.2.3