~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/sp-femerge.cpp

  • Committer: Ted Gould
  • Date: 2008-11-21 05:24:08 UTC
  • Revision ID: ted@canonical.com-20081121052408-tilucis2pjrrpzxx
MergeĀ fromĀ fe-moved

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#define __SP_FEMERGE_CPP__
2
 
 
3
 
/** \file
4
 
 * SVG <feMerge> implementation.
5
 
 *
6
 
 */
7
 
/*
8
 
 * Authors:
9
 
 *   hugo Rodrigues <haa.rodrigues@gmail.com>
10
 
 *
11
 
 * Copyright (C) 2006 Hugo Rodrigues
12
 
 *
13
 
 * Released under GNU GPL, read the file 'COPYING' for more information
14
 
 */
15
 
 
16
 
#ifdef HAVE_CONFIG_H
17
 
# include "config.h"
18
 
#endif
19
 
 
20
 
#include "attributes.h"
21
 
#include "svg/svg.h"
22
 
#include "xml/repr.h"
23
 
 
24
 
#include "sp-femerge.h"
25
 
#include "sp-femergenode.h"
26
 
#include "display/nr-filter-merge.h"
27
 
 
28
 
/* FeMerge base class */
29
 
 
30
 
static void sp_feMerge_class_init(SPFeMergeClass *klass);
31
 
static void sp_feMerge_init(SPFeMerge *feMerge);
32
 
 
33
 
static void sp_feMerge_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
34
 
static void sp_feMerge_release(SPObject *object);
35
 
static void sp_feMerge_set(SPObject *object, unsigned int key, gchar const *value);
36
 
static void sp_feMerge_update(SPObject *object, SPCtx *ctx, guint flags);
37
 
static Inkscape::XML::Node *sp_feMerge_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
38
 
static void sp_feMerge_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter);
39
 
 
40
 
static SPFilterPrimitiveClass *feMerge_parent_class;
41
 
 
42
 
GType
43
 
sp_feMerge_get_type()
44
 
{
45
 
    static GType feMerge_type = 0;
46
 
 
47
 
    if (!feMerge_type) {
48
 
        GTypeInfo feMerge_info = {
49
 
            sizeof(SPFeMergeClass),
50
 
            NULL, NULL,
51
 
            (GClassInitFunc) sp_feMerge_class_init,
52
 
            NULL, NULL,
53
 
            sizeof(SPFeMerge),
54
 
            16,
55
 
            (GInstanceInitFunc) sp_feMerge_init,
56
 
            NULL,    /* value_table */
57
 
        };
58
 
        feMerge_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeMerge", &feMerge_info, (GTypeFlags)0);
59
 
    }
60
 
    return feMerge_type;
61
 
}
62
 
 
63
 
static void
64
 
sp_feMerge_class_init(SPFeMergeClass *klass)
65
 
{
66
 
    SPObjectClass *sp_object_class = (SPObjectClass *)klass;
67
 
    SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass;
68
 
 
69
 
    feMerge_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass);
70
 
 
71
 
    sp_object_class->build = sp_feMerge_build;
72
 
    sp_object_class->release = sp_feMerge_release;
73
 
    sp_object_class->write = sp_feMerge_write;
74
 
    sp_object_class->set = sp_feMerge_set;
75
 
    sp_object_class->update = sp_feMerge_update;
76
 
 
77
 
    sp_primitive_class->build_renderer = sp_feMerge_build_renderer;
78
 
}
79
 
 
80
 
static void
81
 
sp_feMerge_init(SPFeMerge */*feMerge*/)
82
 
{
83
 
}
84
 
 
85
 
/**
86
 
 * Reads the Inkscape::XML::Node, and initializes SPFeMerge variables.  For this to get called,
87
 
 * our name must be associated with a repr via "sp_object_type_register".  Best done through
88
 
 * sp-object-repr.cpp's repr_name_entries array.
89
 
 */
90
 
static void
91
 
sp_feMerge_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
92
 
{
93
 
    if (((SPObjectClass *) feMerge_parent_class)->build) {
94
 
        ((SPObjectClass *) feMerge_parent_class)->build(object, document, repr);
95
 
    }
96
 
 
97
 
    /*LOAD ATTRIBUTES FROM REPR HERE*/
98
 
}
99
 
 
100
 
