~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/filters/flood.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define __SP_FEFLOOD_CPP__
 
2
 
 
3
/** \file
 
4
 * SVG <feFlood> 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 "flood.h"
 
23
#include "xml/repr.h"
 
24
#include "helper-fns.h"
 
25
#include "svg/svg-color.h"
 
26
 
 
27
/* FeFlood base class */
 
28
 
 
29
static void sp_feFlood_class_init(SPFeFloodClass *klass);
 
30
static void sp_feFlood_init(SPFeFlood *feFlood);
 
31
 
 
32
static void sp_feFlood_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
 
33
static void sp_feFlood_release(SPObject *object);
 
34
static void sp_feFlood_set(SPObject *object, unsigned int key, gchar const *value);
 
35
static void sp_feFlood_update(SPObject *object, SPCtx *ctx, guint flags);
 
36
static Inkscape::XML::Node *sp_feFlood_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
 
37
static void sp_feFlood_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter);
 
38
 
 
39
static SPFilterPrimitiveClass *feFlood_parent_class;
 
40
 
 
41
GType
 
42
sp_feFlood_get_type()
 
43
{
 
44
    static GType feFlood_type = 0;
 
45
 
 
46
    if (!feFlood_type) {
 
47
        GTypeInfo feFlood_info = {
 
48
            sizeof(SPFeFloodClass),
 
49
            NULL, NULL,
 
50
            (GClassInitFunc) sp_feFlood_class_init,
 
51
            NULL, NULL,
 
52
            sizeof(SPFeFlood),
 
53
            16,
 
54
            (GInstanceInitFunc) sp_feFlood_init,
 
55
            NULL,    /* value_table */
 
56
        };
 
57
        feFlood_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeFlood", &feFlood_info, (GTypeFlags)0);
 
58
    }
 
59
    return feFlood_type;
 
60
}
 
61
 
 
62
static void
 
63
sp_feFlood_class_init(SPFeFloodClass *klass)
 
64
{
 
65
    SPObjectClass *sp_object_class = (SPObjectClass *)klass;
 
66
    SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass;
 
67
 
 
68
    feFlood_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass);
 
69
 
 
70
    sp_object_class->build = sp_feFlood_build;
 
71
    sp_object_class->release = sp_feFlood_release;
 
72
    sp_object_class->write = sp_feFlood_write;
 
73
    sp_object_class->set = sp_feFlood_set;
 
74
    sp_object_class->update = sp_feFlood_update;
 
75
    sp_primitive_class->build_renderer = sp_feFlood_build_renderer;
 
76
}
 
77
 
 
78
static void
 
79
sp_feFlood_init(SPFeFlood *feFlood)
 
80
{
 
81
    feFlood->opacity = 1;
 
82
}
 
83
 
 
84
/**
 
85
 * Reads the Inkscape::XML::Node, and initializes SPFeFlood variables.  For this to get called,
 
86
 * our name must be associated with a repr via "sp_object_type_register".  Best done through
 
87
 * sp-object-repr.cpp's repr_name_entries array.
 
88
 */
 
89
static void
 
90
sp_feFlood_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
 
91
{
 
92
    if (((SPObjectClass *) feFlood_parent_class)->build) {
 
93
        ((SPObjectClass *) feFlood_parent_class)->build(object, document, repr);
 
94
    }
 
95
 
 
96
    /*LOAD ATTRIBUTES FROM REPR HERE*/
 
97
    sp_object_read_attr(object, "flood-opacity");
 
98
    sp_object_read_attr(object, "flood-color");
 
99
}
 
100
 
 
101
/**
 
102
 * Drops any allocated memory.
 
103
 */
 
104
static void
 
105
sp_feFlood_release(SPObject *object)
 
106
{
 
107
    if (((SPObjectClass *) feFlood_parent_class)->release)
 
108
        ((SPObjectClass *) feFlood_parent_class)->release(object);
 
109
}
 
110
 
 
111
/**
 
112
 * Sets a specific value in the SPFeFlood.
 
113
 */
 
114
static void
 
115
sp_feFlood_set(SPObject *object, unsigned int key, gchar const *value)
 
