/**
 * Sets a specific value in the SPFeFuncNode.
 */
static void
sp_fefuncnode_set(SPObject *object, unsigned int key, gchar const *value)
{
    SPFeFuncNode *feFuncNode = SP_FEFUNCNODE(object);
    Inkscape::Filters::FilterComponentTransferType type;
    double read_num;
    switch(key) {
    case SP_ATTR_TYPE:
        type = sp_feComponenttransfer_read_type(value);
        if(type != feFuncNode->type) {
            feFuncNode->type = type;
            object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
        }
        break;
    case SP_ATTR_TABLEVALUES:
        if (value) {
            feFuncNode->tableValues = helperfns_read_vector(value);
            object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
        }
        break;
    case SP_ATTR_SLOPE:
        read_num = value ? helperfns_read_number(value) : 1;
        if (read_num != feFuncNode->slope) {
            feFuncNode->slope = read_num;
            object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
        }
        break;
    case SP_ATTR_INTERCEPT:
        read_num = value ? helperfns_read_number(value) : 0;
        if (read_num != feFuncNode->intercept) {
            feFuncNode->intercept = read_num;
            object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
        }
        break;
    case SP_ATTR_AMPLITUDE:
        read_num = value ? helperfns_read_number(value) : 1;
        if (read_num != feFuncNode->amplitude) {
            feFuncNode->amplitude = read_num;
            object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
        }
        break;
    case SP_ATTR_EXPONENT:
        read_num = value ? helperfns_read_number(value) : 1;
        if (read_num != feFuncNode->exponent) {
            feFuncNode->exponent = read_num;
            object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
        }
        break;
    case SP_ATTR_OFFSET:
        read_num = value ? helperfns_read_number(value) : 0;
        if (read_num != feFuncNode->offset) {
            feFuncNode->offset = read_num;
            object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
        }
        break;
    default:
        if (((SPObjectClass *) feFuncNode_parent_class)->set)
            ((SPObjectClass *) feFuncNode_parent_class)->set(object, key, value);
        break;
    }
}
Exemplo n.º 2
0
/**
 * Sets a specific value in the SPFeConvolveMatrix.
 */
