1 #ifndef __INKSCAPE_EXTENSION_INTERNAL_FILTER_DROP_SHADOW_H__
2 #define __INKSCAPE_EXTENSION_INTERNAL_FILTER_DROP_SHADOW_H__
3 /* Change the 'DROP_SHADOW' above to be your file name */
5 /*
6 * Copyright (C) 2008 Authors:
7 * Ted Gould <ted@gould.cx>
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
11 /* ^^^ Change the copyright to be you and your e-mail address ^^^ */
13 #include "filter.h"
15 #include "extension/internal/clear-n_.h"
16 #include "extension/system.h"
17 #include "extension/extension.h"
19 namespace Inkscape {
20 namespace Extension {
21 namespace Internal {
22 namespace Filter {
24 class DropShadow : public Inkscape::Extension::Internal::Filter::Filter {
25 protected:
26 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
28 public:
29 DropShadow ( ) : Filter() { };
30 virtual ~DropShadow ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
32 static void init (void) {
33 Inkscape::Extension::build_from_mem(
34 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
35 "<name>" N_("Drop Shadow") "</name>\n"
36 "<id>org.inkscape.effect.filter.drop-shadow</id>\n"
37 "<param name=\"blur\" gui-text=\"" N_("Blur radius (px):") "\" type=\"float\" min=\"0.0\" max=\"200.0\">2.0</param>\n"
38 "<param name=\"opacity\" gui-text=\"" N_("Opacity (%):") "\" type=\"float\" min=\"0.0\" max=\"100.0\">50</param>\n"
39 "<param name=\"xoffset\" gui-text=\"" N_("Horizontal offset (px):") "\" type=\"float\" min=\"-50.0\" max=\"50.0\">4.0</param>\n"
40 "<param name=\"yoffset\" gui-text=\"" N_("Vertical offset (px):") "\" type=\"float\" min=\"-50.0\" max=\"50.0\">4.0</param>\n"
41 "<effect>\n"
42 "<object-type>all</object-type>\n"
43 "<effects-menu>\n"
44 "<submenu name=\"" N_("Filters") "\" >\n"
45 "<submenu name=\"" N_("Shadows and Glows") "\"/>\n"
46 "</submenu>\n"
47 "</effects-menu>\n"
48 "<menu-tip>" N_("Black, blurred drop shadow") "</menu-tip>\n"
49 "</effect>\n"
50 "</inkscape-extension>\n", new DropShadow());
51 };
53 };
55 gchar const *
56 DropShadow::get_filter_text (Inkscape::Extension::Extension * ext)
57 {
58 if (_filter != NULL) g_free((void *)_filter);
60 std::ostringstream blur;
61 std::ostringstream opacity;
62 std::ostringstream x;
63 std::ostringstream y;
65 blur << ext->get_param_float("blur");
66 opacity << ext->get_param_float("opacity") / 100;
67 x << ext->get_param_float("xoffset");
68 y << ext->get_param_float("yoffset");
70 _filter = g_strdup_printf(
71 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" inkscape:label=\"Drop shadow\" width=\"1.5\" height=\"1.5\" x=\"-.25\" y=\"-.25\">\n"
72 "<feGaussianBlur in=\"SourceAlpha\" stdDeviation=\"%s\" result=\"blur\"/>\n"
73 "<feColorMatrix result=\"bluralpha\" type=\"matrix\" values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 %s 0 \" />\n"
74 "<feOffset in=\"bluralpha\" dx=\"%s\" dy=\"%s\" result=\"offsetBlur\"/>\n"
75 "<feMerge>\n"
76 "<feMergeNode in=\"offsetBlur\"/>\n"
77 "<feMergeNode in=\"SourceGraphic\"/>\n"
78 "</feMerge>\n"
79 "</filter>\n", blur.str().c_str(), opacity.str().c_str(), x.str().c_str(), y.str().c_str());
81 return _filter;
82 };
84 class DropGlow : public Inkscape::Extension::Internal::Filter::Filter {
85 protected:
86 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
88 public:
89 DropGlow ( ) : Filter() { };
90 virtual ~DropGlow ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
92 static void init (void) {
93 Inkscape::Extension::build_from_mem(
94 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
95 "<name>" N_("Drop Glow") "</name>\n"
96 "<id>org.inkscape.effect.filter.drop-glow</id>\n"
97 "<param name=\"blur\" gui-text=\"" N_("Blur radius (px):") "\" type=\"float\" min=\"0.0\" max=\"200.0\">2.0</param>\n"
98 "<param name=\"opacity\" gui-text=\"" N_("Opacity (%):") "\" type=\"float\" min=\"0.0\" max=\"100.0\">50</param>\n"
99 "<param name=\"xoffset\" gui-text=\"" N_("Horizontal offset (px):") "\" type=\"float\" min=\"-50.0\" max=\"50.0\">4.0</param>\n"
100 "<param name=\"yoffset\" gui-text=\"" N_("Vertical offset (px):") "\" type=\"float\" min=\"-50.0\" max=\"50.0\">4.0</param>\n"
101 "<effect>\n"
102 "<object-type>all</object-type>\n"
103 "<effects-menu>\n"
104 "<submenu name=\"" N_("Filters") "\">\n"
105 "<submenu name=\"" N_("Shadows and Glows") "\"/>\n"
106 "</submenu>\n"
107 "</effects-menu>\n"
108 "<menu-tip>" N_("White, blurred drop glow") "</menu-tip>\n"
109 "</effect>\n"
110 "</inkscape-extension>\n", new DropGlow());
111 };
113 };
115 gchar const *
116 DropGlow::get_filter_text (Inkscape::Extension::Extension * ext)
117 {
118 if (_filter != NULL) g_free((void *)_filter);
120 std::ostringstream blur;
121 std::ostringstream opacity;
122 std::ostringstream x;
123 std::ostringstream y;
125 blur << ext->get_param_float("blur");
126 opacity << ext->get_param_float("opacity") / 100;
127 x << ext->get_param_float("xoffset");
128 y << ext->get_param_float("yoffset");
130 _filter = g_strdup_printf(
131 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" inkscape:label=\"Drop shadow\" width=\"1.5\" height=\"1.5\" x=\"-.25\" y=\"-.25\">\n"
132 "<feGaussianBlur in=\"SourceAlpha\" stdDeviation=\"%s\" result=\"blur\"/>\n"
133 "<feColorMatrix result=\"bluralpha\" type=\"matrix\" values=\"-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 %s 0 \" />\n"
134 "<feOffset in=\"bluralpha\" dx=\"%s\" dy=\"%s\" result=\"offsetBlur\"/>\n"
135 "<feMerge>\n"
136 "<feMergeNode in=\"offsetBlur\"/>\n"
137 "<feMergeNode in=\"SourceGraphic\"/>\n"
138 "</feMerge>\n"
139 "</filter>\n", blur.str().c_str(), opacity.str().c_str(), x.str().c_str(), y.str().c_str());
141 return _filter;
142 };
144 class ColorizableDropShadow : public Inkscape::Extension::Internal::Filter::Filter {
145 protected:
146 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
148 public:
149 ColorizableDropShadow ( ) : Filter() { };
150 virtual ~ColorizableDropShadow ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
152 static void init (void) {
153 Inkscape::Extension::build_from_mem(
154 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
155 "<name>" N_("Drop shadow, color -EXP-") "</name>\n"
156 "<id>org.inkscape.effect.filter.colorizable-drop-shadow</id>\n"
157 "<param name=\"blur\" gui-text=\"" N_("Blur radius (px):") "\" type=\"float\" min=\"0.0\" max=\"200.0\">3.0</param>\n"
158 "<param name=\"xoffset\" gui-text=\"" N_("Horizontal offset (px):") "\" type=\"float\" min=\"-50.0\" max=\"50.0\">6.0</param>\n"
159 "<param name=\"yoffset\" gui-text=\"" N_("Vertical offset (px):") "\" type=\"float\" min=\"-50.0\" max=\"50.0\">6.0</param>\n"
160 "<param name=\"color\" gui-text=\"" N_("Color") "\" type=\"color\">127</param>\n"
161 "<effect>\n"
162 "<object-type>all</object-type>\n"
163 "<effects-menu>\n"
164 "<submenu name=\"" N_("Filters") "\">\n"
165 "<submenu name=\"" N_("Experimental") "\"/>\n"
166 "</submenu>\n"
167 "</effects-menu>\n"
168 "<menu-tip>" N_("Colorizable Drop shadow") "</menu-tip>\n"
169 "</effect>\n"
170 "</inkscape-extension>\n", new ColorizableDropShadow());
171 };
173 };
175 gchar const *
176 ColorizableDropShadow::get_filter_text (Inkscape::Extension::Extension * ext)
177 {
178 if (_filter != NULL) g_free((void *)_filter);
180 std::ostringstream blur;
181 std::ostringstream a;
182 std::ostringstream r;
183 std::ostringstream g;
184 std::ostringstream b;
185 std::ostringstream x;
186 std::ostringstream y;
188 guint32 color = ext->get_param_color("color");
190 blur << ext->get_param_float("blur");
191 x << ext->get_param_float("xoffset");
192 y << ext->get_param_float("yoffset");
193 a << (color & 0xff) / 255.0F;
194 r << ((color >> 24) & 0xff);
195 g << ((color >> 16) & 0xff);
196 b << ((color >> 8) & 0xff);
198 _filter = g_strdup_printf(
199 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1.2\" width=\"1.2\" y=\"-0.1\" x=\"-0.1\" inkscape:label=\"Drop shadow, color -EXP-\">\n"
200 "<feFlood flood-opacity=\"%s\" result=\"flood\" flood-color=\"rgb(%s,%s,%s)\" />\n"
201 "<feComposite in2=\"SourceGraphic\" in=\"flood\" result=\"composite\" operator=\"in\" />\n"
202 "<feGaussianBlur result=\"blur\" stdDeviation=\"%s\" in=\"composite\" />\n"
203 "<feOffset result=\"offsetBlur\" dx=\"%s\" dy=\"%s\" />\n"
204 "<feComposite in2=\"offsetBlur\" in=\"SourceGraphic\" operator=\"over\" result=\"compositeBlur\" />\n"
205 "</filter>\n", a.str().c_str(), r.str().c_str(), g.str().c_str(), b.str().c_str(), blur.str().c_str(), x.str().c_str(), y.str().c_str());
207 return _filter;
208 };
209 }; /* namespace Filter */
210 }; /* namespace Internal */
211 }; /* namespace Extension */
212 }; /* namespace Inkscape */
214 /* Change the 'DROP_SHADOW' below to be your file name */
215 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_DROP_SHADOW_H__ */