diff options
Diffstat (limited to 'src/sp-filter.cpp')
| -rw-r--r-- | src/sp-filter.cpp | 176 |
1 files changed, 78 insertions, 98 deletions
diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index 2a566efa2..91389bf7d 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -51,7 +51,12 @@ namespace { bool filterRegistered = SPFactory::instance().registerObject("svg:filter", createFilter); } -SPFilter::SPFilter() : SPObject() { +SPFilter::SPFilter() + : SPObject(), filterUnits(SP_FILTER_UNITS_OBJECTBOUNDINGBOX), filterUnits_set(FALSE), + primitiveUnits(SP_FILTER_UNITS_USERSPACEONUSE), primitiveUnits_set(FALSE), + filterRes(NumberOptNumber()), + _renderer(NULL), _image_name(new std::map<gchar *, int, ltstr>), _image_number_next(0) +{ this->href = new SPFilterReference(this); this->href->changedSignal().connect(sigc::bind(sigc::ptr_fun(filter_ref_changed), this)); @@ -60,20 +65,7 @@ SPFilter::SPFilter() : SPObject() { this->width = 0; this->height = 0; - this->filterUnits = SP_FILTER_UNITS_OBJECTBOUNDINGBOX; - this->primitiveUnits = SP_FILTER_UNITS_USERSPACEONUSE; - this->filterUnits_set = FALSE; - this->primitiveUnits_set = FALSE; - - this->_renderer = NULL; - - this->_image_name = new std::map<gchar *, int, ltstr>; this->_image_name->clear(); - this->_image_number_next = 0; - - this->filterRes = NumberOptNumber(); - - new (&this->modified_connection) sigc::connection(); } SPFilter::~SPFilter() { @@ -86,49 +78,43 @@ SPFilter::~SPFilter() { * sp-object-repr.cpp's repr_name_entries array. */ void SPFilter::build(SPDocument *document, Inkscape::XML::Node *repr) { - SPFilter* object = this; - //Read values of key attributes from XML nodes into object. - object->readAttr( "style" ); // struct not derived from SPItem, we need to do this ourselves. - object->readAttr( "filterUnits" ); - object->readAttr( "primitiveUnits" ); - object->readAttr( "x" ); - object->readAttr( "y" ); - object->readAttr( "width" ); - object->readAttr( "height" ); - object->readAttr( "filterRes" ); - object->readAttr( "xlink:href" ); + this->readAttr( "style" ); // struct not derived from SPItem, we need to do this ourselves. + this->readAttr( "filterUnits" ); + this->readAttr( "primitiveUnits" ); + this->readAttr( "x" ); + this->readAttr( "y" ); + this->readAttr( "width" ); + this->readAttr( "height" ); + this->readAttr( "filterRes" ); + this->readAttr( "xlink:href" ); SPObject::build(document, repr); //is this necessary? - document->addResource("filter", object); + document->addResource("filter", this); } /** * Drops any allocated memory. */ void SPFilter::release() { - SPFilter* object = this; - SPFilter *filter = SP_FILTER(object); - - if (object->document) { + if (this->document) { // Unregister ourselves - object->document->removeResource("filter", object); + this->document->removeResource("filter", this); } //TODO: release resources here //release href - if (filter->href) { - filter->modified_connection.disconnect(); - filter->href->detach(); - delete filter->href; - filter->href = NULL; + if (this->href) { + this->modified_connection.disconnect(); + this->href->detach(); + delete this->href; + this->href = NULL; } - filter->modified_connection.~connection(); - delete filter->_image_name; + delete this->_image_name; SPObject::release(); } @@ -137,68 +123,69 @@ void SPFilter::release() { * Sets a specific value in the SPFilter. */ void SPFilter::set(unsigned int key, gchar const *value) { - SPFilter* object = this; - SPFilter *filter = SP_FILTER(object); - switch (key) { case SP_ATTR_FILTERUNITS: if (value) { if (!strcmp(value, "userSpaceOnUse")) { - filter->filterUnits = SP_FILTER_UNITS_USERSPACEONUSE; + this->filterUnits = SP_FILTER_UNITS_USERSPACEONUSE; } else { - filter->filterUnits = SP_FILTER_UNITS_OBJECTBOUNDINGBOX; + this->filterUnits = SP_FILTER_UNITS_OBJECTBOUNDINGBOX; } - filter->filterUnits_set = TRUE; + + this->filterUnits_set = TRUE; } else { - filter->filterUnits = SP_FILTER_UNITS_OBJECTBOUNDINGBOX; - filter->filterUnits_set = FALSE; + this->filterUnits = SP_FILTER_UNITS_OBJECTBOUNDINGBOX; + this->filterUnits_set = FALSE; } - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + + this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_PRIMITIVEUNITS: if (value) { if (!strcmp(value, "objectBoundingBox")) { - filter->primitiveUnits = SP_FILTER_UNITS_OBJECTBOUNDINGBOX; + this->primitiveUnits = SP_FILTER_UNITS_OBJECTBOUNDINGBOX; } else { - filter->primitiveUnits = SP_FILTER_UNITS_USERSPACEONUSE; + this->primitiveUnits = SP_FILTER_UNITS_USERSPACEONUSE; } - filter->primitiveUnits_set = TRUE; + + this->primitiveUnits_set = TRUE; } else { - filter->primitiveUnits = SP_FILTER_UNITS_USERSPACEONUSE; - filter->primitiveUnits_set = FALSE; + this->primitiveUnits = SP_FILTER_UNITS_USERSPACEONUSE; + this->primitiveUnits_set = FALSE; } - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + + this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_X: - filter->x.readOrUnset(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->x.readOrUnset(value); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_Y: - filter->y.readOrUnset(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->y.readOrUnset(value); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_WIDTH: - filter->width.readOrUnset(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->width.readOrUnset(value); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_HEIGHT: - filter->height.readOrUnset(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->height.readOrUnset(value); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_FILTERRES: - filter->filterRes.set(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->filterRes.set(value); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_XLINK_HREF: if (value) { try { - filter->href->attach(Inkscape::URI(value)); + this->href->attach(Inkscape::URI(value)); } catch (Inkscape::BadURIException &e) { g_warning("%s", e.what()); - filter->href->detach(); + this->href->detach(); } } else { - filter->href->detach(); + this->href->detach(); } break; default: @@ -212,8 +199,6 @@ void SPFilter::set(unsigned int key, gchar const *value) { * Receives update notifications. */ void SPFilter::update(SPCtx *ctx, guint flags) { - //SPFilter *filter = SP_FILTER(object); - if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { @@ -228,34 +213,34 @@ void SPFilter::update(SPCtx *ctx, guint flags) { * Writes its settings to an incoming repr object, if any. */ Inkscape::XML::Node* SPFilter::write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) { - SPFilter* object = this; - SPFilter *filter = SP_FILTER(object); - // Original from sp-item-group.cpp if (flags & SP_OBJECT_WRITE_BUILD) { if (!repr) { - repr = doc->createElement("svg:filter"); + repr = doc->createElement("svg:this"); } + GSList *l = NULL; - for ( SPObject *child = object->firstChild(); child; child = child->getNext() ) { + for ( SPObject *child = this->firstChild(); child; child = child->getNext() ) { Inkscape::XML::Node *crepr = child->updateRepr(doc, NULL, flags); + if (crepr) { l = g_slist_prepend (l, crepr); } } + while (l) { repr->addChild((Inkscape::XML::Node *) l->data, NULL); Inkscape::GC::release((Inkscape::XML::Node *) l->data); l = g_slist_remove (l, l->data); } } else { - for ( SPObject *child = object->firstChild() ; child; child = child->getNext() ) { + for ( SPObject *child = this->firstChild() ; child; child = child->getNext() ) { child->updateRepr(flags); } } - if ((flags & SP_OBJECT_WRITE_ALL) || filter->filterUnits_set) { - switch (filter->filterUnits) { + if ((flags & SP_OBJECT_WRITE_ALL) || this->filterUnits_set) { + switch (this->filterUnits) { case SP_FILTER_UNITS_USERSPACEONUSE: repr->setAttribute("filterUnits", "userSpaceOnUse"); break; @@ -265,8 +250,8 @@ Inkscape::XML::Node* SPFilter::write(Inkscape::XML::Document *doc, Inkscape::XML } } - if ((flags & SP_OBJECT_WRITE_ALL) || filter->primitiveUnits_set) { - switch (filter->primitiveUnits) { + if ((flags & SP_OBJECT_WRITE_ALL) || this->primitiveUnits_set) { + switch (this->primitiveUnits) { case SP_FILTER_UNITS_OBJECTBOUNDINGBOX: repr->setAttribute("primitiveUnits", "objectBoundingBox"); break; @@ -276,40 +261,40 @@ Inkscape::XML::Node* SPFilter::write(Inkscape::XML::Document *doc, Inkscape::XML } } - if (filter->x._set) { - sp_repr_set_svg_double(repr, "x", filter->x.computed); + if (this->x._set) { + sp_repr_set_svg_double(repr, "x", this->x.computed); } else { repr->setAttribute("x", NULL); } - if (filter->y._set) { - sp_repr_set_svg_double(repr, "y", filter->y.computed); + if (this->y._set) { + sp_repr_set_svg_double(repr, "y", this->y.computed); } else { repr->setAttribute("y", NULL); } - if (filter->width._set) { - sp_repr_set_svg_double(repr, "width", filter->width.computed); + if (this->width._set) { + sp_repr_set_svg_double(repr, "width", this->width.computed); } else { repr->setAttribute("width", NULL); } - if (filter->height._set) { - sp_repr_set_svg_double(repr, "height", filter->height.computed); + if (this->height._set) { + sp_repr_set_svg_double(repr, "height", this->height.computed); } else { repr->setAttribute("height", NULL); } - if (filter->filterRes.getNumber()>=0) { - gchar *tmp = filter->filterRes.getValueString(); + if (this->filterRes.getNumber()>=0) { + gchar *tmp = this->filterRes.getValueString(); repr->setAttribute("filterRes", tmp); g_free(tmp); } else { repr->setAttribute("filterRes", NULL); } - if (filter->href->getURI()) { - gchar *uri_string = filter->href->getURI()->toString(); + if (this->href->getURI()) { + gchar *uri_string = this->href->getURI()->toString(); repr->setAttribute("xlink:href", uri_string); g_free(uri_string); } @@ -329,6 +314,7 @@ filter_ref_changed(SPObject *old_ref, SPObject *ref, SPFilter *filter) if (old_ref) { filter->modified_connection.disconnect(); } + if ( SP_IS_FILTER(ref) && ref != filter ) { @@ -348,24 +334,18 @@ static void filter_ref_modified(SPObject */*href*/, guint /*flags*/, SPFilter *f * Callback for child_added event. */ void SPFilter::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { - SPFilter* object = this; - //SPFilter *f = SP_FILTER(object); - SPObject::child_added(child, ref); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); } /** * Callback for remove_child event. */ void SPFilter::remove_child(Inkscape::XML::Node *child) { - SPFilter* object = this; - // SPFilter *f = SP_FILTER(object); - SPObject::remove_child(child); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); } void sp_filter_build_renderer(SPFilter *sp_filter, Inkscape::Filters::Filter *nr_filter) |
