diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-03-29 23:52:42 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-03-29 23:52:42 +0000 |
| commit | a168040d5a452544328a1e6ad35aaac351f94d44 (patch) | |
| tree | fae1ba829f543a473da281bd5fa6e4deabbf6912 /src/sp-filter.cpp | |
| parent | Removed function pointers from SPObject and subclasses. (diff) | |
| parent | Dutch translation update (diff) | |
| download | inkscape-a168040d5a452544328a1e6ad35aaac351f94d44.tar.gz inkscape-a168040d5a452544328a1e6ad35aaac351f94d44.zip | |
merged from trunk
(bzr r11608.1.56)
Diffstat (limited to 'src/sp-filter.cpp')
| -rw-r--r-- | src/sp-filter.cpp | 370 |
1 files changed, 7 insertions, 363 deletions
diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index 1af450c8b..01328adbe 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -22,6 +22,7 @@ using std::map; using std::pair; +#include <glibmm/stringutils.h> #include "attributes.h" #include "document.h" #include "sp-filter.h" @@ -37,62 +38,14 @@ using std::pair; #include "display/nr-filter.h" -/* Filter base class */ - -static void sp_filter_class_init(SPFilterClass *klass); -static void sp_filter_init(SPFilter *filter); - -static void sp_filter_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); -static void sp_filter_release(SPObject *object); -static void sp_filter_set(SPObject *object, unsigned int key, gchar const *value); -static void sp_filter_update(SPObject *object, SPCtx *ctx, guint flags); -static void sp_filter_child_added(SPObject *object, - Inkscape::XML::Node *child, - Inkscape::XML::Node *ref); -static void sp_filter_remove_child(SPObject *object, Inkscape::XML::Node *child); -static Inkscape::XML::Node *sp_filter_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); - static void filter_ref_changed(SPObject *old_ref, SPObject *ref, SPFilter *filter); static void filter_ref_modified(SPObject *href, guint flags, SPFilter *filter); -static SPObjectClass *filter_parent_class; - -GType -sp_filter_get_type() -{ - static GType filter_type = 0; - - if (!filter_type) { - GTypeInfo filter_info = { - sizeof(SPFilterClass), - NULL, NULL, - (GClassInitFunc) sp_filter_class_init, - NULL, NULL, - sizeof(SPFilter), - 16, - (GInstanceInitFunc) sp_filter_init, - NULL, /* value_table */ - }; - filter_type = g_type_register_static(SP_TYPE_OBJECT, "SPFilter", &filter_info, (GTypeFlags)0); - } - return filter_type; -} +G_DEFINE_TYPE(SPFilter, sp_filter, SP_TYPE_OBJECT); static void sp_filter_class_init(SPFilterClass *klass) { - - SPObjectClass *sp_object_class = (SPObjectClass *)klass; - - filter_parent_class = (SPObjectClass*)g_type_class_peek_parent(klass); - - //sp_object_class->build = sp_filter_build; -// sp_object_class->release = sp_filter_release; -// sp_object_class->write = sp_filter_write; -// sp_object_class->set = sp_filter_set; -// sp_object_class->update = sp_filter_update; -// sp_object_class->child_added = sp_filter_child_added; -// sp_object_class->remove_child = sp_filter_remove_child; } CFilter::CFilter(SPFilter* filter) : CObject(filter) { @@ -106,6 +59,8 @@ static void sp_filter_init(SPFilter *filter) { filter->cfilter = new CFilter(filter); + + delete filter->cobject; filter->cobject = filter->cfilter; filter->href = new SPFilterReference(filter); @@ -137,30 +92,11 @@ sp_filter_init(SPFilter *filter) * our name must be associated with a repr via "sp_object_type_register". Best done through * sp-object-repr.cpp's repr_name_entries array. */ -//static void -//sp_filter_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -//{ -// if (((SPObjectClass *) filter_parent_class)->build) { -// ((SPObjectClass *) filter_parent_class)->build(object, document, repr); -// } -// //Read values of key attributes from XML nodes into object. -// 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" ); -// -////is this necessary? -// document->addResource("filter", object); -//} - void CFilter::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { SPFilter* object = this->spfilter; //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" ); @@ -170,6 +106,8 @@ void CFilter::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { object->readAttr( "filterRes" ); object->readAttr( "xlink:href" ); + CObject::onBuild(document, repr); + //is this necessary? document->addResource("filter", object); } @@ -177,33 +115,6 @@ void CFilter::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { /** * Drops any allocated memory. */ -static void sp_filter_release(SPObject *object) -{ -// SPFilter *filter = SP_FILTER(object); -// -// if (object->document) { -// // Unregister ourselves -// object->document->removeResource("filter", object); -// } -// -////TODO: release resources here -// -// //release href -// if (filter->href) { -// filter->modified_connection.disconnect(); -// filter->href->detach(); -// delete filter->href; -// filter->href = NULL; -// } -// -// filter->modified_connection.~connection(); -// delete filter->_image_name; -// -// if (((SPObjectClass *) filter_parent_class)->release) -// ((SPObjectClass *) filter_parent_class)->release(object); - ((SPFilter*)object)->cfilter->onRelease(); -} - void CFilter::onRelease() { SPFilter* object = this->spfilter; SPFilter *filter = SP_FILTER(object); @@ -226,90 +137,12 @@ void CFilter::onRelease() { filter->modified_connection.~connection(); delete filter->_image_name; -// if (((SPObjectClass *) filter_parent_class)->release) -// ((SPObjectClass *) filter_parent_class)->release(object); CObject::onRelease(); } /** * Sets a specific value in the SPFilter. */ -static void -sp_filter_set(SPObject *object, unsigned int key, gchar const *value) -{ -// SPFilter *filter = SP_FILTER(object); -// -// switch (key) { -// case SP_ATTR_FILTERUNITS: -// if (value) { -// if (!strcmp(value, "userSpaceOnUse")) { -// filter->filterUnits = SP_FILTER_UNITS_USERSPACEONUSE; -// } else { -// filter->filterUnits = SP_FILTER_UNITS_OBJECTBOUNDINGBOX; -// } -// filter->filterUnits_set = TRUE; -// } else { -// filter->filterUnits = SP_FILTER_UNITS_OBJECTBOUNDINGBOX; -// filter->filterUnits_set = FALSE; -// } -// object->requestModified(SP_OBJECT_MODIFIED_FLAG); -// break; -// case SP_ATTR_PRIMITIVEUNITS: -// if (value) { -// if (!strcmp(value, "objectBoundingBox")) { -// filter->primitiveUnits = SP_FILTER_UNITS_OBJECTBOUNDINGBOX; -// } else { -// filter->primitiveUnits = SP_FILTER_UNITS_USERSPACEONUSE; -// } -// filter->primitiveUnits_set = TRUE; -// } else { -// filter->primitiveUnits = SP_FILTER_UNITS_USERSPACEONUSE; -// filter->primitiveUnits_set = FALSE; -// } -// object->requestModified(SP_OBJECT_MODIFIED_FLAG); -// break; -// case SP_ATTR_X: -// filter->x.readOrUnset(value); -// object->requestModified(SP_OBJECT_MODIFIED_FLAG); -// break; -// case SP_ATTR_Y: -// filter->y.readOrUnset(value); -// object->requestModified(SP_OBJECT_MODIFIED_FLAG); -// break; -// case SP_ATTR_WIDTH: -// filter->width.readOrUnset(value); -// object->requestModified(SP_OBJECT_MODIFIED_FLAG); -// break; -// case SP_ATTR_HEIGHT: -// filter->height.readOrUnset(value); -// object->requestModified(SP_OBJECT_MODIFIED_FLAG); -// break; -// case SP_ATTR_FILTERRES: -// filter->filterRes.set(value); -// object->requestModified(SP_OBJECT_MODIFIED_FLAG); -// break; -// case SP_ATTR_XLINK_HREF: -// if (value) { -// try { -// filter->href->attach(Inkscape::URI(value)); -// } catch (Inkscape::BadURIException &e) { -// g_warning("%s", e.what()); -// filter->href->detach(); -// } -// } else { -// filter->href->detach(); -// } -// break; -// default: -// // See if any parents need this value. -// if (((SPObjectClass *) filter_parent_class)->set) { -// ((SPObjectClass *) filter_parent_class)->set(object, key, value); -// } -// break; -// } - ((SPFilter*)object)->cfilter->onSet(key, value); -} - void CFilter::onSet(unsigned int key, gchar const *value) { SPFilter* object = this->spfilter; SPFilter *filter = SP_FILTER(object); @@ -377,9 +210,6 @@ void CFilter::onSet(unsigned int key, gchar const *value) { break; default: // See if any parents need this value. -// if (((SPObjectClass *) filter_parent_class)->set) { -// ((SPObjectClass *) filter_parent_class)->set(object, key, value); -// } CObject::onSet(key, value); break; } @@ -388,24 +218,6 @@ void CFilter::onSet(unsigned int key, gchar const *value) { /** * Receives update notifications. */ -static void -sp_filter_update(SPObject *object, 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)) { -// -// /* do something to trigger redisplay, updates? */ -// -// } -// -// if (((SPObjectClass *) filter_parent_class)->update) { -// ((SPObjectClass *) filter_parent_class)->update(object, ctx, flags); -// } - ((SPFilter*)object)->cfilter->onUpdate(ctx, flags); -} - void CFilter::onUpdate(SPCtx *ctx, guint flags) { //SPFilter *filter = SP_FILTER(object); @@ -416,130 +228,12 @@ void CFilter::onUpdate(SPCtx *ctx, guint flags) { } -// if (((SPObjectClass *) filter_parent_class)->update) { -// ((SPObjectClass *) filter_parent_class)->update(object, ctx, flags); -// } CObject::onUpdate(ctx, flags); } /** * Writes its settings to an incoming repr object, if any. */ -static Inkscape::XML::Node * -sp_filter_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) -{ -// SPFilter *filter = SP_FILTER(object); -// -// // Original from sp-item-group.cpp -// if (flags & SP_OBJECT_WRITE_BUILD) { -// if (!repr) { -// repr = doc->createElement("svg:filter"); -// } -// GSList *l = NULL; -// for ( SPObject *child = object->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() ) { -// child->updateRepr(flags); -// } -// } -// -// if ((flags & SP_OBJECT_WRITE_ALL) || filter->filterUnits_set) { -// switch (filter->filterUnits) { -// case SP_FILTER_UNITS_USERSPACEONUSE: -// repr->setAttribute("filterUnits", "userSpaceOnUse"); -// break; -// default: -// repr->setAttribute("filterUnits", "objectBoundingBox"); -// break; -// } -// } -// -// if ((flags & SP_OBJECT_WRITE_ALL) || filter->primitiveUnits_set) { -// switch (filter->primitiveUnits) { -// case SP_FILTER_UNITS_OBJECTBOUNDINGBOX: -// repr->setAttribute("primitiveUnits", "objectBoundingBox"); -// break; -// default: -// repr->setAttribute("primitiveUnits", "userSpaceOnUse"); -// break; -// } -// } -// -// if (filter->x._set) { -// sp_repr_set_svg_double(repr, "x", filter->x.computed); -// } else { -// repr->setAttribute("x", NULL); -// } -// -// if (filter->y._set) { -// sp_repr_set_svg_double(repr, "y", filter->y.computed); -// } else { -// repr->setAttribute("y", NULL); -// } -// -// if (filter->width._set) { -// sp_repr_set_svg_double(repr, "width", filter->width.computed); -// } else { -// repr->setAttribute("width", NULL); -// } -// -// if (filter->height._set) { -// sp_repr_set_svg_double(repr, "height", filter->height.computed); -// } else { -// repr->setAttribute("height", NULL); -// } -// -// if (filter->filterRes.getNumber()>=0) { -// gchar *tmp = filter->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(); -// repr->setAttribute("xlink:href", uri_string); -// g_free(uri_string); -// } -// -// // TODO: This is evil, correctly implement support for color-interpolation-filters!!! -// // The color-interpolation-filters attribute is initially set to linearRGB according to the SVG standard. -// // However, Inkscape completely ignores it and implicitly assumes that it is sRGB (like color-interpolation). -// // This results in a discrepancy between Inkscape and other renderers in how they render filters. -// // To mitigate this problem I've (Jasper van de Gronde,th.v.d.gronde@hccnet.nl) added this to ensure that at least -// // any filters written by Inkscape will henceforth be rendered the same in other renderers. -// // In the future Inkscape should have proper support for the color-interpolation properties and this should be changed. -// -// // repr->setAttribute("color-interpolation-filters", "sRGB"); -// -// // Actually, the above line is not correct as the attribute is only allowed on filter -// // primitives and not <filter> objects. However, it is allowed as a property in a style -// // attribute. Note, this property must also be set in sp-filter-chemistry, filter_new() as the -// // code here is not necessarily called when a new filter is created. 29 Aug 2011 Tav. -// SPCSSAttr *css = sp_repr_css_attr_new(); -// sp_repr_css_set_property(css, "color-interpolation-filters", "sRGB"); -// sp_repr_css_change(repr, css, "style"); -// sp_repr_css_attr_unref(css); -// -// if (((SPObjectClass *) filter_parent_class)->write) { -// ((SPObjectClass *) filter_parent_class)->write(object, doc, repr, flags); -// } -// -// return repr; - return ((SPFilter*)object)->cfilter->onWrite(doc, repr, flags); -} - Inkscape::XML::Node* CFilter::onWrite(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) { SPFilter* object = this->spfilter; SPFilter *filter = SP_FILTER(object); @@ -627,28 +321,6 @@ Inkscape::XML::Node* CFilter::onWrite(Inkscape::XML::Document *doc, Inkscape::XM g_free(uri_string); } - // TODO: This is evil, correctly implement support for color-interpolation-filters!!! - // The color-interpolation-filters attribute is initially set to linearRGB according to the SVG standard. - // However, Inkscape completely ignores it and implicitly assumes that it is sRGB (like color-interpolation). - // This results in a discrepancy between Inkscape and other renderers in how they render filters. - // To mitigate this problem I've (Jasper van de Gronde,th.v.d.gronde@hccnet.nl) added this to ensure that at least - // any filters written by Inkscape will henceforth be rendered the same in other renderers. - // In the future Inkscape should have proper support for the color-interpolation properties and this should be changed. - - // repr->setAttribute("color-interpolation-filters", "sRGB"); - - // Actually, the above line is not correct as the attribute is only allowed on filter - // primitives and not <filter> objects. However, it is allowed as a property in a style - // attribute. Note, this property must also be set in sp-filter-chemistry, filter_new() as the - // code here is not necessarily called when a new filter is created. 29 Aug 2011 Tav. - SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_set_property(css, "color-interpolation-filters", "sRGB"); - sp_repr_css_change(repr, css, "style"); - sp_repr_css_attr_unref(css); - -// if (((SPObjectClass *) filter_parent_class)->write) { -// ((SPObjectClass *) filter_parent_class)->write(object, doc, repr, flags); -// } CObject::onWrite(doc, repr, flags); return repr; @@ -682,24 +354,10 @@ static void filter_ref_modified(SPObject */*href*/, guint /*flags*/, SPFilter *f /** * Callback for child_added event. */ -static void -sp_filter_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) -{ -// //SPFilter *f = SP_FILTER(object); -// -// if (((SPObjectClass *) filter_parent_class)->child_added) -// (* ((SPObjectClass *) filter_parent_class)->child_added)(object, child, ref); -// -// object->requestModified(SP_OBJECT_MODIFIED_FLAG); - ((SPFilter*)object)->cfilter->onChildAdded(child, ref); -} - void CFilter::onChildAdded(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { SPFilter* object = this->spfilter; //SPFilter *f = SP_FILTER(object); -// if (((SPObjectClass *) filter_parent_class)->child_added) -// (* ((SPObjectClass *) filter_parent_class)->child_added)(object, child, ref); CObject::onChildAdded(child, ref); object->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -708,24 +366,10 @@ void CFilter::onChildAdded(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) /** * Callback for remove_child event. */ -static void -sp_filter_remove_child(SPObject *object, Inkscape::XML::Node *child) -{ -//// SPFilter *f = SP_FILTER(object); -// -// if (((SPObjectClass *) filter_parent_class)->remove_child) -// (* ((SPObjectClass *) filter_parent_class)->remove_child)(object, child); -// -// object->requestModified(SP_OBJECT_MODIFIED_FLAG); - ((SPFilter*)object)->cfilter->onRemoveChild(child); -} - void CFilter::onRemoveChild(Inkscape::XML::Node *child) { SPFilter* object = this->spfilter; // SPFilter *f = SP_FILTER(object); -// if (((SPObjectClass *) filter_parent_class)->remove_child) -// (* ((SPObjectClass *) filter_parent_class)->remove_child)(object, child); CObject::onRemoveChild(child); object->requestModified(SP_OBJECT_MODIFIED_FLAG); |
