Exemple #1
0
/**
 * Writes its settings to an incoming repr object, if any.
 */
static Inkscape::XML::Node *
sp_feBlend_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
{
    SPFeBlend *blend = SP_FEBLEND(object);
    SPFilter *parent = SP_FILTER(object->parent);

    if (!repr) {
        repr = doc->createElement("svg:feBlend");
    }

    gchar const *out_name = sp_filter_name_for_image(parent, blend->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 feBlend");
        }
    }

    char const *mode;
    switch(blend->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;
        default:
            mode = 0;
    }
    repr->setAttribute("mode", mode);

    if (((SPObjectClass *) feBlend_parent_class)->write) {
        ((SPObjectClass *) feBlend_parent_class)->write(object, doc, repr, flags);
    }

    return repr;
}
/**
 * Gives name for output of previous filter. Makes things clearer when prim
 * is a filter with two or more inputs. Returns the slot number of result
 * of previous primitive, or NR_FILTER_SOURCEGRAPHIC if this is the first
 * primitive.
 */
int sp_filter_primitive_name_previous_out(SPFilterPrimitive *prim) {
    SPFilter *parent = SP_FILTER(prim->parent);
    SPObject *i = parent->children;
    while (i && i->next != prim) i = i->next;
    if (i) {
        SPFilterPrimitive *i_prim = SP_FILTER_PRIMITIVE(i);
        if (i_prim->image_out < 0) {
            Glib::ustring name = sp_filter_get_new_result_name(parent);
            int slot = sp_filter_set_image_name(parent, name.c_str());
            i_prim->image_out = slot;
            //XML Tree is being directly used while it shouldn't be.
            i_prim->getRepr()->setAttribute("result", name.c_str());
            return slot;
        } else {
            return i_prim->image_out;
        }
    }
    return Inkscape::Filters::NR_FILTER_SOURCEGRAPHIC;
}
Exemple #3
0
/**
 * Writes its settings to an incoming repr object, if any.
 */
Inkscape::XML::Node* SPFeDisplacementMap::write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) {
    SPFilter *parent = SP_FILTER(this->parent);

    if (!repr) {
        repr = doc->createElement("svg:feDisplacementMap");
    }

    gchar const *in2_name = sp_filter_name_for_image(parent, this->in2);

    if( !in2_name ) {

        // This code is very similar to sp_filter_primtive_name_previous_out()
        SPObject *i = parent->children;

        // Find previous filter primitive
        while (i && i->next != this) {
        	i = i->next;
        }

        if( i ) {
            SPFilterPrimitive *i_prim = SP_FILTER_PRIMITIVE(i);
            in2_name = sp_filter_name_for_image(parent, i_prim->image_out);
        }
    }

    if (in2_name) {
        repr->setAttribute("in2", in2_name);
    } else {
        g_warning("Unable to set in2 for feDisplacementMap");
    }

    sp_repr_set_svg_double(repr, "scale", this->scale);
    repr->setAttribute("xChannelSelector",
                       get_channelselector_name(this->xChannelSelector));
    repr->setAttribute("yChannelSelector",
                       get_channelselector_name(this->yChannelSelector));

    SPFilterPrimitive::write(doc, repr, flags);

    return repr;
}
/**
 * Writes its settings to an incoming repr object, if any.
 */
Inkscape::XML::Node* SPFilterPrimitive::write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) {
    SPFilterPrimitive* object = this;

    SPFilterPrimitive *prim = SP_FILTER_PRIMITIVE(object);
    SPFilter *parent = SP_FILTER(object->parent);

    if (!repr) {
        repr = object->getRepr()->duplicate(doc);
    }

    gchar const *in_name = sp_filter_name_for_image(parent, prim->image_in);
    repr->setAttribute("in", in_name);

    gchar const *out_name = sp_filter_name_for_image(parent, prim->image_out);
    repr->setAttribute("result", out_name);

    /* Do we need to add x,y,width,height? */
    SPObject::write(doc, repr, flags);

    return repr;
}
Exemple #5
0
/**
 * 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;
}
Exemple #6
0
/**
 * 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;
}