void SPFeConvolveMatrix::set(unsigned int key, gchar const *value) {
    double read_num;
    int read_int;
    bool read_bool;
    Inkscape::Filters::FilterConvolveMatrixEdgeMode read_mode;
   
    switch(key) {
	/*DEAL WITH SETTING ATTRIBUTES HERE*/
        case SP_ATTR_ORDER:
            this->order.set(value);
            
            //From SVG spec: If <orderY> is not provided, it defaults to <orderX>.
            if (this->order.optNumIsSet() == false) {
                this->order.setOptNumber(this->order.getNumber());
            }
            
            if (this->targetXIsSet == false) {
            	this->targetX = (int) floor(this->order.getNumber()/2);
            }
            
            if (this->targetYIsSet == false) {
            	this->targetY = (int) floor(this->order.getOptNumber()/2);
            }
            
            this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
            break;
        case SP_ATTR_KERNELMATRIX:
            if (value){
                this->kernelMatrixIsSet = true;
                this->kernelMatrix = helperfns_read_vector(value);
                
                if (! this->divisorIsSet) {
                    this->divisor = 0;
                    
                    for (unsigned int i = 0; i< this->kernelMatrix.size(); i++) {
                        this->divisor += this->kernelMatrix[i];
                    }
                    
                    if (this->divisor == 0) {
                    	this->divisor = 1;
                    }
                }
                
                this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
            } else {
                g_warning("For feConvolveMatrix you MUST pass a kernelMatrix parameter!");
            }
            break;
        case SP_ATTR_DIVISOR:
            if (value) { 
                read_num = helperfns_read_number(value);
                
                if (read_num == 0) {
                    // This should actually be an error, but given our UI it is more useful to simply set divisor to the default.
                    if (this->kernelMatrixIsSet) {
                        for (unsigned int i = 0; i< this->kernelMatrix.size(); i++) {
                            read_num += this->kernelMatrix[i];
                        }
                    }
                    
                    if (read_num == 0) {
                    	read_num = 1;
                    }
                    
                    if (this->divisorIsSet || this->divisor!=read_num) {
                        this->divisorIsSet = false;
                        this->divisor = read_num;
                        this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
                    }
                } else if (!this->divisorIsSet || this->divisor!=read_num) {
                    this->divisorIsSet = true;
                    this->divisor = read_num;
                    this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
                }
            }
            break;
        case SP_ATTR_BIAS:
            read_num = 0;
            if (value) {
            	read_num = helperfns_read_number(value);
            }
            
            if (read_num != this->bias){
                this->bias = read_num;
                this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
            }
            break;
        case SP_ATTR_TARGETX:
            if (value) {
                read_int = (int) helperfns_read_number(value);
                
                if (read_int < 0 || read_int > this->order.getNumber()){
                    g_warning("targetX must be a value between 0 and orderX! Assuming floor(orderX/2) as default value.");
                    read_int = (int) floor(this->order.getNumber()/2.0);
                }
                
                this->targetXIsSet = true;
                
                if (read_int != this->targetX){
                    this->targetX = read_int;
                    this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
                }
            }
            break;
        case SP_ATTR_TARGETY:
            if (value) {
                read_int = (int) helperfns_read_number(value);
                
                if (read_int < 0 || read_int > this->order.getOptNumber()){
                    g_warning("targetY must be a value between 0 and orderY! Assuming floor(orderY/2) as default value.");
                    read_int = (int) floor(this->order.getOptNumber()/2.0);
                }
                
                this->targetYIsSet = true;
                
                if (read_int != this->targetY){
                    this->targetY = read_int;
                    this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
                }
            }
            break;
        case SP_ATTR_EDGEMODE:
            read_mode = sp_feConvolveMatrix_read_edgeMode(value);
            
            if (read_mode != this->edgeMode){
                this->edgeMode = read_mode;
                this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
            }
            break;
        case SP_ATTR_KERNELUNITLENGTH:
            this->kernelUnitLength.set(value);
            
            //From SVG spec: If the <dy> value is not specified, it defaults to the same value as <dx>.
            if (this->kernelUnitLength.optNumIsSet() == false) {
                this->kernelUnitLength.setOptNumber(this->kernelUnitLength.getNumber());
            }
            
            this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
            break;
        case SP_ATTR_PRESERVEALPHA:
            read_bool = helperfns_read_bool(value, false);
            
            if (read_bool != this->preserveAlpha){
                this->preserveAlpha = read_bool;
                this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
            }
            break;
        default:
        	SPFilterPrimitive::set(key, value);
            break;
    }

}
/**
 * Sets a specific value in the SPFeFuncNode.
 */
void SPFeFuncNode::set(unsigned int key, gchar const *value) {
    Inkscape::Filters::FilterComponentTransferType type;
    double read_num;

    switch(key) {
        case SP_ATTR_TYPE:
            type = sp_feComponenttransfer_read_type(value);

            if(type != this->type) {
                this->type = type;
                this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
            }
            break;
        case SP_ATTR_TABLEVALUES:
            if (value){
                this->tableValues = helperfns_read_vector(value);
                this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
            }
            break;
        case SP_ATTR_SLOPE:
            read_num = value ? helperfns_read_number(value) : 1;

            if (read_num != this->slope) {
                this->slope = read_num;
                this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
            }
            break;
        case SP_ATTR_INTERCEPT:
            read_num = value ? helperfns_read_number(value) : 0;

            if (read_num != this->intercept) {
                this->intercept = read_num;
                this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
            }
            break;
        case SP_ATTR_AMPLITUDE:
            read_num = value ? helperfns_read_number(value) : 1;

            if (read_num != this->amplitude) {
                this->amplitude = read_num;
                this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
            }
            break;
        case SP_ATTR_EXPONENT:
            read_num = value ? helperfns_read_number(value) : 1;

            if (read_num != this->exponent) {
                this->exponent = read_num;
                this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
            }
            break;
        case SP_ATTR_OFFSET:
            read_num = value ? helperfns_read_number(value) : 0;

            if (read_num != this->offset) {
                this->offset = read_num;
                this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
            }
            break;
        default:
        	SPObject::set(key, value);
            break;
    }
}