Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
bluredge.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
7/*
8 * Authors:
9 * Ted Gould <ted@gould.cx>
10 *
11 * Copyright (C) 2005 Authors
12 *
13 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
14 */
15
16#include "bluredge.h"
17
18#include <vector>
19#include "desktop.h"
20#include "document.h"
21#include "selection.h"
22
23#include "preferences.h"
24#include "path-chemistry.h"
25#include "object/sp-item.h"
26
27#include "extension/effect.h"
28#include "extension/system.h"
29
30#include "path/path-offset.h"
31
32namespace Inkscape {
33namespace Extension {
34namespace Internal {
35
36
42bool
44{
45 // std::cout << "Hey, I'm Blur Edge, I'm loading!" << std::endl;
46 return TRUE;
47}
48
56{
58
59 double width = module->get_param_float("blur-width");
60 int steps = module->get_param_int("num-steps");
61
63 double old_offset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0, "px");
64
65 // TODO need to properly refcount the items, at least
66 std::vector<SPItem*> items(selection->items().begin(), selection->items().end());
67 selection->clear();
68
69 for(auto spitem : items) {
70 std::vector<Inkscape::XML::Node *> new_items(steps);
72 Inkscape::XML::Node * new_group = xml_doc->createElement("svg:g");
73 spitem->getRepr()->parent()->appendChild(new_group);
74
75 double orig_opacity = sp_repr_css_double_property(sp_repr_css_attr(spitem->getRepr(), "style"), "opacity", 1.0);
76 char opacity_string[64];
77 g_ascii_formatd(opacity_string, sizeof(opacity_string), "%f",
78 orig_opacity / (steps));
79
80 for (int i = 0; i < steps; i++) {
81 double offset = (width / (float)(steps - 1) * (float)i) - (width / 2.0);
82
83 new_items[i] = spitem->getRepr()->duplicate(xml_doc);
84
85 SPCSSAttr * css = sp_repr_css_attr(new_items[i], "style");
86 sp_repr_css_set_property(css, "opacity", opacity_string);
87 sp_repr_css_change(new_items[i], css, "style");
88
89 new_group->appendChild(new_items[i]);
90 selection->add(new_items[i]);
91 selection->toCurves();
92 selection->removeLPESRecursive(true);
93 selection->unlinkRecursive(true);
94
95 if (offset < 0.0) {
96 /* Doing an inset here folks */
97 offset *= -1.0;
98 prefs->setDoubleUnit("/options/defaultoffsetwidth/value", offset, "px");
100 } else if (offset > 0.0) {
101 prefs->setDoubleUnit("/options/defaultoffsetwidth/value", offset, "px");
103 }
104
105 selection->clear();
106 }
107
108 Inkscape::GC::release(new_group);
109 }
110
111 prefs->setDoubleUnit("/options/defaultoffsetwidth/value", old_offset, "px");
112
113 selection->clear();
114 selection->add(items.begin(), items.end());
115
116 return;
117}
118
119Gtk::Widget *
121{
122 return module->autogui(nullptr, nullptr, changeSignal);
123}
124
125#include "clear-n_.h"
126
127void
129{
130 // clang-format off
132 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
133 "<name>" N_("Inset/Outset Halo") "</name>\n"
134 "<id>org.inkscape.effect.bluredge</id>\n"
135 "<param name=\"blur-width\" gui-text=\"" N_("Width:") "\" gui-description=\"" N_("Width in px of the halo") "\" type=\"float\" min=\"1.0\" max=\"50.0\">1.0</param>\n"
136 "<param name=\"num-steps\" gui-text=\"" N_("Number of steps:") "\" gui-description=\"" N_("Number of inset/outset copies of the object to make") "\" type=\"int\" min=\"5\" max=\"100\">11</param>\n"
137 "<effect>\n"
138 "<object-type>all</object-type>\n"
139 "<effects-menu>\n"
140 "<submenu name=\"" N_("Generate from Path") "\" />\n"
141 "</effects-menu>\n"
142 "</effect>\n"
143 "</inkscape-extension>\n" , std::make_unique<BlurEdge>());
144 // clang-format on
145 return;
146}
147
148}; /* namespace Internal */
149}; /* namespace Extension */
150}; /* namespace Inkscape */
151
152/*
153 Local Variables:
154 mode:c++
155 c-file-style:"stroustrup"
156 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
157 indent-tabs-mode:nil
158 fill-column:99
159 End:
160*/
161// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Effects are extensions that take a document and do something to it in place.
Definition effect.h:39
The object that is the basis for the Extension system.
Definition extension.h:133
A cache for the document and this implementation.
void effect(Inkscape::Extension::Effect *module, ExecutionEnv *executionEnv, SPDesktop *desktop, Inkscape::Extension::Implementation::ImplementationDocumentCache *docCache) override
This actually blurs the edge.
Definition bluredge.cpp:54
bool load(Inkscape::Extension::Extension *module) override
A function to allocated anything – just an example here.
Definition bluredge.cpp:43
Gtk::Widget * prefs_effect(Inkscape::Extension::Effect *module, SPDesktop *desktop, sigc::signal< void()> *changeSignal, Inkscape::Extension::Implementation::ImplementationDocumentCache *docCache) override
Find out information about the file.
Definition bluredge.cpp:120
SPItemRange items()
Returns a range of selected SPItems.
Definition object-set.h:230
void removeLPESRecursive(bool keep_paths)
void clear()
Unselects all selected objects.
void toCurves(bool skip_undo=false, bool clonesjustunlink=false)
bool unlinkRecursive(const bool skip_undo=false, const bool force=false, const bool silent=false)
Recursively unlink any clones present in the current selection, including clones which are used to cl...
Preference storage class.
Definition preferences.h:61
void setDoubleUnit(Glib::ustring const &pref_path, double value, Glib::ustring const &unit_abbr)
Set a floating point value with unit.
double getDouble(Glib::ustring const &pref_path, double def=0.0, Glib::ustring const &unit="")
Retrieve a floating point value.
static Preferences * get()
Access the singleton Preferences object.
The set of selected SPObjects for a given document and layer model.
Definition selection.h:80
void add(XML::Node *repr)
Add an XML node's SPObject to the set of selected objects.
Definition selection.h:107
Interface for refcounted XML nodes.
Definition node.h:80
virtual Node * parent()=0
Get the parent of this node.
virtual void appendChild(Node *child)=0
Append a node as the last child of this node.
To do: update description of desktop.
Definition desktop.h:149
Inkscape::Selection * getSelection() const
Definition desktop.h:188
SPDocument * doc() const
Definition desktop.h:159
Inkscape::XML::Document * getReprDoc()
Our Inkscape::XML::Document.
Definition document.h:211
A way to clear the N_ macro, which is defined as an inline function.
std::shared_ptr< Css const > css
Editable view implementation.
double offset
void build_from_mem(gchar const *buffer, std::unique_ptr< Implementation::Implementation > in_imp)
Create a module from a buffer holding an XML description.
Definition system.cpp:459
static R & release(R &r)
Decrements the reference count of a anchored object.
Helper class to stream background task notifications as a series of messages.
void sp_selected_path_offset(SPDesktop *desktop)
void sp_selected_path_inset(SPDesktop *desktop)
Path offsets.
Singleton class to access the preferences file in a convenient way.
void sp_repr_css_change(Node *repr, SPCSSAttr *css, gchar const *attr)
Creates a new SPCSAttr with the values filled from a repr, merges in properties from the given SPCSAt...
Definition repr-css.cpp:357
double sp_repr_css_double_property(SPCSSAttr *css, gchar const *name, double defval)
Return the value of a style property if property define, or a default value if not.
Definition repr-css.cpp:212
SPCSSAttr * sp_repr_css_attr(Node const *repr, gchar const *attr)
Creates a new SPCSSAttr with one attribute (i.e.
Definition repr-css.cpp:88
void sp_repr_css_set_property(SPCSSAttr *css, gchar const *name, gchar const *value)
Set a style property to a new value (e.g.
Definition repr-css.cpp:190
GList * items
Some things pertinent to all visible shapes: SPItem, SPItemView, SPItemCtx.
Interface for XML documents.
Definition document.h:43
virtual Node * createElement(char const *name)=0
SPDesktop * desktop
double width