Code

Filtering now works with text and image objects
authorkiirala <kiirala@users.sourceforge.net>
Tue, 10 Oct 2006 22:00:49 +0000 (22:00 +0000)
committerkiirala <kiirala@users.sourceforge.net>
Tue, 10 Oct 2006 22:00:49 +0000 (22:00 +0000)
src/display/nr-arena-image.cpp
src/display/nr-arena-image.h
src/sp-image.cpp
src/sp-text.cpp

index ee566d2dceb90a8b0a749c857ddd017a36090d95..39e33c7711b07f40bc418ed77cc99e8f7e46d3dc 100644 (file)
 #include <libnr/nr-compose-transform.h>
 #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; i<style->filter.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;
+  }
+}
index 8c5afc55f4cbd6d2c81ee683f0e4272102bb2ccb..60485ea33ef984236dc66e0cfdcefed24f8e814e 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <libnr/nr-matrix.h>
 #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<NRArenaImage *>(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
index 5804089e687cf9efc1ef658cb01ab2274c574c73..301c6f8d50c9edf50d6ddc15715d2b12c91bfc90 100644 (file)
@@ -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),
index c9811ec6e18420d291de0efbd875a55beaadf6ef..3059cf22d9aaf16b599360e16eff94ccf7d19ef1 100644 (file)
@@ -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);
         }
     }