/**
101
 
 * Drops any allocated memory.
102
 
 */
103
 
static void
104
 
sp_feMerge_release(SPObject *object)
105
 
{
106
 
    if (((SPObjectClass *) feMerge_parent_class)->release)
107
 
        ((SPObjectClass *) feMerge_parent_class)->release(object);
108
 
}
109
 
 
110
 
/**
111
 
 * Sets a specific value in the SPFeMerge.
112
 
 */
113
 
static void
114
 
sp_feMerge_set(SPObject *object, unsigned int key, gchar const *value)
115
 
{
116
 
    SPFeMerge *feMerge = SP_FEMERGE(object);
117
 
    (void)feMerge;
118
 
 
119
 
    switch(key) {
120
 
        /*DEAL WITH SETTING ATTRIBUTES HERE*/
121
 
        default:
122
 
            if (((SPObjectClass *) feMerge_parent_class)->set)
123
 
                ((SPObjectClass *) feMerge_parent_class)->set(object, key, value);
124
 
            break;
125
 
    }
126
 
 
127
 
}
128
 
 
129
 
/**
130
 
 * Receives update notifications.
131
 
 */
132
 
static void
133
 
sp_feMerge_update(SPObject *object, SPCtx *ctx, guint flags)
134
 
{
135
 
    if (flags & SP_OBJECT_MODIFIED_FLAG) {
136
 
        object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
137
 
    }
138
 
 
139
 
    if (((SPObjectClass *) feMerge_parent_class)->update) {
140
 
        ((SPObjectClass *) feMerge_parent_class)->update(object, ctx, flags);
141
 
    }
142
 
}
143
 
 
144
 
/**
145
 
 * Writes its settings to an incoming repr object, if any.
146
 
 */
147
 
static Inkscape::XML::Node *
148
 
sp_feMerge_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
149
 
{
150
 
    // Inkscape-only object, not copied during an "plain SVG" dump:
151
 
    if (flags & SP_OBJECT_WRITE_EXT) {
152
 
        if (repr) {
153
 
            // is this sane?
154
 
            //repr->mergeFrom(SP_OBJECT_REPR(object), "id");
155
 
        } else {
156
 
            repr = SP_OBJECT_REPR(object)->duplicate(doc);
157
 
        }
158
 
    }
159
 
 
160
 
    if (((SPObjectClass *) feMerge_parent_class)->write) {
161
 
        ((SPObjectClass *) feMerge_parent_class)->write(object, doc, repr, flags);
162
 
    }
163
 
 
164
 
    return repr;
165
 
}
166
 
 
167
 
static void sp_feMerge_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter) {
168
 
    g_assert(primitive != NULL);
169
 
    g_assert(filter != NULL);
170
 
 
171
 
    SPFeMerge *sp_merge = SP_FEMERGE(primitive);
172
 
    (void)sp_merge;
173
 
 
174
 
    int primitive_n = filter->add_primitive(NR::NR_FILTER_MERGE);
175
 
    NR::FilterPrimitive *nr_primitive = filter->get_primitive(primitive_n);
176
 
    NR::FilterMerge *nr_merge = dynamic_cast<NR::FilterMerge*>(nr_primitive);
177
 
    g_assert(nr_merge != NULL);
178
 
 
179
 
    sp_filter_primitive_renderer_common(primitive, nr_primitive);
180
 
 
181
 
    SPObject *input = primitive->children;
182
 
    int in_nr = 0;
183
 
    while (input) {
184
 
        if (SP_IS_FEMERGENODE(input)) {
185
 
            SPFeMergeNode *node = SP_FEMERGENODE(input);
186
 
            nr_merge->set_input(in_nr, node->input);
187
 
            in_nr++;
188
 
        }
189
 
        input = input->next;
190
 
    }
191
 
}
192
 
 
193
 
 
194
 
/*
195
 
  Local Variables:
196
 
  mode:c++
197
 
  c-file-style:"stroustrup"
198
 
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
199
 
  indent-tabs-mode:nil
200
 
  fill-column:99
201
 
  End:
202
 
*/
203
 
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :