summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbulia byak <buliabyak@gmail.com>2006-10-23 01:44:48 +0000
committerbuliabyak <buliabyak@users.sourceforge.net>2006-10-23 01:44:48 +0000
commitfc917ac5847d6f728178367295e93dd7ac3331f1 (patch)
treecf05d6c8f5ef18daa5a2178c7d912949071d2609
parentFix msgstr[0/1] problem. (diff)
downloadinkscape-fc917ac5847d6f728178367295e93dd7ac3331f1.tar.gz
inkscape-fc917ac5847d6f728178367295e93dd7ac3331f1.zip
change API: separate functions creating a blur filter, one for a given item, another from the given matrix expansion and w/h
(bzr r1839)
-rw-r--r--src/filter-chemistry.cpp30
-rw-r--r--src/filter-chemistry.h3
2 files changed, 27 insertions, 6 deletions
diff --git a/src/filter-chemistry.cpp b/src/filter-chemistry.cpp
index e18e54ed6..3c27b6edc 100644
--- a/src/filter-chemistry.cpp
+++ b/src/filter-chemistry.cpp
@@ -24,10 +24,10 @@
#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);
@@ -55,6 +56,10 @@ new_filter_gaussian_blur (SPDocument *document, gdouble stdDeviation, double wid
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);
@@ -78,6 +83,21 @@ new_filter_gaussian_blur (SPDocument *document, gdouble stdDeviation, double wid
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 4c6606fc0..d575b7f1e 100644
--- a/src/filter-chemistry.h
+++ b/src/filter-chemistry.h
@@ -16,7 +16,8 @@
#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