X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Ffilter-chemistry.cpp;h=90151d6d20135dc84eb2f8e85bab6e0abdcdb9ee;hb=b2e46b1363564aa72394ee2feb6a5a6cb49194a5;hp=d3a02852eed3b2f5ecbbf12d23bae703dd2bf2e2;hpb=2be579ebe9adb75296037faf3ed89d7a5f25bbbd;p=inkscape.git diff --git a/src/filter-chemistry.cpp b/src/filter-chemistry.cpp index d3a02852e..90151d6d2 100644 --- a/src/filter-chemistry.cpp +++ b/src/filter-chemistry.cpp @@ -18,10 +18,15 @@ #include "document-private.h" #include "desktop-style.h" +#include "filter-chemistry.h" +#include "filter-enums.h" + #include "sp-feblend.h" #include "sp-filter.h" +#include "sp-filter-reference.h" #include "sp-gaussian-blur.h" #include "svg/css-ostringstream.h" +#include "libnr/nr-matrix-fns.h" #include "xml/repr.h" @@ -40,7 +45,7 @@ count_filter_hrefs(SPObject *o, SPFilter *filter) SPStyle *style = SP_OBJECT_STYLE(o); if (style && style->filter.set - && style->filter.filter == filter) + && style->getFilter() == filter) { i ++; } @@ -110,14 +115,57 @@ SPFilter *new_filter(SPDocument *document) } SPFilterPrimitive * -filter_add_primitive(SPFilter *filter, const gchar *type) +filter_add_primitive(SPFilter *filter, const NR::FilterPrimitiveType type) { Inkscape::XML::Document *xml_doc = sp_document_repr_doc(filter->document); //create filter primitive node Inkscape::XML::Node *repr; - repr = xml_doc->createElement(type); - repr->setAttribute("inkscape:collect", "always"); + repr = xml_doc->createElement(FPConverter.get_key(type).c_str()); + + // set default values + switch(type) { + case NR::NR_FILTER_BLEND: + repr->setAttribute("blend", "normal"); + break; + case NR::NR_FILTER_COLORMATRIX: + break; + case NR::NR_FILTER_COMPONENTTRANSFER: + break; + case NR::NR_FILTER_COMPOSITE: + break; + case NR::NR_FILTER_CONVOLVEMATRIX: + repr->setAttribute("order", "3 3"); + repr->setAttribute("kernelMatrix", "0 0 0 0 0 0 0 0 0"); + break; + case NR::NR_FILTER_DIFFUSELIGHTING: + break; + case NR::NR_FILTER_DISPLACEMENTMAP: + break; + case NR::NR_FILTER_FLOOD: + break; + case NR::NR_FILTER_GAUSSIANBLUR: + repr->setAttribute("stdDeviation", "1"); + break; + case NR::NR_FILTER_IMAGE: + break; + case NR::NR_FILTER_MERGE: + break; + case NR::NR_FILTER_MORPHOLOGY: + break; + case NR::NR_FILTER_OFFSET: + repr->setAttribute("dx", "0"); + repr->setAttribute("dy", "0"); + break; + case NR::NR_FILTER_SPECULARLIGHTING: + break; + case NR::NR_FILTER_TILE: + break; + case NR::NR_FILTER_TURBULENCE: + break; + default: + break; + } //set primitive as child of filter node filter->repr->appendChild(repr); @@ -271,7 +319,7 @@ new_filter_blend_gaussian_blur (SPDocument *document, const char *blendmode, gdo SPFilter * new_filter_simple_from_item (SPDocument *document, SPItem *item, const char *mode, gdouble radius) { - NR::Maybe const r = sp_item_bbox_desktop(item); + NR::Maybe const r = sp_item_bbox_desktop(item, SPItem::GEOMETRIC_BBOX); double width; double height; @@ -282,9 +330,9 @@ new_filter_simple_from_item (SPDocument *document, SPItem *item, const char *mod width = height = 0; } - NR::Matrix i2d = sp_item_i2d_affine (item); + NR::Matrix i2d = from_2geom(sp_item_i2d_affine (item) ); - return (new_filter_blend_gaussian_blur (document, mode, radius, i2d.expansion(), i2d.expansionX(), i2d.expansionY(), width, height)); + return (new_filter_blend_gaussian_blur (document, mode, radius, NR::expansion(i2d), NR::expansionX(i2d), NR::expansionY(i2d), width, height)); } /** @@ -301,16 +349,16 @@ modify_filter_gaussian_blur_from_item(SPDocument *document, SPItem *item, gdouble radius) { if (!item->style || !item->style->filter.set) { - //return new_filter_gaussian_blur_from_item(document, item, radius); + return new_filter_simple_from_item(document, item, "normal", radius); } - SPFilter *filter = SP_FILTER(item->style->filter.filter); + SPFilter *filter = SP_FILTER(item->style->getFilter()); Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document); // If there are more users for this filter, duplicate it if (SP_OBJECT_HREFCOUNT(filter) > count_filter_hrefs(item, filter)) { Inkscape::XML::Node *repr; - repr = SP_OBJECT_REPR(item->style->filter.filter)->duplicate(xml_doc); + repr = SP_OBJECT_REPR(item->style->getFilter())->duplicate(xml_doc); SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document); SP_OBJECT_REPR(defs)->appendChild(repr); @@ -319,14 +367,14 @@ modify_filter_gaussian_blur_from_item(SPDocument *document, SPItem *item, } // Determine the required standard deviation value - NR::Matrix i2d = sp_item_i2d_affine (item); - double expansion = i2d.expansion(); + NR::Matrix i2d = from_2geom(sp_item_i2d_affine (item)); + double expansion = NR::expansion(i2d); double stdDeviation = radius; if (expansion != 0) stdDeviation /= expansion; // Get the object size - NR::Maybe const r = sp_item_bbox_desktop(item); + NR::Maybe const r = sp_item_bbox_desktop(item, SPItem::GEOMETRIC_BBOX); double width; double height; if (r) { @@ -337,9 +385,9 @@ modify_filter_gaussian_blur_from_item(SPDocument *document, SPItem *item, } // Set the filter effects area - Inkscape::XML::Node *repr = SP_OBJECT_REPR(item->style->filter.filter); - set_filter_area(repr, radius, expansion, i2d.expansionX(), - i2d.expansionY(), width, height); + Inkscape::XML::Node *repr = SP_OBJECT_REPR(item->style->getFilter()); + set_filter_area(repr, radius, expansion, NR::expansionX(i2d), + NR::expansionY(i2d), width, height); // Search for gaussian blur primitives. If found, set the stdDeviation // of the first one and return. @@ -390,9 +438,9 @@ void remove_filter (SPObject *item, bool recursive) * be handled gracefully */ void remove_filter_gaussian_blur (SPObject *item) { - if (item->style && item->style->filter.set && item->style->filter.filter) { + if (item->style && item->style->filter.set && item->style->getFilter()) { // Search for the first blur primitive and remove it. (if found) - Inkscape::XML::Node *repr = SP_OBJECT_REPR(item->style->filter.filter); + Inkscape::XML::Node *repr = SP_OBJECT_REPR(item->style->getFilter()); Inkscape::XML::Node *primitive = repr->firstChild(); while (primitive) { if (strcmp("svg:feGaussianBlur", primitive->name()) == 0) { @@ -409,6 +457,32 @@ void remove_filter_gaussian_blur (SPObject *item) } } +bool filter_is_single_gaussian_blur(SPFilter *filter) +{ + return (SP_OBJECT(filter)->firstChild() && + SP_OBJECT(filter)->firstChild() == SP_OBJECT(filter)->lastChild() && + SP_IS_GAUSSIANBLUR(SP_OBJECT(filter)->firstChild())); +} + +double get_single_gaussian_blur_radius(SPFilter *filter) +{ + if (SP_OBJECT(filter)->firstChild() && + SP_OBJECT(filter)->firstChild() == SP_OBJECT(filter)->lastChild() && + SP_IS_GAUSSIANBLUR(SP_OBJECT(filter)->firstChild())) { + + SPGaussianBlur *gb = SP_GAUSSIANBLUR(SP_OBJECT(filter)->firstChild()); + double x = gb->stdDeviation.getNumber(); + double y = gb->stdDeviation.getOptNumber(); + if (x > 0 && y > 0) { + return MAX(x, y); + } + return x; + } + return 0.0; +} + + + /* Local Variables: mode:c++