Code

new file for filter manipulation stuff
[inkscape.git] / src / filter-chemistry.cpp
1 #define __SP_FILTER_CHEMISTRY_C__
3 /*
4  * Various utility methods for filters
5  *
6  * Authors:
7  *   Hugo Rodrigues
8  *   bulia byak
9  *
10  * Copyright (C) 2006 authors
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
16 #include "style.h"
17 #include "document-private.h"
18 #include "desktop-style.h"
20 #include "sp-filter.h"
21 #include "sp-gaussian-blur.h"
22 #include "svg/css-ostringstream.h"
24 #include "xml/repr.h"
26 /**
27  * Creates a filter with blur primitive of specified stdDeviation
28  */
29 SPFilter *
30 new_filter_gaussian_blur (SPDocument *document, gdouble stdDeviation)
31 {
32     g_return_val_if_fail(document != NULL, NULL);
34     SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document);
36     // create a new private filter
37     Inkscape::XML::Node *repr;
38     repr = sp_repr_new("svg:filter");
39     repr->setAttribute("inkscape:collect", "always");
41     //create feGaussianBlur node
42     Inkscape::XML::Node *b_repr;
43     b_repr = sp_repr_new("svg:feGaussianBlur");
44     b_repr->setAttribute("inkscape:collect", "always");
45     
46     //set stdDeviation attribute
47     Inkscape::CSSOStringStream os;
48     os << stdDeviation;
49     b_repr->setAttribute("stdDeviation", os.str().c_str());
50     
51     //set feGaussianBlur as child of filter node
52     repr->appendChild(b_repr);
53     Inkscape::GC::release(b_repr);
54     
55     // Append the new filter node to defs
56     SP_OBJECT_REPR(defs)->appendChild(repr);
57     Inkscape::GC::release(repr);
59     // get corresponding object
60     SPFilter *f = SP_FILTER( document->getObjectByRepr(repr) );
61     SPGaussianBlur *b = SP_GAUSSIANBLUR( document->getObjectByRepr(b_repr) );
62     
63     g_assert(f != NULL);
64     g_assert(SP_IS_FILTER(f));
65     g_assert(b != NULL);
66     g_assert(SP_IS_GAUSSIANBLUR(b));
68     return f;
69 }
71 void remove_filter (SPObject *item, bool recursive)
72 {
73         SPCSSAttr *css = sp_repr_css_attr_new ();
74         sp_repr_css_unset_property (css, "filter");
75         if (recursive)
76                 sp_repr_css_change_recursive(SP_OBJECT_REPR(item), css, "style");
77         else
78                 sp_repr_css_change (SP_OBJECT_REPR(item), css, "style");
79       sp_repr_css_attr_unref (css);
80 }
82 /*
83   Local Variables:
84   mode:c++
85   c-file-style:"stroustrup"
86   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
87   indent-tabs-mode:nil
88   fill-column:99
89   End:
90 */
91 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :