Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
shadows.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_SHADOWS_H__
3#define SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_SHADOWS_H__
4/* Change the 'SHADOWS' above to be your file name */
5
6/*
7 * Copyright (C) 2013 Authors:
8 * Ivan Louette (filters)
9 * Nicolas Dufour (UI) <nicoduf@yahoo.fr>
10 *
11 * Shadow filters
12 * Drop shadow
13 *
14 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15 */
16/* ^^^ Change the copyright to be you and your e-mail address ^^^ */
17
18#include "extension/extension.h"
20#include "extension/system.h"
21#include "filter.h"
22
23namespace Inkscape {
24namespace Extension {
25namespace Internal {
26namespace Filter {
27
47{
48protected:
49 gchar const *get_filter_text(Inkscape::Extension::Extension *ext) override;
50
51public:
55 {
56 if (_filter != nullptr)
57 g_free((void *)_filter);
58 return;
59 }
60
61 static void init()
62 {
63 // clang-format off
65 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
66 "<name>" N_("Drop Shadow") "</name>\n"
67 "<id>org.inkscape.effect.filter.ColorDropShadow</id>\n"
68 "<param name=\"tab\" type=\"notebook\">\n"
69 "<page name=\"optionstab\" gui-text=\"" N_("Options") "\">\n"
70 "<param name=\"blur\" gui-text=\"" N_("Blur radius (px)") "\" type=\"float\" appearance=\"full\" min=\"0.0\" max=\"200.0\">3.0</param>\n"
71 "<param name=\"xoffset\" gui-text=\"" N_("Horizontal offset (px)") "\" type=\"float\" appearance=\"full\" min=\"-50.0\" max=\"50.0\">6.0</param>\n"
72 "<param name=\"yoffset\" gui-text=\"" N_("Vertical offset (px)") "\" type=\"float\" appearance=\"full\" min=\"-50.0\" max=\"50.0\">6.0</param>\n"
73 "<param name=\"type\" gui-text=\"" N_("Shadow type:") "\" type=\"optiongroup\" appearance=\"combo\" >\n"
74 "<option value=\"outer\">" N_("Outer") "</option>\n"
75 "<option value=\"inner\">" N_("Inner") "</option>\n"
76 "<option value=\"outercut\">" N_("Outer cutout") "</option>\n"
77 "<option value=\"innercut\">" N_("Inner cutout") "</option>\n"
78 "<option value=\"shadow\">" N_("Shadow only") "</option>\n"
79 "</param>\n"
80 "</page>\n"
81 "<page name=\"coltab\" gui-text=\"" N_("Blur color") "\">\n"
82 "<param name=\"color\" gui-text=\"" N_("Color") "\" type=\"color\">127</param>\n"
83 "<param name=\"objcolor\" gui-text=\"" N_("Use object's color") "\" type=\"bool\" >false</param>\n"
84 "</page>\n"
85 "</param>\n"
86 "<effect>\n"
87 "<object-type>all</object-type>\n"
88 "<effects-menu>\n"
89 "<submenu name=\"" N_("Filters") "\">\n"
90 "<submenu name=\"" N_("Shadows and Glows") "\"/>\n"
91 "</submenu>\n"
92 "</effects-menu>\n"
93 "<menu-tip>" N_("Colorizable Drop shadow") "</menu-tip>\n"
94 "</effect>\n"
95 "</inkscape-extension>\n", std::make_unique<ColorizableDropShadow>());
96 // clang-format on
97 };
98};
99
101{
102 if (_filter != nullptr)
103 g_free((void *)_filter);
104
105 // Style parameters
106
107 auto color = ext->get_param_color("color");
108 float blur_std = ext->get_param_float("blur");
109 float offset_x = ext->get_param_float("xoffset");
110 float offset_y = ext->get_param_float("yoffset");
111
112 // Handle mode parameter
113
114 const char *comp1op;
115 const char *comp1in1;
116 const char *comp1in2;
117 const char *comp2in1;
118 const char *comp2in2;
119 const char *comp2op;
120
121 bool objcolor = ext->get_param_bool("objcolor");
122 const gchar *mode = ext->get_param_optiongroup("type");
123
124 comp1in1 = "flood";
125 comp1in2 = "offset";
126 if (g_ascii_strcasecmp("outer", mode) == 0) {
127 comp1op = "in";
128 comp2op = "over";
129 comp2in1 = "SourceGraphic";
130 comp2in2 = "comp1";
131 } else if (g_ascii_strcasecmp("inner", mode) == 0) {
132 comp1op = "out";
133 comp2op = "atop";
134 comp2in1 = "comp1";
135 comp2in2 = "SourceGraphic";
136 } else if (g_ascii_strcasecmp("outercut", mode) == 0) {
137 comp1op = "in";
138 comp2op = "out";
139 comp2in1 = "comp1";
140 comp2in2 = "SourceGraphic";
141 } else if (g_ascii_strcasecmp("innercut", mode) == 0) {
142 comp1op = "out";
143 comp2op = "in";
144 comp2in1 = "comp1";
145 comp2in2 = "SourceGraphic";
146 if (objcolor) {
147 std::swap(comp2in1, comp2in2);
148 objcolor = false; // don't swap comp1 inputs later
149 }
150 } else { // shadow only
151 comp1op = "in";
152 comp2op = "atop";
153 comp2in1 = "comp1";
154 comp2in2 = "comp1";
155 }
156
157 if (objcolor) {
158 std::swap(comp1in1, comp1in2);
159 }
160
161 // clang-format off
162 auto old = std::locale::global(std::locale::classic());
163 _filter = g_strdup_printf(
164 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Drop Shadow\">\n"
165 "<feFlood result=\"flood\" in=\"SourceGraphic\" flood-opacity=\"%f\" flood-color=\"%s\"/>\n"
166 "<feGaussianBlur result=\"blur\" in=\"SourceGraphic\" stdDeviation=\"%f\"/>\n"
167 "<feOffset result=\"offset\" in=\"blur\" dx=\"%f\" dy=\"%f\"/>\n"
168 "<feComposite result=\"comp1\" operator=\"%s\" in=\"%s\" in2=\"%s\"/>\n"
169 "<feComposite result=\"comp2\" operator=\"%s\" in=\"%s\" in2=\"%s\"/>\n"
170 "</filter>\n",
171
172 color.getOpacity(), color.toString(false).c_str(),
173 blur_std,
174 offset_x, offset_y,
175
176 comp1op, comp1in1, comp1in2,
177 comp2op, comp2in1, comp2in2
178 );
179 std::locale::global(old);
180 // clang-format on
181
182 return _filter;
183}; /* Drop shadow filter */
184
185}; /* namespace Filter */
186}; /* namespace Internal */
187}; /* namespace Extension */
188}; /* namespace Inkscape */
189
190/* Change the 'SHADOWS' below to be your file name */
191#endif /* SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_SHADOWS_H__ */
The object that is the basis for the Extension system.
Definition extension.h:133
char const * get_param_optiongroup(char const *name, char const *alt) const
Like get_param_optiongroup but with a default on param_not_exist error.
double get_param_float(char const *name) const
Gets a float parameter identified by name with the double placed in value.
Colors::Color get_param_color(char const *name) const
Gets a parameter identified by name with the unsigned int placed in value.
bool get_param_bool(char const *name) const
Gets a parameter identified by name with the bool placed in value.
Custom predefined Drop shadow filter.
Definition shadows.h:47
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition shadows.h:100
A way to clear the N_ macro, which is defined as an inline function.
Inkscape::Extension::Extension: Frontend to certain, possibly pluggable, actions.
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
Helper class to stream background task notifications as a series of messages.
int mode