summaryrefslogtreecommitdiffstats
path: root/src/sp-filter-primitive.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2014-04-01 17:00:00 +0000
committerJabiertxof <jtx@jtx.marker.es>2014-04-01 17:00:00 +0000
commit208ccdf9782984702f79b8ba416e67dd1e2c2dfa (patch)
tree79d15123aa526c49c6386db6245fbfc6b7a63eaf /src/sp-filter-primitive.cpp
parentupdate to trunk (diff)
parentpartial 2geom update: (diff)
downloadinkscape-208ccdf9782984702f79b8ba416e67dd1e2c2dfa.tar.gz
inkscape-208ccdf9782984702f79b8ba416e67dd1e2c2dfa.zip
update to trunk
(bzr r12588.1.32)
Diffstat (limited to 'src/sp-filter-primitive.cpp')
-rw-r--r--src/sp-filter-primitive.cpp100
1 files changed, 56 insertions, 44 deletions
diff --git a/src/sp-filter-primitive.cpp b/src/sp-filter-primitive.cpp
index f6b89bc21..ceb91c984 100644
--- a/src/sp-filter-primitive.cpp
+++ b/src/sp-filter-primitive.cpp
@@ -24,13 +24,14 @@
#include "sp-filter-primitive.h"
#include "xml/repr.h"
#include "sp-filter.h"
+#include "sp-item.h"
#include "display/nr-filter-primitive.h"
#include "display/nr-filter-types.h"
// CPPIFY: Make pure virtual.
//void SPFilterPrimitive::build_renderer(Inkscape::Filters::Filter* filter) {
- // throw;
+// throw;
//}
SPFilterPrimitive::SPFilterPrimitive() : SPObject() {
@@ -57,75 +58,72 @@ SPFilterPrimitive::~SPFilterPrimitive() {
* sp-object-repr.cpp's repr_name_entries array.
*/
void SPFilterPrimitive::build(SPDocument *document, Inkscape::XML::Node *repr) {
- SPFilterPrimitive* object = this;
+ SPFilterPrimitive* object = this;
object->readAttr( "style" ); // struct not derived from SPItem, we need to do this ourselves.
- object->readAttr( "in" );
- object->readAttr( "result" );
- object->readAttr( "x" );
- object->readAttr( "y" );
- object->readAttr( "width" );
- object->readAttr( "height" );
-
- SPObject::build(document, repr);
+ object->readAttr( "in" );
+ object->readAttr( "result" );
+ object->readAttr( "x" );
+ object->readAttr( "y" );
+ object->readAttr( "width" );
+ object->readAttr( "height" );
+
+ SPObject::build(document, repr);
}
/**
* Drops any allocated memory.
*/
void SPFilterPrimitive::release() {
- SPObject::release();
+ SPObject::release();
}
/**
* Sets a specific value in the SPFilterPrimitive.
*/
void SPFilterPrimitive::set(unsigned int key, gchar const *value) {
- SPFilterPrimitive* object = this;
- SPFilterPrimitive *filter_primitive = SP_FILTER_PRIMITIVE(object);
- (void)filter_primitive;
int image_nr;
switch (key) {
case SP_ATTR_IN:
if (value) {
- image_nr = sp_filter_primitive_read_in(filter_primitive, value);
+ image_nr = sp_filter_primitive_read_in(this, value);
} else {
image_nr = Inkscape::Filters::NR_FILTER_SLOT_NOT_SET;
}
- if (image_nr != filter_primitive->image_in) {
- filter_primitive->image_in = image_nr;
- object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ if (image_nr != this->image_in) {
+ this->image_in = image_nr;
+ this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
break;
case SP_ATTR_RESULT:
if (value) {
- image_nr = sp_filter_primitive_read_result(filter_primitive, value);
+ image_nr = sp_filter_primitive_read_result(this, value);
} else {
image_nr = Inkscape::Filters::NR_FILTER_SLOT_NOT_SET;
}
- if (image_nr != filter_primitive->image_out) {
- filter_primitive->image_out = image_nr;
- object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ if (image_nr != this->image_out) {
+ this->image_out = image_nr;
+ this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
break;
/* Filter primitive sub-region */
case SP_ATTR_X:
- filter_primitive->x.readOrUnset(value);
- object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ this->x.readOrUnset(value);
+ this->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_Y:
- filter_primitive->y.readOrUnset(value);
- object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ this->y.readOrUnset(value);
+ this->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_WIDTH:
- filter_primitive->width.readOrUnset(value);
- object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ this->width.readOrUnset(value);
+ this->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_HEIGHT:
- filter_primitive->height.readOrUnset(value);
- object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ this->height.readOrUnset(value);
+ this->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
}
@@ -137,19 +135,32 @@ void SPFilterPrimitive::set(unsigned int key, gchar const *value) {
* Receives update notifications.
*/
void SPFilterPrimitive::update(SPCtx *ctx, guint flags) {
- SPFilterPrimitive* object = this;
-
- //SPFilterPrimitive *filter_primitive = SP_FILTER_PRIMITIVE(object);
-
- // Is this required?
- if (flags & SP_OBJECT_MODIFIED_FLAG) {
- object->readAttr( "style" );
- object->readAttr( "in" );
- object->readAttr( "result" );
- object->readAttr( "x" );
- object->readAttr( "y" );
- object->readAttr( "width" );
- object->readAttr( "height" );
+
+ SPItemCtx *ictx = (SPItemCtx *) ctx;
+
+ // Do here since we know viewport (Bounding box case handled during rendering)
+ SPFilter *parent = SP_FILTER(this->parent);
+
+ if( parent->primitiveUnits == SP_FILTER_UNITS_USERSPACEONUSE ) {
+ if (this->x.unit == SVGLength::PERCENT) {
+ this->x._set = true;
+ this->x.computed = this->x.value * ictx->viewport.width();
+ }
+
+ if (this->y.unit == SVGLength::PERCENT) {
+ this->y._set = true;
+ this->y.computed = this->y.value * ictx->viewport.height();
+ }
+
+ if (this->width.unit == SVGLength::PERCENT) {
+ this->width._set = true;
+ this->width.computed = this->width.value * ictx->viewport.width();
+ }
+
+ if (this->height.unit == SVGLength::PERCENT) {
+ this->height._set = true;
+ this->height.computed = this->height.value * ictx->viewport.height();
+ }
}
SPObject::update(ctx, flags);
@@ -159,7 +170,7 @@ void SPFilterPrimitive::update(SPCtx *ctx, guint flags) {
* Writes its settings to an incoming repr object, if any.
*/
Inkscape::XML::Node* SPFilterPrimitive::write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) {
- SPFilterPrimitive* object = this;
+ SPFilterPrimitive* object = this;
SPFilterPrimitive *prim = SP_FILTER_PRIMITIVE(object);
SPFilter *parent = SP_FILTER(object->parent);
@@ -261,6 +272,7 @@ void sp_filter_primitive_renderer_common(SPFilterPrimitive *sp_prim, Inkscape::F
nr_prim->set_output(sp_prim->image_out);
/* TODO: place here code to handle input images, filter area etc. */
+ // We don't know current viewport or bounding box, this is wrong approach.
nr_prim->set_subregion( sp_prim->x, sp_prim->y, sp_prim->width, sp_prim->height );
// Give renderer access to filter properties