1
#define __SP_FECOLORMATRIX_CPP__
4
* SVG <feColorMatrix> implementation.
9
* Felipe Sanches <felipe.sanches@gmail.com>
10
* hugo Rodrigues <haa.rodrigues@gmail.com>
12
* Copyright (C) 2007 Felipe C. da S. Sanches
13
* Copyright (C) 2006 Hugo Rodrigues
15
* Released under GNU GPL, read the file 'COPYING' for more information
24
#include "attributes.h"
26
#include "colormatrix.h"
28
#include "helper-fns.h"
30
#include "display/nr-filter-colormatrix.h"
32
/* FeColorMatrix base class */
34
static void sp_feColorMatrix_class_init(SPFeColorMatrixClass *klass);
35
static void sp_feColorMatrix_init(SPFeColorMatrix *feColorMatrix);
37
static void sp_feColorMatrix_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
38
static void sp_feColorMatrix_release(SPObject *object);
39
static void sp_feColorMatrix_set(SPObject *object, unsigned int key, gchar const *value);
40
static void sp_feColorMatrix_update(SPObject *object, SPCtx *ctx, guint flags);
41
static Inkscape::XML::Node *sp_feColorMatrix_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
42
static void sp_feColorMatrix_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter);
44
static SPFilterPrimitiveClass *feColorMatrix_parent_class;
47
sp_feColorMatrix_get_type()
49
static GType feColorMatrix_type = 0;
51
if (!feColorMatrix_type) {
52
GTypeInfo feColorMatrix_info = {
53
sizeof(SPFeColorMatrixClass),
55
(GClassInitFunc) sp_feColorMatrix_class_init,
57
sizeof(SPFeColorMatrix),
59
(GInstanceInitFunc) sp_feColorMatrix_init,
60
NULL, /* value_table */
62
feColorMatrix_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeColorMatrix", &feColorMatrix_info, (GTypeFlags)0);
64
return feColorMatrix_type;
68
sp_feColorMatrix_class_init(SPFeColorMatrixClass *klass)
70
SPObjectClass *sp_object_class = (SPObjectClass *)klass;
71
SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass;
73
feColorMatrix_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass);
75
sp_object_class->build = sp_feColorMatrix_build;
76
sp_object_class->release = sp_feColorMatrix_release;
77
sp_object_class->write = sp_feColorMatrix_write;
78
sp_object_class->set = sp_feColorMatrix_set;
79
sp_object_class->update = sp_feColorMatrix_update;
80
sp_primitive_class->build_renderer = sp_feColorMatrix_build_renderer;
84
sp_feColorMatrix_init(SPFeColorMatrix */*feColorMatrix*/)
89
* Reads the Inkscape::XML::Node, and initializes SPFeColorMatrix variables. For this to get called,
90
* our name must be associated with a repr via "sp_object_type_register". Best done through
91
* sp-object-repr.cpp's repr_name_entries array.
94
sp_feColorMatrix_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
96
if (((SPObjectClass *) feColorMatrix_parent_class)->build) {
97
((SPObjectClass *) feColorMatrix_parent_class)->build(object, document, repr);
100
/*LOAD ATTRIBUTES FROM REPR HERE*/
101
sp_object_read_attr(object, "type");
102
sp_object_read_attr(object, "values");
106
* Drops any allocated memory.
109
sp_feColorMatrix_release(SPObject *object)
111
if (((SPObjectClass *) feColorMatrix_parent_class)->release)
112
((SPObjectClass *) feColorMatrix_parent_class)->release(object);
115
static NR::FilterColorMatrixType sp_feColorMatrix_read_type(gchar const *value){
116
if (!value) return NR::COLORMATRIX_MATRIX; //matrix is default
119
if (strcmp(value, "matrix") == 0) return NR::COLORMATRIX_MATRIX;
122
if (strcmp(value, "saturate") == 0) return NR::COLORMATRIX_SATURATE;
125
if (strcmp(value, "hueRotate") == 0) return NR::COLORMATRIX_HUEROTATE;
128
if (strcmp(value, "luminanceToAlpha") == 0) return NR::COLORMATRIX_LUMINANCETOALPHA;
131
return NR::COLORMATRIX_MATRIX; //matrix is default
135
* Sets a specific value in the SPFeColorMatrix.
138
sp_feColorMatrix_set(SPObject *object, unsigned int key, gchar const *str)
140
SPFeColorMatrix *feColorMatrix = SP_FECOLORMATRIX(object);
143
NR::FilterColorMatrixType read_type;
144
/*DEAL WITH SETTING ATTRIBUTES HERE*/
147
read_type = sp_feColorMatrix_read_type(str);
148
if (feColorMatrix->type != read_type){
149
feColorMatrix->type = read_type;
150
object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
155
feColorMatrix->values = helperfns_read_vector(str, 20);
156
feColorMatrix->value = helperfns_read_number(str, HELPERFNS_NO_WARNING);
157
object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
161
if (((SPObjectClass *) feColorMatrix_parent_class)->set)
162
((SPObjectClass *) feColorMatrix_parent_class)->set(object, key, str);
168
* Receives update notifications.
171
sp_feColorMatrix_update(SPObject *object, SPCtx *ctx, guint flags)
173
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
174
SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
176
/* do something to trigger redisplay, updates? */
180
if (((SPObjectClass *) feColorMatrix_parent_class)->update) {
181
((SPObjectClass *) feColorMatrix_parent_class)->update(object, ctx, flags);
186
* Writes its settings to an incoming repr object, if any.
188
static Inkscape::XML::Node *
189
sp_feColorMatrix_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
191
// Inkscape-only object, not copied during an "plain SVG" dump:
192
if (flags & SP_OBJECT_WRITE_EXT) {
195
//repr->mergeFrom(SP_OBJECT_REPR(object), "id");
197
repr = SP_OBJECT_REPR(object)->duplicate(doc);
201
if (((SPObjectClass *) feColorMatrix_parent_class)->write) {
202
((SPObjectClass *) feColorMatrix_parent_class)->write(object, doc, repr, flags);
208
static void sp_feColorMatrix_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter) {
209
g_assert(primitive != NULL);
210
g_assert(filter != NULL);
212
SPFeColorMatrix *sp_colormatrix = SP_FECOLORMATRIX(primitive);
214
int primitive_n = filter->add_primitive(NR::NR_FILTER_COLORMATRIX);
215
NR::FilterPrimitive *nr_primitive = filter->get_primitive(primitive_n);
216
NR::FilterColorMatrix *nr_colormatrix = dynamic_cast<NR::FilterColorMatrix*>(nr_primitive);
217
g_assert(nr_colormatrix != NULL);
219
sp_filter_primitive_renderer_common(primitive, nr_primitive);
220
nr_colormatrix->set_type(sp_colormatrix->type);
221
nr_colormatrix->set_value(sp_colormatrix->value);
222
nr_colormatrix->set_values(sp_colormatrix->values);
228
c-file-style:"stroustrup"
229
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
234
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :