/** * Reads the Inkscape::XML::Node, and initializes SPFeBlend variables. For this to get called, * 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_feBlend_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { SPFeBlend *blend = SP_FEBLEND(object); if (((SPObjectClass *) feBlend_parent_class)->build) { ((SPObjectClass *) feBlend_parent_class)->build(object, document, repr); } /*LOAD ATTRIBUTES FROM REPR HERE*/ sp_object_read_attr(object, "mode"); sp_object_read_attr(object, "in2"); /* Unlike normal in, in2 is required attribute. Make sure, we can call * it by some name. */ if (blend->in2 == Inkscape::Filters::NR_FILTER_SLOT_NOT_SET || blend->in2 == Inkscape::Filters::NR_FILTER_UNNAMED_SLOT) { SPFilter *parent = SP_FILTER(object->parent); blend->in2 = sp_filter_primitive_name_previous_out(blend); repr->setAttribute("in2", sp_filter_name_for_image(parent, blend->in2)); } }
/** * Receives update notifications. */ static void sp_feBlend_update(SPObject *object, SPCtx *ctx, guint flags) { SPFeBlend *blend = SP_FEBLEND(object); if (flags & SP_OBJECT_MODIFIED_FLAG) { sp_object_read_attr(object, "mode"); sp_object_read_attr(object, "in2"); } /* Unlike normal in, in2 is required attribute. Make sure, we can call * it by some name. */ if (blend->in2 == Inkscape::Filters::NR_FILTER_SLOT_NOT_SET || blend->in2 == Inkscape::Filters::NR_FILTER_UNNAMED_SLOT) { SPFilter *parent = SP_FILTER(object->parent); blend->in2 = sp_filter_primitive_name_previous_out(blend); object->repr->setAttribute("in2", sp_filter_name_for_image(parent, blend->in2)); } if (((SPObjectClass *) feBlend_parent_class)->update) { ((SPObjectClass *) feBlend_parent_class)->update(object, ctx, flags); } }
/** * Writes its settings to an incoming repr object, if any. */ static Inkscape::XML::Node * sp_feComposite_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) { SPFeComposite *comp = SP_FECOMPOSITE(object); SPFilter *parent = SP_FILTER(object->parent); if (!repr) { repr = doc->createElement("svg:feComposite"); } gchar const *out_name = sp_filter_name_for_image(parent, comp->in2); if (out_name) { repr->setAttribute("in2", out_name); } else { SPObject *i = parent->children; while (i && i->next != object) i = i->next; SPFilterPrimitive *i_prim = SP_FILTER_PRIMITIVE(i); out_name = sp_filter_name_for_image(parent, i_prim->image_out); repr->setAttribute("in2", out_name); if (!out_name) { g_warning("Unable to set in2 for feComposite"); } } char const *comp_op; switch (comp->composite_operator) { case COMPOSITE_OVER: comp_op = "over"; break; case COMPOSITE_IN: comp_op = "in"; break; case COMPOSITE_OUT: comp_op = "out"; break; case COMPOSITE_ATOP: comp_op = "atop"; break; case COMPOSITE_XOR: comp_op = "xor"; break; case COMPOSITE_ARITHMETIC: comp_op = "arithmetic"; break; default: comp_op = 0; } repr->setAttribute("operator", comp_op); if (comp->composite_operator == COMPOSITE_ARITHMETIC) { sp_repr_set_svg_double(repr, "k1", comp->k1); sp_repr_set_svg_double(repr, "k2", comp->k2); sp_repr_set_svg_double(repr, "k3", comp->k3); sp_repr_set_svg_double(repr, "k4", comp->k4); } else { repr->setAttribute("k1", 0); repr->setAttribute("k2", 0); repr->setAttribute("k3", 0); repr->setAttribute("k4", 0); } if (((SPObjectClass *) feComposite_parent_class)->write) { ((SPObjectClass *) feComposite_parent_class)->write(object, doc, repr, flags); } return repr; }
/** * Writes its settings to an incoming repr object, if any. */ Inkscape::XML::Node* SPFeBlend::write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) { SPFilter *parent = SP_FILTER(this->parent); if (!repr) { repr = doc->createElement("svg:feBlend"); } gchar const *out_name = sp_filter_name_for_image(parent, this->in2); if (out_name) { repr->setAttribute("in2", out_name); } else { SPObject *i = parent->children; while (i && i->next != this) { i = i->next; } SPFilterPrimitive *i_prim = SP_FILTER_PRIMITIVE(i); out_name = sp_filter_name_for_image(parent, i_prim->image_out); repr->setAttribute("in2", out_name); if (!out_name) { g_warning("Unable to set in2 for feBlend"); } } char const *mode; switch(this->blend_mode) { case Inkscape::Filters::BLEND_NORMAL: mode = "normal"; break; case Inkscape::Filters::BLEND_MULTIPLY: mode = "multiply"; break; case Inkscape::Filters::BLEND_SCREEN: mode = "screen"; break; case Inkscape::Filters::BLEND_DARKEN: mode = "darken"; break; case Inkscape::Filters::BLEND_LIGHTEN: mode = "lighten"; break; // New case Inkscape::Filters::BLEND_OVERLAY: mode = "overlay"; break; case Inkscape::Filters::BLEND_COLORDODGE: mode = "color-dodge"; break; case Inkscape::Filters::BLEND_COLORBURN: mode = "color-burn"; break; case Inkscape::Filters::BLEND_HARDLIGHT: mode = "hard-light"; break; case Inkscape::Filters::BLEND_SOFTLIGHT: mode = "soft-light"; break; case Inkscape::Filters::BLEND_DIFFERENCE: mode = "difference"; break; case Inkscape::Filters::BLEND_EXCLUSION: mode = "exclusion"; break; case Inkscape::Filters::BLEND_HUE: mode = "hue"; break; case Inkscape::Filters::BLEND_SATURATION: mode = "saturation"; break; case Inkscape::Filters::BLEND_COLOR: mode = "color"; break; case Inkscape::Filters::BLEND_LUMINOSITY: mode = "luminosity"; break; default: mode = 0; } repr->setAttribute("mode", mode); SPFilterPrimitive::write(doc, repr, flags); return repr; }