Code

Pot and Dutch translation update
[inkscape.git] / src / sp-object-repr.cpp
1 #define __SP_OBJECT_REPR_C__
3 /*
4  * Object type dictionary and build frontend
5  *
6  * Authors:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *
9  * Copyright (C) 1999-2003 Lauris Kaplinski
10  *
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
14 #include "sp-defs.h"
15 #include "sp-symbol.h"
16 #include "marker.h"
17 #include "sp-use.h"
18 #include "sp-root.h"
19 #include "sp-image.h"
20 #include "sp-linear-gradient-fns.h"
21 #include "sp-path.h"
22 #include "sp-radial-gradient-fns.h"
23 #include "sp-rect.h"
24 #include "box3d.h"
25 #include "box3d-side.h"
26 #include "persp3d.h"
27 #include "sp-ellipse.h"
28 #include "sp-star.h"
29 #include "sp-stop.h"
30 #include "sp-spiral.h"
31 #include "sp-offset.h"
32 #include "sp-line.h"
33 #include "sp-metadata.h"
34 #include "sp-polyline.h"
35 #include "sp-textpath.h"
36 #include "sp-tref.h"
37 #include "sp-tspan.h"
38 #include "sp-pattern.h"
39 #include "sp-clippath.h"
40 #include "sp-mask.h"
41 #include "sp-anchor.h"
42 //#include "sp-animation.h"
43 #include "sp-flowdiv.h"
44 #include "sp-flowregion.h"
45 #include "sp-flowtext.h"
46 #include "sp-script.h"
47 #include "config.h"
49 #ifdef ENABLE_SVG_FONTS
50     #include "sp-font.h"
51     #include "sp-font-face.h"
52     #include "sp-glyph.h"
53     #include "sp-missing-glyph.h"
54     #include "sp-glyph-kerning.h"
55 #endif
57 #include "sp-style-elem.h"
58 #include "sp-switch.h"
59 #include "color-profile-fns.h"
60 #include "xml/repr.h"
61 #include "sp-filter.h"
62 #include "sp-gaussian-blur.h"
63 #include "filters/blend.h"
64 #include "filters/colormatrix.h"
65 #include "filters/componenttransfer.h"
66 #include "filters/componenttransfer-funcnode.h"
67 #include "filters/composite.h"
68 #include "filters/convolvematrix.h"
69 #include "filters/diffuselighting.h"
70 #include "filters/distantlight.h"
71 #include "filters/displacementmap.h"
72 #include "filters/flood.h"
73 #include "filters/image.h"
74 #include "filters/merge.h"
75 #include "filters/morphology.h"
76 #include "filters/offset.h"
77 #include "filters/pointlight.h"
78 #include "filters/specularlighting.h"
79 #include "filters/spotlight.h"
80 #include "filters/tile.h"
81 #include "filters/turbulence.h"
82 #include "filters/mergenode.h"
83 #include "live_effects/lpeobject.h"
84 #include "sp-title.h"
85 #include "sp-desc.h"
88 enum NameType { REPR_NAME, SODIPODI_TYPE };
89 static unsigned const N_NAME_TYPES = SODIPODI_TYPE + 1;
91 static GType name_to_gtype(NameType name_type, gchar const *name);
93 /**
94  * Construct an SPRoot and all its descendents from the given repr.
95  */
96 SPObject *
97 sp_object_repr_build_tree(SPDocument *document, Inkscape::XML::Node *repr)
98 {
99     g_assert(document != NULL);
100     g_assert(repr != NULL);
102     gchar const * const name = repr->name();
103     g_assert(name != NULL);
104     GType const type = name_to_gtype(REPR_NAME, name);
105     g_assert(g_type_is_a(type, SP_TYPE_ROOT));
106     gpointer newobj = g_object_new(type, 0);
107     g_assert(newobj != NULL);
108     SPObject *const object = SP_OBJECT(newobj);
109     g_assert(object != NULL);
110     sp_object_invoke_build(object, document, repr, FALSE);
112     return object;
115 GType
116 sp_repr_type_lookup(Inkscape::XML::Node *repr)
118     if ( repr->type() == Inkscape::XML::TEXT_NODE ) {
119         return SP_TYPE_STRING;
120     } else if ( repr->type() == Inkscape::XML::ELEMENT_NODE ) {
121         gchar const * const type_name = repr->attribute("sodipodi:type");
122         return ( type_name
123                  ? name_to_gtype(SODIPODI_TYPE, type_name)
124                  : name_to_gtype(REPR_NAME, repr->name()) );
125     } else {
126         return 0;
127     }
130 static GHashTable *t2dtable[N_NAME_TYPES] = {NULL};
132 static void
133 populate_dtables()
135     struct NameTypeEntry { char const *const name; GType const type_id; };
136     NameTypeEntry const repr_name_entries[] = {
137         { "svg:a", SP_TYPE_ANCHOR },
138         //{ "svg:animate", SP_TYPE_ANIMATE },
139         { "svg:circle", SP_TYPE_CIRCLE },
140         { "svg:color-profile", COLORPROFILE_TYPE },
141         { "svg:clipPath", SP_TYPE_CLIPPATH },
142         { "svg:defs", SP_TYPE_DEFS },
143         { "svg:desc", SP_TYPE_DESC },
144         { "svg:ellipse", SP_TYPE_ELLIPSE },
145         { "svg:filter", SP_TYPE_FILTER },
146         /* Note: flow* elements are proposed additions for SVG 1.2, they aren't in
147            SVG 1.1. */
148         { "svg:flowDiv", SP_TYPE_FLOWDIV },
149         { "svg:flowLine", SP_TYPE_FLOWLINE },
150         { "svg:flowPara", SP_TYPE_FLOWPARA },
151         { "svg:flowRegion", SP_TYPE_FLOWREGION },
152         { "svg:flowRegionBreak", SP_TYPE_FLOWREGIONBREAK },
153         { "svg:flowRegionExclude", SP_TYPE_FLOWREGIONEXCLUDE },
154         { "svg:flowRoot", SP_TYPE_FLOWTEXT },
155         { "svg:flowSpan", SP_TYPE_FLOWTSPAN },
156 #ifdef ENABLE_SVG_FONTS
157         { "svg:font", SP_TYPE_FONT },
158         { "svg:font-face", SP_TYPE_FONTFACE },
159         { "svg:glyph", SP_TYPE_GLYPH },
160         { "svg:missing-glyph", SP_TYPE_MISSING_GLYPH },
161         { "svg:hkern", SP_TYPE_HKERN },
162         { "svg:vkern", SP_TYPE_VKERN },
163 #endif
164         { "svg:g", SP_TYPE_GROUP },
165         { "svg:feBlend", SP_TYPE_FEBLEND },
166         { "svg:feColorMatrix", SP_TYPE_FECOLORMATRIX },
167         { "svg:feComponentTransfer", SP_TYPE_FECOMPONENTTRANSFER },
168         { "svg:feComposite", SP_TYPE_FECOMPOSITE },
169         { "svg:feConvolveMatrix", SP_TYPE_FECONVOLVEMATRIX },
170         { "svg:feDiffuseLighting", SP_TYPE_FEDIFFUSELIGHTING },
171         { "svg:feDistantLight", SP_TYPE_FEDISTANTLIGHT },
172         { "svg:feDisplacementMap", SP_TYPE_FEDISPLACEMENTMAP },
173         { "svg:feFlood", SP_TYPE_FEFLOOD },
174         { "svg:feFuncR", SP_TYPE_FEFUNCR },
175         { "svg:feFuncG", SP_TYPE_FEFUNCG },
176         { "svg:feFuncB", SP_TYPE_FEFUNCB },
177         { "svg:feFuncA", SP_TYPE_FEFUNCA },
178         { "svg:feGaussianBlur", SP_TYPE_GAUSSIANBLUR },
179         { "svg:feImage", SP_TYPE_FEIMAGE },
180         { "svg:feMerge", SP_TYPE_FEMERGE },
181         { "svg:feMorphology", SP_TYPE_FEMORPHOLOGY },
182         { "svg:feOffset", SP_TYPE_FEOFFSET },
183         { "svg:fePointLight", SP_TYPE_FEPOINTLIGHT },
184         { "svg:feSpecularLighting", SP_TYPE_FESPECULARLIGHTING },
185         { "svg:feSpotLight", SP_TYPE_FESPOTLIGHT },
186         { "svg:feTile", SP_TYPE_FETILE },
187         { "svg:feTurbulence", SP_TYPE_FETURBULENCE },
188         { "svg:feMergeNode", SP_TYPE_FEMERGENODE },
189         { "svg:image", SP_TYPE_IMAGE },
190         { "svg:line", SP_TYPE_LINE },
191         { "svg:linearGradient", SP_TYPE_LINEARGRADIENT },
192         { "svg:marker", SP_TYPE_MARKER },
193         { "svg:mask", SP_TYPE_MASK },
194         { "svg:metadata", SP_TYPE_METADATA },
195         { "svg:path", SP_TYPE_PATH },
196         { "svg:pattern", SP_TYPE_PATTERN },
197         { "svg:polygon", SP_TYPE_POLYGON },
198         { "svg:polyline", SP_TYPE_POLYLINE },
199         { "svg:radialGradient", SP_TYPE_RADIALGRADIENT },
200         { "svg:rect", SP_TYPE_RECT },
201         { "svg:stop", SP_TYPE_STOP },
202         { "svg:script", SP_TYPE_SCRIPT },
203         { "svg:svg", SP_TYPE_ROOT },
204         { "svg:style", SP_TYPE_STYLE_ELEM },
205         { "svg:switch", SP_TYPE_SWITCH },
206         { "svg:symbol", SP_TYPE_SYMBOL },
207         { "svg:text", SP_TYPE_TEXT },
208         { "svg:textPath", SP_TYPE_TEXTPATH },
209         { "svg:title", SP_TYPE_TITLE },
210         { "svg:tref", SP_TYPE_TREF },
211         { "svg:tspan", SP_TYPE_TSPAN },
212         { "svg:use", SP_TYPE_USE },
213         { "inkscape:path-effect", TYPE_LIVEPATHEFFECT }
214     };
215     NameTypeEntry const sodipodi_name_entries[] = {
216         { "arc", SP_TYPE_ARC },
217         { "inkscape:offset", SP_TYPE_OFFSET },
218         { "spiral", SP_TYPE_SPIRAL },
219         { "star", SP_TYPE_STAR },
220         { "inkscape:box3d", SP_TYPE_BOX3D },
221         { "inkscape:box3dside", SP_TYPE_BOX3D_SIDE },
222         { "inkscape:persp3d", SP_TYPE_PERSP3D }
223     };
225     NameTypeEntry const *const t2entries[] = {
226         repr_name_entries,
227         sodipodi_name_entries
228     };
229     unsigned const t2n_entries[] = {
230         G_N_ELEMENTS(repr_name_entries),
231         G_N_ELEMENTS(sodipodi_name_entries)
232     };
234     for (unsigned nt = 0; nt < N_NAME_TYPES; ++nt) {
235         NameTypeEntry const *const entries = t2entries[nt];
236         unsigned const n_entries = t2n_entries[nt];
237         GHashTable *&dtable = t2dtable[nt];
239         dtable = g_hash_table_new(g_str_hash, g_str_equal);
240         for (unsigned i = 0; i < n_entries; ++i) {
241             g_hash_table_insert(dtable,
242                                 (void *)entries[i].name,
243                                 (gpointer) entries[i].type_id);
244         }
245     }
248 static inline void
249 ensure_dtables_populated()
251     if (!*t2dtable) {
252         populate_dtables();
253     }
256 static GType
257 name_to_gtype(NameType const name_type, gchar const *name)
259     ensure_dtables_populated();
261     gpointer const data = g_hash_table_lookup(t2dtable[name_type], name);
262     return ( ( data == NULL )
263              ? SP_TYPE_OBJECT
264              : (GType) data );
267 void
268 sp_object_type_register(gchar const *name, GType const gtype)
270     GType const current = name_to_gtype(REPR_NAME, name);
271     if (current == SP_TYPE_OBJECT) {
272         g_hash_table_insert(t2dtable[REPR_NAME],
273                             const_cast<gchar *>(name),
274                             (gpointer) gtype);
275     } else {
276         /* Already registered. */
277         if (current != gtype) {
278             g_warning("repr type `%s' already registered as type #%lu, ignoring attempt to re-register as #%lu.",
279                       name, current, gtype);
280         }
281     }
284 /*
285   Local Variables:
286   mode:c++
287   c-file-style:"stroustrup"
288   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
289   indent-tabs-mode:nil
290   fill-column:99
291   End:
292 */
293 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :