From: bryce Date: Tue, 20 Feb 2007 06:01:42 +0000 (+0000) Subject: Partial fix for bug 980157. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=30e67e5cf0256bb30d02f301cd119615503bbfa5;p=inkscape.git Partial fix for bug 980157. This commit disables the code that prevents stock markers from appearing at the top of the marker menu, as discussed in the bug report. Additionally, this patch factors out the pixmap rendering code, which is nearly identical to the rendering code in icon.cpp (and perhaps elsewhere). --- diff --git a/src/dialogs/stroke-style.cpp b/src/dialogs/stroke-style.cpp index 3db6c62ee..bab57b679 100644 --- a/src/dialogs/stroke-style.cpp +++ b/src/dialogs/stroke-style.cpp @@ -35,9 +35,9 @@ #include "sp-linear-gradient.h" #include "sp-radial-gradient.h" #include "marker.h" -#include -#include -#include +#include "sp-pattern.h" +#include "widgets/paint-selector.h" +#include "widgets/dash-selector.h" #include "style.h" #include "gradient-chemistry.h" #include "sp-namedview.h" @@ -56,9 +56,11 @@ #include "widgets/icon.h" #include "helper/stock-items.h" #include "io/sys.h" +#include "ui/cache/svg_preview_cache.h" #include "dialogs/stroke-style.h" + /* Paint */ static void sp_stroke_style_paint_construct(SPWidget *spw, SPPaintSelector *psel); @@ -550,7 +552,7 @@ sp_stroke_radio_button(GtkWidget *tb, char const *icon, * preview images of each marker in the marker menu. */ static GtkWidget * -sp_marker_prev_new(unsigned size, gchar const *mname, +sp_marker_prev_new(unsigned psize, gchar const *mname, SPDocument *source, SPDocument *sandbox, gchar *menu_id, NRArena const *arena, unsigned visionkey, NRArenaItem *root) { @@ -594,66 +596,12 @@ sp_marker_prev_new(unsigned size, gchar const *mname, } /* Update to renderable state */ - NRMatrix t; double sf = 0.8; - nr_matrix_set_scale(&t, sf, sf); - nr_arena_item_set_transform(root, &t); - NRGC gc(NULL); - 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(sf * dbox.min()[NR::X] + 0.5); - ibox.y0 = (int) floor(sf * dbox.min()[NR::Y] + 0.5); - ibox.x1 = (int) floor(sf * dbox.max()[NR::X] + 0.5); - ibox.y1 = (int) floor(sf * dbox.max()[NR::Y] + 0.5); - - /* Find visible area */ - int width = ibox.x1 - ibox.x0; - int height = ibox.y1 - ibox.y0; - int dx = size; - int dy = size; - 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 + size; - area.y1 = area.y0 + size; - - /* 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); - - /* Set up pixblock */ - guchar *px = g_new(guchar, 4 * size * size); - memset(px, 0x00, 4 * size * size); - - /* Render */ - NRPixBlock B; - nr_pixblock_setup_extern( &B, NR_PIXBLOCK_MODE_R8G8B8A8N, - ua.x0, ua.y0, ua.x1, ua.y1, - px + 4 * size * (ua.y0 - area.y0) + - 4 * (ua.x0 - area.x0), - 4 * size, FALSE, FALSE ); - nr_arena_item_invoke_render( root, &ua, &B, - NR_ARENA_ITEM_RENDER_NO_CACHE ); - nr_pixblock_release(&B); + GdkPixbuf* pixbuf = render_pixbuf(root, sf, dbox, psize); // Create widget - GtkWidget *pb = gtk_image_new_from_pixbuf(gdk_pixbuf_new_from_data(px, - GDK_COLORSPACE_RGB, - TRUE, - 8, size, size, size * 4, - (GdkPixbufDestroyNotify)g_free, - NULL)); + GtkWidget *pb = gtk_image_new_from_pixbuf(get_pixbuf(pixbuf)); + return pb; } @@ -753,6 +701,10 @@ sp_marker_list_from_doc (GtkWidget *m, SPDocument *current_doc, SPDocument *sour if (!SP_IS_MARKER(ml->data)) continue; +/* + Bug 980157 wants to have stock markers show up at the top of the dropdown menu + Thus we can skip all of this code, which simply looks for duplicate stock markers + Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) ml->data); bool stock_dupe = false; @@ -767,6 +719,7 @@ sp_marker_list_from_doc (GtkWidget *m, SPDocument *current_doc, SPDocument *sour if (stock_dupe) // stock item, dont add to list from current doc continue; +*/ // Add to the list of markers we really do wish to show clean_ml = g_slist_prepend (clean_ml, ml->data); diff --git a/src/ui/cache/svg_preview_cache.h b/src/ui/cache/svg_preview_cache.h new file mode 100644 index 000000000..7b802fee3 --- /dev/null +++ b/src/ui/cache/svg_preview_cache.h @@ -0,0 +1,78 @@ +/** \file + * SPIcon: Generic icon widget + */ +/* + * Copyright (C) 2007 Bryce W. Harrington + * + * Released under GNU GPL, read the file 'COPYING' for more information + * + */ + +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; +}