116
{
 
117
    SPFeFlood *feFlood = SP_FEFLOOD(object);
 
118
    (void)feFlood;
 
119
    gchar const *cend_ptr = NULL;
 
120
    gchar *end_ptr = NULL;
 
121
    guint32 read_color;
 
122
    double read_num;
 
123
    
 
124
    switch(key) {
 
125
        /*DEAL WITH SETTING ATTRIBUTES HERE*/
 
126
        case SP_PROP_FLOOD_COLOR:
 
127
            cend_ptr = NULL;
 
128
            read_color = sp_svg_read_color(value, &cend_ptr, 0xffffffff);
 
129
            if (cend_ptr && read_color != feFlood->color){
 
130
                feFlood->color = read_color;
 
131
                object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
132
            }
 
133
            break;
 
134
        case SP_PROP_FLOOD_OPACITY:
 
135
            if (value) {
 
136
                read_num = g_ascii_strtod(value, &end_ptr);
 
137
                if (*end_ptr) {
 
138
                    g_warning("Unable to convert \"%s\" to number", value);
 
139
                    read_num = 1;
 
140
                }
 
141
            }
 
142
            else {
 
143
                read_num = 1;
 
144
            }
 
145
            if (read_num != feFlood->opacity){
 
146
                feFlood->opacity = read_num;
 
147
                object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
148
            }
 
149
            break;
 
150
        default:
 
151
            if (((SPObjectClass *) feFlood_parent_class)->set)
 
152
                ((SPObjectClass *) feFlood_parent_class)->set(object, key, value);
 
153
            break;
 
154
    }
 
155
 
 
156
}
 
157
 
 
158
/**
 
159
 * Receives update notifications.
 
160
 */
 
161
static void
 
162
sp_feFlood_update(SPObject *object, SPCtx *ctx, guint flags)
 
163
{
 
164
    if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
 
165
                 SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
 
166
 
 
167
        /* do something to trigger redisplay, updates? */
 
168
 
 
169
    }
 
170
 
 
171
    if (((SPObjectClass *) feFlood_parent_class)->update) {
 
172
        ((SPObjectClass *) feFlood_parent_class)->update(object, ctx, flags);
 
173
    }
 
174
}
 
175
 
 
176
/**
 
177
 * Writes its settings to an incoming repr object, if any.
 
178
 */
 
179
static Inkscape::XML::Node *
 
180
sp_feFlood_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
 
181
{
 
182
    /* TODO: Don't just clone, but create a new repr node and write all
 
183
     * relevant values into it */
 
184
    if (!repr) {
 
185
        repr = SP_OBJECT_REPR(object)->duplicate(doc);
 
186
    }
 
187
 
 
188
    if (((SPObjectClass *) feFlood_parent_class)->write) {
 
189
        ((SPObjectClass *) feFlood_parent_class)->write(object, doc, repr, flags);
 
190
    }
 
191
 
 
192
    return repr;
 
193
}
 
194
 
 
195
static void sp_feFlood_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter) {
 
196
    g_assert(primitive != NULL);
 
197
    g_assert(filter != NULL);
 
198
 
 
199
    SPFeFlood *sp_flood = SP_FEFLOOD(primitive);
 
200
    (void)sp_flood;
 
201
 
 
202
    int primitive_n = filter->add_primitive(Inkscape::Filters::NR_FILTER_FLOOD);
 
203
    Inkscape::Filters::FilterPrimitive *nr_primitive = filter->get_primitive(primitive_n);
 
204
    Inkscape::Filters::FilterFlood *nr_flood = dynamic_cast<Inkscape::Filters::FilterFlood*>(nr_primitive);
 
205
    g_assert(nr_flood != NULL);
 
206
 
 
207
    sp_filter_primitive_renderer_common(primitive, nr_primitive);
 
208
    
 
209
    nr_flood->set_opacity(sp_flood->opacity);
 
210
    nr_flood->set_color(sp_flood->color);
 
211
}
 
212
 
 
213
 
 
214
/*
 
215
  Local Variables:
 
216
  mode:c++
 
217
  c-file-style:"stroustrup"
 
218
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
219
  indent-tabs-mode:nil
 
220
  fill-column:99
 
221
  End:
 
222
*/
 
223
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :