summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 938c961)
raw | patch | inline | side by side (parent: 938c961)
author | buliabyak <buliabyak@users.sourceforge.net> | |
Mon, 23 Oct 2006 01:44:48 +0000 (01:44 +0000) | ||
committer | buliabyak <buliabyak@users.sourceforge.net> | |
Mon, 23 Oct 2006 01:44:48 +0000 (01:44 +0000) |
src/filter-chemistry.cpp | patch | blob | history | |
src/filter-chemistry.h | patch | blob | history |
index e18e54ed6e9fca4bd3a70b8d1f4b44d9ee5348f3..3c27b6edc5b3eafef9ffe9dee1aa2bc1bd5e47e8 100644 (file)
--- a/src/filter-chemistry.cpp
+++ b/src/filter-chemistry.cpp
#include "xml/repr.h"
/**
- * Creates a filter with blur primitive of specified stdDeviation
+ * Creates a filter with blur primitive of specified radius for an item with the given matrix expansion, width and height
*/
SPFilter *
-new_filter_gaussian_blur (SPDocument *document, gdouble stdDeviation, double width, double height)
+new_filter_gaussian_blur (SPDocument *document, gdouble radius, double expansion, double width, double height)
{
g_return_val_if_fail(document != NULL, NULL);
@@ -38,12 +38,13 @@ new_filter_gaussian_blur (SPDocument *document, gdouble stdDeviation, double wid
repr = sp_repr_new("svg:filter");
repr->setAttribute("inkscape:collect", "always");
- if (width != 0 && height != 0 && (2 * stdDeviation > width * 0.1 || 2 * stdDeviation > height * 0.1)) {
+ if (width != 0 && height != 0 && (2 * radius > width * 0.1 || 2 * radius > height * 0.1)) {
// If not within the default 10% margin (see
// http://www.w3.org/TR/SVG11/filters.html#FilterEffectsRegion), specify margins
- double xmargin = 2 * stdDeviation / width;
- double ymargin = 2 * stdDeviation / height;
+ double xmargin = 2 * radius / width;
+ double ymargin = 2 * radius / height;
+ // TODO: set it in UserSpaceOnUse instead?
sp_repr_set_svg_double(repr, "x", -xmargin);
sp_repr_set_svg_double(repr, "width", 1 + 2 * xmargin);
sp_repr_set_svg_double(repr, "y", -ymargin);
b_repr = sp_repr_new("svg:feGaussianBlur");
b_repr->setAttribute("inkscape:collect", "always");
+ double stdDeviation = radius;
+ if (expansion != 0)
+ stdDeviation /= expansion;
+
//set stdDeviation attribute
sp_repr_set_svg_double(b_repr, "stdDeviation", stdDeviation);
return f;
}
+/**
+ * Creates a filter with blur primitive of specified radius for the given item
+ */
+SPFilter *
+new_filter_gaussian_blur_from_item (SPDocument *document, SPItem *item, gdouble radius)
+{
+ NR::Rect const r = sp_item_bbox_desktop(item);
+ double width = r.extent(NR::X);
+ double height = r.extent(NR::Y);
+
+ NR::Matrix i2d = sp_item_i2d_affine (item);
+
+ return (new_filter_gaussian_blur (document, radius, i2d.expansion(), width, height));
+}
+
void remove_filter (SPObject *item, bool recursive)
{
SPCSSAttr *css = sp_repr_css_attr_new ();
diff --git a/src/filter-chemistry.h b/src/filter-chemistry.h
index 4c6606fc08635073f86326d4c9490d242fa480f0..d575b7f1ebe706b430571744ad86edbadaac3562 100644 (file)
--- a/src/filter-chemistry.h
+++ b/src/filter-chemistry.h
#include "forward.h"
#include "sp-filter.h"
-SPFilter *new_filter_gaussian_blur (SPDocument *document, gdouble stdDeviation, double width, double height);
+SPFilter *new_filter_gaussian_blur (SPDocument *document, gdouble stdDeviation, double expansion, double width, double height);
+SPFilter *new_filter_gaussian_blur_from_item (SPDocument *document, SPItem *item, gdouble stdDeviation);
void remove_filter (SPObject *item, bool recursive);
#endif