X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Ffilter-chemistry.cpp;h=d6900b1f675ae8f28cffe0b598d8b0a42598cbcc;hb=c7cf14ac71346f76ae219ce67fb88c1bd34832e2;hp=58e2fae6efab6042e78925f1f498dcc1d68a7486;hpb=ce2b2419b56b38d08c79720b2278f4b27e61d175;p=inkscape.git diff --git a/src/filter-chemistry.cpp b/src/filter-chemistry.cpp index 58e2fae6e..d6900b1f6 100644 --- a/src/filter-chemistry.cpp +++ b/src/filter-chemistry.cpp @@ -1,5 +1,3 @@ -#define __SP_FILTER_CHEMISTRY_C__ - /* * Various utility methods for filters * @@ -7,8 +5,10 @@ * Hugo Rodrigues * bulia byak * Niko Kiirala + * Jon A. Cruz + * Abhishek Sharma * - * Copyright (C) 2006,2007 authors + * Copyright (C) 2006-2008 authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -21,7 +21,7 @@ #include "filter-chemistry.h" #include "filter-enums.h" -#include "sp-feblend.h" +#include "filters/blend.h" #include "sp-filter.h" #include "sp-filter-reference.h" #include "sp-gaussian-blur.h" @@ -34,8 +34,7 @@ * Count how many times the filter is used by the styles of o and its * descendants */ -static guint -count_filter_hrefs(SPObject *o, SPFilter *filter) +static guint count_filter_hrefs(SPObject *o, SPFilter *filter) { if (!o) return 1; @@ -50,8 +49,7 @@ count_filter_hrefs(SPObject *o, SPFilter *filter) i ++; } - for (SPObject *child = sp_object_first_child(o); - child != NULL; child = SP_OBJECT_NEXT(child)) { + for ( SPObject *child = o->firstChild(); child; child = child->getNext() ) { i += count_filter_hrefs(child, filter); } @@ -94,14 +92,14 @@ SPFilter *new_filter(SPDocument *document) SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document); - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document); + Inkscape::XML::Document *xml_doc = document->getReprDoc(); // create a new filter Inkscape::XML::Node *repr; repr = xml_doc->createElement("svg:filter"); // Append the new filter node to defs - SP_OBJECT_REPR(defs)->appendChild(repr); + defs->appendChild(repr); Inkscape::GC::release(repr); // get corresponding object @@ -115,9 +113,9 @@ SPFilter *new_filter(SPDocument *document) } SPFilterPrimitive * -filter_add_primitive(SPFilter *filter, const NR::FilterPrimitiveType type) +filter_add_primitive(SPFilter *filter, const Inkscape::Filters::FilterPrimitiveType type) { - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(filter->document); + Inkscape::XML::Document *xml_doc = filter->document->getReprDoc(); //create filter primitive node Inkscape::XML::Node *repr; @@ -125,50 +123,51 @@ filter_add_primitive(SPFilter *filter, const NR::FilterPrimitiveType type) // set default values switch(type) { - case NR::NR_FILTER_BLEND: + case Inkscape::Filters::NR_FILTER_BLEND: repr->setAttribute("blend", "normal"); break; - case NR::NR_FILTER_COLORMATRIX: + case Inkscape::Filters::NR_FILTER_COLORMATRIX: break; - case NR::NR_FILTER_COMPONENTTRANSFER: + case Inkscape::Filters::NR_FILTER_COMPONENTTRANSFER: break; - case NR::NR_FILTER_COMPOSITE: + case Inkscape::Filters::NR_FILTER_COMPOSITE: break; - case NR::NR_FILTER_CONVOLVEMATRIX: + case Inkscape::Filters::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: + case Inkscape::Filters::NR_FILTER_DIFFUSELIGHTING: break; - case NR::NR_FILTER_DISPLACEMENTMAP: + case Inkscape::Filters::NR_FILTER_DISPLACEMENTMAP: break; - case NR::NR_FILTER_FLOOD: + case Inkscape::Filters::NR_FILTER_FLOOD: break; - case NR::NR_FILTER_GAUSSIANBLUR: + case Inkscape::Filters::NR_FILTER_GAUSSIANBLUR: repr->setAttribute("stdDeviation", "1"); break; - case NR::NR_FILTER_IMAGE: + case Inkscape::Filters::NR_FILTER_IMAGE: break; - case NR::NR_FILTER_MERGE: + case Inkscape::Filters::NR_FILTER_MERGE: break; - case NR::NR_FILTER_MORPHOLOGY: + case Inkscape::Filters::NR_FILTER_MORPHOLOGY: break; - case NR::NR_FILTER_OFFSET: + case Inkscape::Filters::NR_FILTER_OFFSET: repr->setAttribute("dx", "0"); repr->setAttribute("dy", "0"); break; - case NR::NR_FILTER_SPECULARLIGHTING: + case Inkscape::Filters::NR_FILTER_SPECULARLIGHTING: break; - case NR::NR_FILTER_TILE: + case Inkscape::Filters::NR_FILTER_TILE: break; - case NR::NR_FILTER_TURBULENCE: + case Inkscape::Filters::NR_FILTER_TURBULENCE: break; default: break; } //set primitive as child of filter node - filter->repr->appendChild(repr); + // XML tree being used directly while/where it shouldn't be... + filter->appendChild(repr); Inkscape::GC::release(repr); // get corresponding object @@ -190,7 +189,7 @@ new_filter_gaussian_blur (SPDocument *document, gdouble radius, double expansion SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document); - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document); + Inkscape::XML::Document *xml_doc = document->getReprDoc(); // create a new filter Inkscape::XML::Node *repr; @@ -217,7 +216,7 @@ new_filter_gaussian_blur (SPDocument *document, gdouble radius, double expansion Inkscape::GC::release(b_repr); // Append the new filter node to defs - SP_OBJECT_REPR(defs)->appendChild(repr); + defs->appendChild(repr); Inkscape::GC::release(repr); // get corresponding object @@ -245,7 +244,7 @@ new_filter_blend_gaussian_blur (SPDocument *document, const char *blendmode, gdo SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document); - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document); + Inkscape::XML::Document *xml_doc = document->getReprDoc(); // create a new filter Inkscape::XML::Node *repr; @@ -253,7 +252,7 @@ new_filter_blend_gaussian_blur (SPDocument *document, const char *blendmode, gdo repr->setAttribute("inkscape:collect", "always"); // Append the new filter node to defs - SP_OBJECT_REPR(defs)->appendChild(repr); + defs->appendChild(repr); Inkscape::GC::release(repr); // get corresponding object @@ -319,20 +318,20 @@ 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, SPItem::GEOMETRIC_BBOX); + Geom::OptRect const r = item->getBboxDesktop(SPItem::GEOMETRIC_BBOX); double width; double height; if (r) { - width = r->extent(NR::X); - height= r->extent(NR::Y); + width = r->dimensions()[Geom::X]; + height= r->dimensions()[Geom::Y]; } else { width = height = 0; } - NR::Matrix i2d = sp_item_i2d_affine (item); + Geom::Matrix i2d (item->i2d_affine () ); - return (new_filter_blend_gaussian_blur (document, mode, radius, NR::expansion(i2d), NR::expansionX(i2d), NR::expansionY(i2d), width, height)); + return (new_filter_blend_gaussian_blur (document, mode, radius, i2d.descrim(), i2d.expansionX(), i2d.expansionY(), width, height)); } /** @@ -344,50 +343,48 @@ new_filter_simple_from_item (SPDocument *document, SPItem *item, const char *mod * duplicated, so that other elements referring that filter are not modified. */ /* TODO: this should be made more generic, not just for blurs */ -SPFilter * -modify_filter_gaussian_blur_from_item(SPDocument *document, SPItem *item, - gdouble radius) +SPFilter *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->getFilter()); - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document); + Inkscape::XML::Document *xml_doc = document->getReprDoc(); // 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->getFilter())->duplicate(xml_doc); + if (filter->hrefcount > count_filter_hrefs(item, filter)) { + Inkscape::XML::Node *repr = SP_OBJECT_REPR(item->style->getFilter())->duplicate(xml_doc); SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document); - SP_OBJECT_REPR(defs)->appendChild(repr); + defs->appendChild(repr); filter = SP_FILTER( document->getObjectByRepr(repr) ); Inkscape::GC::release(repr); } // Determine the required standard deviation value - NR::Matrix i2d = sp_item_i2d_affine (item); - double expansion = NR::expansion(i2d); + Geom::Matrix i2d (item->i2d_affine ()); + double expansion = i2d.descrim(); double stdDeviation = radius; if (expansion != 0) stdDeviation /= expansion; // Get the object size - NR::Maybe const r = sp_item_bbox_desktop(item, SPItem::GEOMETRIC_BBOX); + Geom::OptRect const r = item->getBboxDesktop(SPItem::GEOMETRIC_BBOX); double width; double height; if (r) { - width = r->extent(NR::X); - height= r->extent(NR::Y); + width = r->dimensions()[Geom::X]; + height= r->dimensions()[Geom::Y]; } else { width = height = 0; } // Set the filter effects area Inkscape::XML::Node *repr = SP_OBJECT_REPR(item->style->getFilter()); - set_filter_area(repr, radius, expansion, NR::expansionX(i2d), - NR::expansionY(i2d), width, height); + set_filter_area(repr, radius, expansion, i2d.expansionX(), + i2d.expansionY(), width, height); // Search for gaussian blur primitives. If found, set the stdDeviation // of the first one and return. @@ -478,6 +475,7 @@ double get_single_gaussian_blur_radius(SPFilter *filter) } return x; } + return 0.0; } @@ -491,4 +489,4 @@ double get_single_gaussian_blur_radius(SPFilter *filter) fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :