From 4041c6f58df9361eb3df76e8ba737401cd9a3bcd Mon Sep 17 00:00:00 2001 From: kiirala Date: Tue, 10 Oct 2006 22:00:49 +0000 Subject: [PATCH] Filtering now works with text and image objects --- src/display/nr-arena-image.cpp | 57 ++++++++++++++++++++++++++++++++++ src/display/nr-arena-image.h | 4 +++ src/sp-image.cpp | 2 ++ src/sp-text.cpp | 2 ++ 4 files changed, 65 insertions(+) diff --git a/src/display/nr-arena-image.cpp b/src/display/nr-arena-image.cpp index ee566d2dc..39e33c771 100644 --- a/src/display/nr-arena-image.cpp +++ b/src/display/nr-arena-image.cpp @@ -15,6 +15,11 @@ #include #include "../prefs-utils.h" #include "nr-arena-image.h" +#include "style.h" +#include "display/nr-filter.h" +#include "display/nr-filter-gaussian.h" +#include "sp-filter.h" +#include "sp-gaussian-blur.h" int nr_arena_image_x_sample = 1; int nr_arena_image_y_sample = 1; @@ -79,6 +84,8 @@ nr_arena_image_init (NRArenaImage *image) image->height = 256.0; nr_matrix_set_identity (&image->grid2px); + + image->style = 0; } static void @@ -256,3 +263,53 @@ nr_arena_image_set_geometry (NRArenaImage *image, double x, double y, double wid nr_arena_item_request_update (NR_ARENA_ITEM (image), NR_ARENA_ITEM_STATE_ALL, FALSE); } +void nr_arena_image_set_style (NRArenaImage *image, SPStyle *style) +{ + g_return_if_fail(image != NULL); + g_return_if_fail(NR_IS_ARENA_IMAGE(image)); + + if (style) sp_style_ref(style); + if (image->style) sp_style_unref(image->style); + image->style = style; + + //if there is a filter set for this group + if (style && style->filter.set && style->filter.filter) { + + image->filter = new NR::Filter(); + image->filter->set_x(style->filter.filter->x); + image->filter->set_y(style->filter.filter->y); + image->filter->set_width(style->filter.filter->width); + image->filter->set_height(style->filter.filter->height); + + //go through all SP filter primitives + for(int i=0; ifilter.filter->_primitive_count; i++) + { + SPFilterPrimitive *primitive = style->filter.filter->_primitives[i]; + //if primitive is gaussianblur +// if(SP_IS_GAUSSIANBLUR(primitive)) + { + NR::FilterGaussian * gaussian = (NR::FilterGaussian *) image->filter->add_primitive(NR::NR_FILTER_GAUSSIANBLUR); + SPGaussianBlur * spblur = SP_GAUSSIANBLUR(primitive); + float num = spblur->stdDeviation.getNumber(); + if( num>=0.0 ) + { + float optnum = spblur->stdDeviation.getOptNumber(); + if( optnum>=0.0 ) + gaussian->set_deviation((double) num, (double) optnum); + else + gaussian->set_deviation((double) num); + } + } + } + } + else + { + //no filter set for this group + image->filter = NULL; + } + + if (style && style->enable_background.set + && style->enable_background.value == SP_CSS_BACKGROUND_NEW) { + image->background_new = true; + } +} diff --git a/src/display/nr-arena-image.h b/src/display/nr-arena-image.h index 8c5afc55f..60485ea33 100644 --- a/src/display/nr-arena-image.h +++ b/src/display/nr-arena-image.h @@ -19,6 +19,7 @@ #include #include "nr-arena-item.h" +#include "style.h" NRType nr_arena_image_get_type (void); @@ -34,6 +35,8 @@ struct NRArenaImage : public NRArenaItem { /* From GRID to PIXELS */ NR::Matrix grid2px; + SPStyle *style; + static NRArenaImage *create(NRArena *arena) { NRArenaImage *obj=reinterpret_cast(nr_object_new(NR_TYPE_ARENA_IMAGE)); obj->init(arena); @@ -47,5 +50,6 @@ struct NRArenaImageClass { void nr_arena_image_set_pixels (NRArenaImage *image, const unsigned char *px, unsigned int pxw, unsigned int pxh, unsigned int pxrs); void nr_arena_image_set_geometry (NRArenaImage *image, double x, double y, double width, double height); +void nr_arena_image_set_style (NRArenaImage *image, SPStyle *style); #endif diff --git a/src/sp-image.cpp b/src/sp-image.cpp index 5804089e6..301c6f8d5 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -996,6 +996,7 @@ sp_image_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flag if (image->pixbuf) { pixskip = gdk_pixbuf_get_n_channels (image->pixbuf) * gdk_pixbuf_get_bits_per_sample (image->pixbuf) / 8; rs = gdk_pixbuf_get_rowstride (image->pixbuf); + nr_arena_image_set_style(NR_ARENA_IMAGE(ai), SP_OBJECT_STYLE(SP_OBJECT(item))); if (image->aspect_align == SP_ASPECT_NONE) nr_arena_image_set_pixels (NR_ARENA_IMAGE (ai), gdk_pixbuf_get_pixels (image->pixbuf), @@ -1116,6 +1117,7 @@ sp_image_update_canvas_image (SPImage *image) for (v = item->display; v != NULL; v = v->next) { pixskip = gdk_pixbuf_get_n_channels (image->pixbuf) * gdk_pixbuf_get_bits_per_sample (image->pixbuf) / 8; rs = gdk_pixbuf_get_rowstride (image->pixbuf); + nr_arena_image_set_style (NR_ARENA_IMAGE(v->arenaitem), SP_OBJECT_STYLE(SP_OBJECT(image))); if (image->aspect_align == SP_ASPECT_NONE) { nr_arena_image_set_pixels (NR_ARENA_IMAGE (v->arenaitem), gdk_pixbuf_get_pixels (image->pixbuf), diff --git a/src/sp-text.cpp b/src/sp-text.cpp index c9811ec6e..3059cf22d 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -248,6 +248,7 @@ sp_text_update (SPObject *object, SPCtx *ctx, guint flags) sp_item_invoke_bbox(text, &paintbox, NR::identity(), TRUE); for (SPItemView* v = text->display; v != NULL; v = v->next) { text->_clearFlow(NR_ARENA_GROUP(v->arenaitem)); + nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), SP_OBJECT_STYLE(object)); // pass the bbox of the text object as paintbox (used for paintserver fills) text->layout.show(NR_ARENA_GROUP(v->arenaitem), &paintbox); } @@ -273,6 +274,7 @@ sp_text_modified (SPObject *object, guint flags) sp_item_invoke_bbox(text, &paintbox, NR::identity(), TRUE); for (SPItemView* v = text->display; v != NULL; v = v->next) { text->_clearFlow(NR_ARENA_GROUP(v->arenaitem)); + nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), SP_OBJECT_STYLE(object)); text->layout.show(NR_ARENA_GROUP(v->arenaitem), &paintbox); } } -- 2.30.2