diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2016-10-14 08:39:17 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2016-10-14 08:39:17 +0000 |
| commit | 2715ea15f1574bf2efc00610ac3c930dcfb30621 (patch) | |
| tree | d1ae11cd9ccb645f1670f8a5f46db6a8df9bf664 /src | |
| parent | Ensure newly created meshes have correct 'gradientUnits'. (diff) | |
| download | inkscape-2715ea15f1574bf2efc00610ac3c930dcfb30621.tar.gz inkscape-2715ea15f1574bf2efc00610ac3c930dcfb30621.zip | |
Do not create unused "vector" gradient when creating mesh gradient.
(bzr r15168)
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/tools/mesh-tool.cpp | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index aac8239f3..5e88e26b3 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -38,6 +38,9 @@ #include "snap.h" #include "sp-namedview.h" #include "verbs.h" +#include "sp-text.h" +#include "sp-defs.h" +#include "style.h" // Gradient specific #include "gradient-drag.h" @@ -937,37 +940,42 @@ static void sp_mesh_end_drag(MeshTool &rc) { if (!selection->isEmpty()) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - int type = SP_GRADIENT_TYPE_MESH; - Inkscape::PaintTarget fill_or_stroke = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; + Inkscape::PaintTarget fill_or_stroke = + (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? + Inkscape::FOR_FILL : Inkscape::FOR_STROKE; - SPGradient *vector; - if (ec->item_to_select) { - // pick color from the object where drag started - vector = sp_gradient_vector_for_object(document, desktop, ec->item_to_select, fill_or_stroke); - } else { - // Starting from empty space: - // Sort items so that the topmost comes last - std::vector<SPItem*> items(selection->items().begin(), selection->items().end()); - sort(items.begin(),items.end(),sp_item_repr_compare_position); - // take topmost - vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(items.back()), fill_or_stroke); - } - - // HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs +// HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "fill-opacity", "1.0"); + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + SPDefs *defs = document->getDefs(); + auto items= selection->items(); for(auto i=items.begin();i!=items.end();++i){ //FIXME: see above sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); - sp_item_set_gradient(*i, vector, (SPGradientType) type, fill_or_stroke); + // Create mesh element + Inkscape::XML::Node *repr = xml_doc->createElement("svg:meshgradient"); - // We don't need to do anything. Mesh is already sized appropriately. - - (*i)->requestModified(SP_OBJECT_MODIFIED_FLAG); + // privates are garbage-collectable + repr->setAttribute("inkscape:collect", "always"); + + // Attach to document + defs->getRepr()->appendChild(repr); + Inkscape::GC::release(repr); + + // Get corresponding object + SPMeshGradient *mg = static_cast<SPMeshGradient *>(document->getObjectByRepr(repr)); + mg->array.create(mg, *i, (*i)->visualBounds()); + + bool isText = SP_IS_TEXT(*i); + sp_style_set_property_url (*i, ((fill_or_stroke == Inkscape::FOR_FILL) ? "fill":"stroke"), + mg, isText); + + (*i)->requestModified(SP_OBJECT_MODIFIED_FLAG|SP_OBJECT_STYLE_MODIFIED_FLAG); } DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MESH, _("Create mesh")); |
