Code

make win32 compile using libxslt
[inkscape.git] / src / sp-feimage.cpp
1         #define __SP_FEIMAGE_CPP__
3 /** \file
4  * SVG <feImage> implementation.
5  *
6  */
7 /*
8  * Authors:
9  *   Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com>
10  *   hugo Rodrigues <haa.rodrigues@gmail.com>
11  *
12  * Copyright (C) 2007 Felipe Sanches
13  * Copyright (C) 2006 Hugo Rodrigues
14  *
15  * Released under GNU GPL, read the file 'COPYING' for more information
16  */
18 #ifdef HAVE_CONFIG_H
19 # include "config.h"
20 #endif
22 #include "attributes.h"
23 #include "svg/svg.h"
24 #include "sp-feimage.h"
25 #include "xml/repr.h"
26 #include <string.h>
28 #include "display/nr-filter.h"
29 #include "display/nr-filter-image.h"
31 /* FeImage base class */
33 static void sp_feImage_class_init(SPFeImageClass *klass);
34 static void sp_feImage_init(SPFeImage *feImage);
36 static void sp_feImage_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
37 static void sp_feImage_release(SPObject *object);
38 static void sp_feImage_set(SPObject *object, unsigned int key, gchar const *value);
39 static void sp_feImage_update(SPObject *object, SPCtx *ctx, guint flags);
40 static Inkscape::XML::Node *sp_feImage_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
41 static void sp_feImage_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter);
43 static SPFilterPrimitiveClass *feImage_parent_class;
45 GType
46 sp_feImage_get_type()
47 {
48     static GType feImage_type = 0;
50     if (!feImage_type) {
51         GTypeInfo feImage_info = {
52             sizeof(SPFeImageClass),
53             NULL, NULL,
54             (GClassInitFunc) sp_feImage_class_init,
55             NULL, NULL,
56             sizeof(SPFeImage),
57             16,
58             (GInstanceInitFunc) sp_feImage_init,
59             NULL,    /* value_table */
60         };
61         feImage_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeImage", &feImage_info, (GTypeFlags)0);
62     }
63     return feImage_type;
64 }
66 static void
67 sp_feImage_class_init(SPFeImageClass *klass)
68 {
69     SPObjectClass *sp_object_class = (SPObjectClass *)klass;
70     SPFilterPrimitiveClass * sp_primitive_class = (SPFilterPrimitiveClass *)klass;
72     feImage_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass);
74     sp_object_class->build = sp_feImage_build;
75     sp_object_class->release = sp_feImage_release;
76     sp_object_class->write = sp_feImage_write;
77     sp_object_class->set = sp_feImage_set;
78     sp_object_class->update = sp_feImage_update;
80     sp_primitive_class->build_renderer = sp_feImage_build_renderer;
81 }
83 static void
84 sp_feImage_init(SPFeImage *feImage)
85 {
86 }
88 /**
89  * Reads the Inkscape::XML::Node, and initializes SPFeImage 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.
92  */
93 static void
94 sp_feImage_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
95 {
96     if (((SPObjectClass *) feImage_parent_class)->build) {
97         ((SPObjectClass *) feImage_parent_class)->build(object, document, repr);
98     }
100     /*LOAD ATTRIBUTES FROM REPR HERE*/
101 /* apparently there's no attribute to load here 
102 since 'in' and 'xlink:href' are common filter attributes.
103 --Juca
104 */
105     sp_object_read_attr(object, "x");
106     sp_object_read_attr(object, "y");
107     sp_object_read_attr(object, "width");
108     sp_object_read_attr(object, "height");            
112 /**
113  * Drops any allocated memory.
114  */
115 static void
116 sp_feImage_release(SPObject *object)
119     if (((SPObjectClass *) feImage_parent_class)->release)
120         ((SPObjectClass *) feImage_parent_class)->release(object);
123 /**
124  * Sets a specific value in the SPFeImage.
125  */
126 static void
127 sp_feImage_set(SPObject *object, unsigned int key, gchar const *value)
129     SPFeImage *feImage = SP_FEIMAGE(object);
130     (void)feImage;
131     
132     switch(key) {
133         /*DEAL WITH SETTING ATTRIBUTES HERE*/
134         case SP_ATTR_X:
135             feImage->x.readOrUnset(value);
136             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
137             break;
138         case SP_ATTR_Y:
139             feImage->y.readOrUnset(value);
140             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
141             break;
142         case SP_ATTR_WIDTH:
143             feImage->width.readOrUnset(value);
144             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
145             break;
146         case SP_ATTR_HEIGHT:
147             feImage->height.readOrUnset(value);
148             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
149             break;
150         default:
151             if (((SPObjectClass *) feImage_parent_class)->set)
152                 ((SPObjectClass *) feImage_parent_class)->set(object, key, value);
153             break;
154     }
158 /**
159  * Receives update notifications.
160  */
161 static void
162 sp_feImage_update(SPObject *object, SPCtx *ctx, guint flags)
164  
165     if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
166                  SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
168         /* do something to trigger redisplay, updates? */
169     }
171     if (((SPObjectClass *) feImage_parent_class)->update) {
172         ((SPObjectClass *) feImage_parent_class)->update(object, ctx, flags);
173     }
176 /**
177  * Writes its settings to an incoming repr object, if any.
178  */
179 static Inkscape::XML::Node *
180 sp_feImage_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
182     // Inkscape-only object, not copied during an "plain SVG" dump:
183     if (flags & SP_OBJECT_WRITE_EXT) {
184         if (repr) {
185             // is this sane?
186             repr->mergeFrom(SP_OBJECT_REPR(object), "id");
187         } else {
188             repr = SP_OBJECT_REPR(object)->duplicate(NULL); // FIXME
189         }
190     }
192     if (((SPObjectClass *) feImage_parent_class)->write) {
193         ((SPObjectClass *) feImage_parent_class)->write(object, repr, flags);
194     }
196     return repr;
199 static void sp_feImage_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter) {
200     g_assert(primitive != NULL);
201     g_assert(filter != NULL);
203     SPFeImage *sp_image = SP_FEIMAGE(primitive);
204     
205     int primitive_n = filter->add_primitive(NR::NR_FILTER_IMAGE);
206     NR::FilterPrimitive *nr_primitive = filter->get_primitive(primitive_n);
207     NR::FilterImage *nr_image = dynamic_cast<NR::FilterImage*>(nr_primitive);
208     g_assert(nr_image != NULL);
210     sp_filter_primitive_renderer_common(primitive, nr_primitive);
211     nr_image->set_region(sp_image->x, sp_image->y, sp_image->width, sp_image->height);
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 :