Code

new file for filter manipulation stuff
authorbuliabyak <buliabyak@users.sourceforge.net>
Sat, 7 Oct 2006 19:45:27 +0000 (19:45 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Sat, 7 Oct 2006 19:45:27 +0000 (19:45 +0000)
src/Makefile_insert
src/filter-chemistry.cpp [new file with mode: 0644]
src/filter-chemistry.h [new file with mode: 0644]

index d0ef0248b74d912538073a7fc3877c7c30da3e48..d6694a759e5e126e7122e2d0530c7749e38aecf6 100644 (file)
@@ -70,6 +70,7 @@ libinkpre_a_SOURCES = \
        event-log.cpp event-log.h       \
        extract-uri.cpp extract-uri.h   \
        file.cpp file.h \
+       filter-chemistry.cpp filter-chemistry.h \
        fontsize-expansion.cpp fontsize-expansion.h     \
        forward.h       \
        geom.cpp geom.h \
@@ -270,6 +271,7 @@ libinkpost_a_SOURCES =      \
        decimal-round.h \
        dir-util.cpp dir-util.h \
        fill-or-stroke.h        \
+       filter-chemistry.cpp filter-chemistry.h \
        fixes.cpp \
        gc-alloc.h      \
        gc-anchored.h gc-anchored.cpp   \
diff --git a/src/filter-chemistry.cpp b/src/filter-chemistry.cpp
new file mode 100644 (file)
index 0000000..0b37416
--- /dev/null
@@ -0,0 +1,91 @@
+#define __SP_FILTER_CHEMISTRY_C__
+
+/*
+ * Various utility methods for filters
+ *
+ * Authors:
+ *   Hugo Rodrigues
+ *   bulia byak
+ *
+ * Copyright (C) 2006 authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+
+#include "style.h"
+#include "document-private.h"
+#include "desktop-style.h"
+
+#include "sp-filter.h"
+#include "sp-gaussian-blur.h"
+#include "svg/css-ostringstream.h"
+
+#include "xml/repr.h"
+
+/**
+ * Creates a filter with blur primitive of specified stdDeviation
+ */
+SPFilter *
+new_filter_gaussian_blur (SPDocument *document, gdouble stdDeviation)
+{
+    g_return_val_if_fail(document != NULL, NULL);
+
+    SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document);
+
+    // create a new private filter
+    Inkscape::XML::Node *repr;
+    repr = sp_repr_new("svg:filter");
+    repr->setAttribute("inkscape:collect", "always");
+
+    //create feGaussianBlur node
+    Inkscape::XML::Node *b_repr;
+    b_repr = sp_repr_new("svg:feGaussianBlur");
+    b_repr->setAttribute("inkscape:collect", "always");
+    
+    //set stdDeviation attribute
+    Inkscape::CSSOStringStream os;
+    os << stdDeviation;
+    b_repr->setAttribute("stdDeviation", os.str().c_str());
+    
+    //set feGaussianBlur as child of filter node
+    repr->appendChild(b_repr);
+    Inkscape::GC::release(b_repr);
+    
+    // Append the new filter node to defs
+    SP_OBJECT_REPR(defs)->appendChild(repr);
+    Inkscape::GC::release(repr);
+
+    // get corresponding object
+    SPFilter *f = SP_FILTER( document->getObjectByRepr(repr) );
+    SPGaussianBlur *b = SP_GAUSSIANBLUR( document->getObjectByRepr(b_repr) );
+    
+    g_assert(f != NULL);
+    g_assert(SP_IS_FILTER(f));
+    g_assert(b != NULL);
+    g_assert(SP_IS_GAUSSIANBLUR(b));
+
+    return f;
+}
+
+void remove_filter (SPObject *item, bool recursive)
+{
+       SPCSSAttr *css = sp_repr_css_attr_new ();
+       sp_repr_css_unset_property (css, "filter");
+       if (recursive)
+               sp_repr_css_change_recursive(SP_OBJECT_REPR(item), css, "style");
+       else
+               sp_repr_css_change (SP_OBJECT_REPR(item), css, "style");
+      sp_repr_css_attr_unref (css);
+}
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/filter-chemistry.h b/src/filter-chemistry.h
new file mode 100644 (file)
index 0000000..3177632
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef __SP_FILTER_CHEMISTRY_H__
+#define __SP_FILTER_CHEMISTRY_H__
+
+/*
+ * Various utility methods for filters
+ *
+ * Authors:
+ *   Hugo Rodrigues
+ *   bulia byak
+ *
+ * Copyright (C) 2006 authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "forward.h"
+#include "sp-filter.h"
+
+SPFilter *new_filter_gaussian_blur (SPDocument *document, gdouble stdDeviation);
+void remove_filter (SPObject *item, bool recursive);
+
+#endif
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :