Code

93d44d6fa685f25ab32f329ec5925607093117e4
[inkscape.git] / src / extension / internal / filter / morphology.h
1 #ifndef __INKSCAPE_EXTENSION_INTERNAL_FILTER_MORPHOLOGY_H__
2 #define __INKSCAPE_EXTENSION_INTERNAL_FILTER_MORPHOLOGY_H__
3 /* Change the 'MORPHOLOGY' above to be your file name */
5 /*
6  * Copyright (C) 2010 Authors:
7  *   Ivan Louette (filters)
8  *   Nicolas Dufour (UI) <nicoduf@yahoo.fr>
9  *
10  * Morphology filters
11  *   Cross-smooth
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
15 /* ^^^ Change the copyright to be you and your e-mail address ^^^ */
17 #include "filter.h"
19 #include "extension/internal/clear-n_.h"
20 #include "extension/system.h"
21 #include "extension/extension.h"
23 namespace Inkscape {
24 namespace Extension {
25 namespace Internal {
26 namespace Filter {
28 /**
29     \brief    Custom predefined Cross-smooth filter.
30     
31     Smooth the outside of shapes and pictures.
33     Filter's parameters:
34     * Type (enum, default "Smooth edges") ->
35         Smooth edges = composite1 (in="SourceGraphic", in2="blur")
36         Smooth all = composite1 (in="blur", in2="blur")
37     * Blur (0.01->10., default 5.) -> blur (stdDeviation)
38 */
40 class Crosssmooth : public Inkscape::Extension::Internal::Filter::Filter {
41 protected:
42         virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
44 public:
45         Crosssmooth ( ) : Filter() { };
46         virtual ~Crosssmooth ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
48         static void init (void) {
49                 Inkscape::Extension::build_from_mem(
50                         "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
51                                 "<name>" N_("Cross-smooth, custom -EXP-") "</name>\n"
52                                 "<id>org.inkscape.effect.filter.Crosssmooth</id>\n"
53                         "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"enum\">\n"
54                             "<_item value=\"edges\">Smooth edges</_item>\n"
55                             "<_item value=\"all\">Smooth all</_item>\n"
56                         "</param>\n"
57                         "<param name=\"blur\" gui-text=\"" N_("Blur:") "\" type=\"float\" min=\"0.01\" max=\"10\">5</param>\n"
58                                 "<effect>\n"
59                                         "<object-type>all</object-type>\n"
60                                         "<effects-menu>\n"
61                                                 "<submenu name=\"" N_("Filters") "\">\n"
62                                                 "<submenu name=\"" N_("Experimental") "\"/>\n"
63                               "</submenu>\n"
64                                         "</effects-menu>\n"
65                                         "<menu-tip>" N_("Smooth edges and angles of shapes") "</menu-tip>\n"
66                                 "</effect>\n"
67                         "</inkscape-extension>\n", new Crosssmooth());
68         };
70 };
72 gchar const *
73 Crosssmooth::get_filter_text (Inkscape::Extension::Extension * ext)
74 {
75         if (_filter != NULL) g_free((void *)_filter);
77     std::ostringstream blur;
78     std::ostringstream c1in;
80     blur << ext->get_param_float("blur");
82     const gchar *type = ext->get_param_enum("type");
83     if((g_ascii_strcasecmp("all", type) == 0)) {
84         c1in << "blur";
85     } else {
86         c1in << "SourceGraphic";
87     }
89         _filter = g_strdup_printf(
90                 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" inkscape:label=\"Cross-smooth, custom -EXP-\">\n"
91         "<feGaussianBlur stdDeviation=\"%s\" result=\"blur\" />\n"
92         "<feComposite in=\"%s\" in2=\"blur\" operator=\"atop\" result=\"composite1\" />\n"
93         "<feComposite in2=\"composite1\" operator=\"in\" result=\"composite2\" />\n"
94         "<feComposite in2=\"composite2\" operator=\"in\" result=\"composite3\" />\n"
95         "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 20 -10 \" result=\"colormatrix\" />\n"
96         "</filter>\n", blur.str().c_str(), c1in.str().c_str());
98         return _filter;
99 }; /* Crosssmooth filter */
101 }; /* namespace Filter */
102 }; /* namespace Internal */
103 }; /* namespace Extension */
104 }; /* namespace Inkscape */
106 /* Change the 'COLOR' below to be your file name */
107 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_MORPHOLOGY_H__ */