diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp
index 150033895202aea50541345839874ed4431463a5..7197c1ec93539c53810f0d0db80ac58703a24882 100644 (file)
--- a/src/sp-filter.cpp
+++ b/src/sp-filter.cpp
using std::map;
using std::pair;
+#include <gtkmm.h>
+
#include "attributes.h"
#include "document.h"
#include "sp-filter.h"
#define SP_MACROS_SILENT
#include "macros.h"
-#include "display/nr-filter.cpp"
+#include "display/nr-filter.h"
/* Filter base class */
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::Node *repr, guint flags);
+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);
filter->_image_name = new std::map<gchar *, int, ltstr>;
filter->_image_name->clear();
+ filter->_image_number_next = 0;
filter->filterRes = NumberOptNumber();
* Writes its settings to an incoming repr object, if any.
*/
static Inkscape::XML::Node *
-sp_filter_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
+sp_filter_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
{
SPFilter *filter = SP_FILTER(object);
-
- if (!repr) {
- repr = SP_OBJECT_REPR(object)->duplicate(NULL); // FIXME
+ SPObject *child;
+ Inkscape::XML::Node *crepr;
+
+ /* Original from sp-item-group.cpp */
+ if (flags & SP_OBJECT_WRITE_BUILD) {
+ GSList *l;
+ if (!repr) {
+ repr = doc->createElement("svg:filter");
+ }
+ l = NULL;
+ for (child = sp_object_first_child(object); child != NULL; child = SP_OBJECT_NEXT(child) ) {
+ 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 (child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
+ child->updateRepr(flags);
+ }
}
if ((flags & SP_OBJECT_WRITE_ALL) || filter->filterUnits_set) {
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-filters).
+ // 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");
+
if (((SPObjectClass *) filter_parent_class)->write) {
- ((SPObjectClass *) filter_parent_class)->write(object, repr, flags);
+ ((SPObjectClass *) filter_parent_class)->write(object, doc, repr, flags);
}
return repr;
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
-void sp_filter_build_renderer(SPFilter *sp_filter, NR::Filter *nr_filter)
+void sp_filter_build_renderer(SPFilter *sp_filter, Inkscape::Filters::Filter *nr_filter)
{
g_assert(sp_filter != NULL);
g_assert(nr_filter != NULL);
return value;
}
+gchar const *sp_filter_name_for_image(SPFilter const *filter, int const image) {
+ switch (image) {
+ case Inkscape::Filters::NR_FILTER_SOURCEGRAPHIC:
+ return "SourceGraphic";
+ break;
+ case Inkscape::Filters::NR_FILTER_SOURCEALPHA:
+ return "SourceAlpha";
+ break;
+ case Inkscape::Filters::NR_FILTER_BACKGROUNDIMAGE:
+ return "BackgroundImage";
+ break;
+ case Inkscape::Filters::NR_FILTER_BACKGROUNDALPHA:
+ return "BackgroundAlpha";
+ break;
+ case Inkscape::Filters::NR_FILTER_STROKEPAINT:
+ return "StrokePaint";
+ break;
+ case Inkscape::Filters::NR_FILTER_FILLPAINT:
+ return "FillPaint";
+ break;
+ case Inkscape::Filters::NR_FILTER_SLOT_NOT_SET:
+ case Inkscape::Filters::NR_FILTER_UNNAMED_SLOT:
+ return 0;
+ break;
+ default:
+ for (map<gchar *, int, ltstr>::const_iterator i
+ = filter->_image_name->begin() ;
+ i != filter->_image_name->end() ; i++) {
+ if (i->second == image) {
+ return i->first;
+ }
+ }
+ }
+ return 0;
+}
+
+Glib::ustring sp_filter_get_new_result_name(SPFilter *filter) {
+ g_assert(filter != NULL);
+ int largest = 0;
+
+ SPObject *primitive_obj = filter->children;
+ while (primitive_obj) {
+ if (SP_IS_FILTER_PRIMITIVE(primitive_obj)) {
+ Inkscape::XML::Node *repr = SP_OBJECT_REPR(primitive_obj);
+ char const *result = repr->attribute("result");
+ int index;
+ if (result && sscanf(result, "result%d", &index) == 1) {
+ if (index > largest) {
+ largest = index;
+ }
+ }
+ }
+ primitive_obj = primitive_obj->next;
+ }
+
+ return "result" + Glib::Ascii::dtostr(largest + 1);
+}
+
bool ltstr::operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;