From: jucablues Date: Mon, 5 Nov 2007 07:00:34 +0000 (+0000) Subject: partially implemented xlink:href parameter loading. (It still just X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2a5174dfcab08a69683845404fd928c60607a581;p=inkscape.git partially implemented xlink:href parameter loading. (It still just works for filenames.) Removed a hardcoded string. This part of the code must be improved in order to reference other pieces of SVG. I need somebody to help me on working with proper URI handling! Also fixed gdk pixbuf handling. --- diff --git a/src/display/nr-filter-image.cpp b/src/display/nr-filter-image.cpp index b8abb0317..d96d2013b 100644 --- a/src/display/nr-filter-image.cpp +++ b/src/display/nr-filter-image.cpp @@ -17,12 +17,8 @@ namespace NR { FilterImage::FilterImage() { -// Testing with hardcoded xlink:href : - image = Gdk::Pixbuf::create_from_file("../images/image1.jpg"); - //TODO: handle errors - width = image->get_width()+1; - height = image->get_height()+1; - image_pixbuf = image->get_pixels(); + feImageHref=NULL; + image_pixbuf=NULL; } FilterPrimitive * FilterImage::create() { @@ -30,9 +26,21 @@ FilterPrimitive * FilterImage::create() { } FilterImage::~FilterImage() -{} +{ + if (feImageHref) g_free(feImageHref); + if (image_pixbuf) g_free(image_pixbuf); +} int FilterImage::render(FilterSlot &slot, FilterUnits const &units) { + if (!feImageHref) return 0; + + if (!image_pixbuf){ + if ( (image = Gdk::Pixbuf::create_from_file(feImageHref)) < 0 ) return 0; + width = image->get_width(); + height = image->get_height(); + rowstride = image->get_rowstride(); + image_pixbuf = image->get_pixels(); + } int w,x,y; NRPixBlock *in = slot.get(_input); NRPixBlock *out = new NRPixBlock; @@ -56,9 +64,9 @@ int FilterImage::render(FilterSlot &slot, FilterUnits const &units) { coordy = int((y - feImageY - bbox_y0)*scaleY); if (coordx > 0 && coordx < width && coordy > 0 && coordy < height){ - out_data[4*((x - x0)+w*(y - y0))] = (unsigned char) image_pixbuf[3*(coordx + width*coordy)]; //Red - out_data[4*((x - x0)+w*(y - y0)) + 1] = (unsigned char) image_pixbuf[3*(coordx + width*coordy) + 1]; //Green - out_data[4*((x - x0)+w*(y - y0)) + 2] = (unsigned char) image_pixbuf[3*(coordx + width*coordy) + 2]; //Blue + out_data[4*((x - x0)+w*(y - y0))] = (unsigned char) image_pixbuf[3*coordx + rowstride*coordy]; //Red + out_data[4*((x - x0)+w*(y - y0)) + 1] = (unsigned char) image_pixbuf[3*coordx + rowstride*coordy + 1]; //Green + out_data[4*((x - x0)+w*(y - y0)) + 2] = (unsigned char) image_pixbuf[3*coordx + rowstride*coordy + 2]; //Blue out_data[4*((x - x0)+w*(y - y0)) + 3] = 255; //Alpha } } @@ -68,6 +76,12 @@ int FilterImage::render(FilterSlot &slot, FilterUnits const &units) { slot.set(_output, out); return 0; } + +void FilterImage::set_href(const gchar *href){ + if (feImageHref) g_free (feImageHref); + feImageHref = (href) ? g_strdup (href) : NULL; +} + void FilterImage::set_region(SVGLength x, SVGLength y, SVGLength width, SVGLength height){ feImageX=x.computed; feImageY=y.computed; diff --git a/src/display/nr-filter-image.h b/src/display/nr-filter-image.h index 9d4057826..47bfe157b 100644 --- a/src/display/nr-filter-image.h +++ b/src/display/nr-filter-image.h @@ -27,11 +27,13 @@ public: virtual int render(FilterSlot &slot, FilterUnits const &units); virtual FilterTraits get_input_traits(); + void set_href(const gchar *href); void set_region(SVGLength x, SVGLength y, SVGLength width, SVGLength height); private: + gchar *feImageHref; guint8* image_pixbuf; Glib::RefPtr image; - int width, height; + int width, height, rowstride; float feImageX,feImageY,feImageWidth,feImageHeight; }; diff --git a/src/sp-feimage.cpp b/src/sp-feimage.cpp index a36015180..9456b5966 100644 --- a/src/sp-feimage.cpp +++ b/src/sp-feimage.cpp @@ -98,14 +98,12 @@ sp_feImage_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *re } /*LOAD ATTRIBUTES FROM REPR HERE*/ -/* apparently there's no attribute to load here -since 'in' and 'xlink:href' are common filter attributes. ---Juca -*/ + sp_object_read_attr(object, "x"); sp_object_read_attr(object, "y"); sp_object_read_attr(object, "width"); sp_object_read_attr(object, "height"); + sp_object_read_attr(object, "xlink:href"); } @@ -131,6 +129,11 @@ sp_feImage_set(SPObject *object, unsigned int key, gchar const *value) switch(key) { /*DEAL WITH SETTING ATTRIBUTES HERE*/ + case SP_ATTR_XLINK_HREF: + if (feImage->href) g_free(feImage->href); + feImage->href = (value) ? g_strdup (value) : NULL; + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; case SP_ATTR_X: feImage->x.readOrUnset(value); object->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -209,6 +212,7 @@ static void sp_feImage_build_renderer(SPFilterPrimitive *primitive, NR::Filter * sp_filter_primitive_renderer_common(primitive, nr_primitive); nr_image->set_region(sp_image->x, sp_image->y, sp_image->width, sp_image->height); + nr_image->set_href(sp_image->href); } /* diff --git a/src/sp-feimage.h b/src/sp-feimage.h index 6786471ad..0c0289d6e 100644 --- a/src/sp-feimage.h +++ b/src/sp-feimage.h @@ -23,11 +23,7 @@ class SPFeImageClass; struct SPFeImage : public SPFilterPrimitive { /** IMAGE ATTRIBUTES HERE */ - /* - Apparently there's no attribute to keep here - since 'in' and 'xlink:href' are common filter attributes. - --Juca - */ + gchar *href; SVGLength x, y, height, width; };