Logo Search packages:      
Sourcecode: inkscape version File versions

void Inkscape::Extension::Internal::BlurEdge::effect ( Inkscape::Extension::Effect module,
Inkscape::UI::View::View document,
Inkscape::Extension::Implementation::ImplementationDocumentCache docCache 
) [virtual]

This actually blurs the edge.

Parameters:
module The effect that was called (unused)
document What should be edited.

Reimplemented from Inkscape::Extension::Implementation::Implementation.

Definition at line 54 of file bluredge.cpp.

References Inkscape::Selection::add(), Inkscape::Selection::clear(), Inkscape::UI::View::View::doc(), Inkscape::Verb::get(), Inkscape::Extension::Extension::get_param_float(), Inkscape::Extension::Extension::get_param_int(), Inkscape::Selection::itemList(), and sp_action_perform().

{
    Inkscape::Selection * selection     = ((SPDesktop *)document)->selection;

    float width = module->get_param_float("blur-width");
    int   steps = module->get_param_int("num-steps");

    double old_offset = prefs_get_double_attribute("options.defaultoffsetwidth", "value", 1.0);

    using Inkscape::Util::GSListConstIterator;
    // TODO need to properly refcount the items, at least
    std::list<SPItem *> items;
    items.insert<GSListConstIterator<SPItem *> >(items.end(), selection->itemList(), NULL);
    selection->clear();

    for(std::list<SPItem *>::iterator item = items.begin();
            item != items.end(); item++) {
        SPItem * spitem = *item;

        std::vector<Inkscape::XML::Node *> new_items(steps);
        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document->doc());
        Inkscape::XML::Node * new_group = xml_doc->createElement("svg:g");
        (SP_OBJECT_REPR(spitem)->parent())->appendChild(new_group);

        double orig_opacity = sp_repr_css_double_property(sp_repr_css_attr(SP_OBJECT_REPR(spitem), "style"), "opacity", 1.0);
        char opacity_string[64];
        g_ascii_formatd(opacity_string, sizeof(opacity_string), "%f",
                        orig_opacity / (steps));

        for (int i = 0; i < steps; i++) {
            double offset = (width / (float)(steps - 1) * (float)i) - (width / 2.0);

            new_items[i] = (SP_OBJECT_REPR(spitem))->duplicate(xml_doc);

            SPCSSAttr * css = sp_repr_css_attr(new_items[i], "style");
            sp_repr_css_set_property(css, "opacity", opacity_string);
            sp_repr_css_change(new_items[i], css, "style");

            new_group->appendChild(new_items[i]);
            selection->add(new_items[i]);
            sp_selected_path_to_curves();

            if (offset < 0.0) {
                /* Doing an inset here folks */
                offset *= -1.0;
                prefs_set_double_attribute("options.defaultoffsetwidth", "value", offset);
                sp_action_perform(Inkscape::Verb::get(SP_VERB_SELECTION_INSET)->get_action(document), NULL);
            } else if (offset > 0.0) {
                prefs_set_double_attribute("options.defaultoffsetwidth", "value", offset);
                sp_action_perform(Inkscape::Verb::get(SP_VERB_SELECTION_OFFSET)->get_action(document), NULL);
            }

            selection->clear();
        }

    }

    prefs_set_double_attribute("options.defaultoffsetwidth", "value", old_offset);

    selection->clear();
    selection->add(items.begin(), items.end());

    return;
}


Generated by  Doxygen 1.6.0   Back to index