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 }; /* namespace Filter */
145 }; /* namespace Internal */
146 }; /* namespace Extension */
147 }; /* namespace Inkscape */
149 /* Change the 'DROP_SHADOW' below to be your file name */
150 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_DROP_SHADOW_H__ */