Code

A simple layout document as to what, why and how is cppification.
[inkscape.git] / src / sp-root.cpp
1 #define __SP_ROOT_C__
3 /** \file
4  * SVG \<svg\> implementation.
5  */
6 /*
7  * Authors:
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *
10  * Copyright (C) 1999-2002 Lauris Kaplinski
11  * Copyright (C) 2000-2001 Ximian, Inc.
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #ifdef HAVE_CONFIG_H
17 # include "config.h"
18 #endif
20 #include <cstring>
21 #include <string>
23 #include "svg/svg.h"
24 #include "display/nr-arena-group.h"
25 #include "attributes.h"
26 #include "print.h"
27 #include "document.h"
28 #include "sp-defs.h"
29 #include "sp-root.h"
30 #include <libnr/nr-matrix-fns.h>
31 #include <libnr/nr-matrix-ops.h>
32 #include <libnr/nr-matrix-translate-ops.h>
33 #include <libnr/nr-scale-ops.h>
34 #include <libnr/nr-translate-scale-ops.h>
35 #include <xml/repr.h>
36 #include "svg/stringstream.h"
37 #include "inkscape-version.h"
39 class SPDesktop;
41 static void sp_root_class_init(SPRootClass *klass);
42 static void sp_root_init(SPRoot *root);
44 static void sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
45 static void sp_root_release(SPObject *object);
46 static void sp_root_set(SPObject *object, unsigned int key, gchar const *value);
47 static void sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
48 static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child);
49 static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags);
50 static void sp_root_modified(SPObject *object, guint flags);
51 static Inkscape::XML::Node *sp_root_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
53 static NRArenaItem *sp_root_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
54 static void sp_root_print(SPItem *item, SPPrintContext *ctx);
56 static SPGroupClass *parent_class;
58 /**
59  * Returns the type info of sp_root, including its class sizes and initialization routines.
60  */
61 GType
62 sp_root_get_type(void)
63 {
64     static GType type = 0;
65     if (!type) {
66         GTypeInfo info = {
67             sizeof(SPRootClass),
68             NULL, NULL,
69             (GClassInitFunc) sp_root_class_init,
70             NULL, NULL,
71             sizeof(SPRoot),
72             16,
73             (GInstanceInitFunc) sp_root_init,
74             NULL,   /* value_table */
75         };
76         type = g_type_register_static(SP_TYPE_GROUP, "SPRoot", &info, (GTypeFlags)0);
77     }
78     return type;
79 }
81 /**
82  * Initializes an SPRootClass object by setting its class and parent class objects, and registering
83  * function pointers (i.e.\ gobject-style virtual functions) for various operations.
84  */
85 static void
86 sp_root_class_init(SPRootClass *klass)
87 {
88     GObjectClass *object_class;
89     SPObjectClass *sp_object_class;
90     SPItemClass *sp_item_class;
92     object_class = G_OBJECT_CLASS(klass);
93     sp_object_class = (SPObjectClass *) klass;
94     sp_item_class = (SPItemClass *) klass;
96     parent_class = (SPGroupClass *)g_type_class_ref(SP_TYPE_GROUP);
98     sp_object_class->build = sp_root_build;
99     sp_object_class->release = sp_root_release;
100     sp_object_class->set = sp_root_set;
101     sp_object_class->child_added = sp_root_child_added;
102     sp_object_class->remove_child = sp_root_remove_child;
103     sp_object_class->update = sp_root_update;
104     sp_object_class->modified = sp_root_modified;
105     sp_object_class->write = sp_root_write;
107     sp_item_class->show = sp_root_show;
108     sp_item_class->print = sp_root_print;
111 /**
112  * Initializes an SPRoot object by setting its default parameter values.
113  */
114 static void
115 sp_root_init(SPRoot *root)
117     static Inkscape::Version const zero_version(0, 0);
119     sp_version_from_string(SVG_VERSION, &root->original.svg);
120     root->version.svg = zero_version;
121     root->original.svg = zero_version;
122     root->version.inkscape = zero_version;
123     root->original.inkscape = zero_version;
125     root->x.unset();
126     root->y.unset();
127     root->width.unset(SVGLength::PERCENT, 1.0, 1.0);
128     root->height.unset(SVGLength::PERCENT, 1.0, 1.0);
130     /* root->viewbox.set_identity(); */
131     root->viewBox_set = FALSE;
133     root->c2p.setIdentity();
135     root->defs = NULL;
138 /**
139  * Fills in the data for an SPObject from its Inkscape::XML::Node object.
140  * It fills in data such as version, x, y, width, height, etc.
141  * It then calls the object's parent class object's build function.
142  */
143 static void
144 sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
146     SPGroup *group = (SPGroup *) object;
147     SPRoot *root = (SPRoot *) object;
149         //XML Tree being used directly here while it shouldn't be.
150     if ( !object->getRepr()->attribute("version") ) {
151         repr->setAttribute("version", SVG_VERSION);
152     }
154     object->readAttr( "version");
155     object->readAttr( "inkscape:version");
156     /* It is important to parse these here, so objects will have viewport build-time */
157     object->readAttr( "x");
158     object->readAttr( "y");
159     object->readAttr( "width");
160     object->readAttr( "height");
161     object->readAttr( "viewBox");
162     object->readAttr( "preserveAspectRatio");
163     object->readAttr( "onload");
165     if (((SPObjectClass *) parent_class)->build)
166         (* ((SPObjectClass *) parent_class)->build) (object, document, repr);
168     /* Search for first <defs> node */
169     for (SPObject *o = SP_OBJECT(group)->first_child() ; o != NULL; o = SP_OBJECT_NEXT(o) ) {
170         if (SP_IS_DEFS(o)) {
171             root->defs = SP_DEFS(o);
172             break;
173         }
174     }
176     // clear transform, if any was read in - SVG does not allow transform= on <svg>
177     SP_ITEM(object)->transform = Geom::identity();
180 /**
181  * This is a destructor routine for SPRoot objects.  It de-references any \<def\> items and calls
182  * the parent class destructor.
183  */
184 static void
185 sp_root_release(SPObject *object)
187     SPRoot *root = (SPRoot *) object;
188     root->defs = NULL;
190     if (((SPObjectClass *) parent_class)->release)
191         ((SPObjectClass *) parent_class)->release(object);
194 /**
195  * Sets the attribute given by key for SPRoot objects to the value specified by value.
196  */
197 static void
198 sp_root_set(SPObject *object, unsigned int key, gchar const *value)
200     SPRoot *root = SP_ROOT(object);
202     switch (key) {
203         case SP_ATTR_VERSION:
204             if (!sp_version_from_string(value, &root->version.svg)) {
205                 root->version.svg = root->original.svg;
206             }
207             break;
208         case SP_ATTR_INKSCAPE_VERSION:
209             if (!sp_version_from_string(value, &root->version.inkscape)) {
210                 root->version.inkscape = root->original.inkscape;
211             }
212             break;
213         case SP_ATTR_X:
214             if (!root->x.readAbsolute(value)) {
215                 /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
216                 root->x.unset();
217             }
218             /* fixme: I am almost sure these do not require viewport flag (Lauris) */
219             object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
220             break;
221         case SP_ATTR_Y:
222             if (!root->y.readAbsolute(value)) {
223                 /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
224                 root->y.unset();
225             }
226             /* fixme: I am almost sure these do not require viewport flag (Lauris) */
227             object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
228             break;
229         case SP_ATTR_WIDTH:
230             if (!root->width.readAbsolute(value) || !(root->width.computed > 0.0)) {
231                 /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
232                 root->width.unset(SVGLength::PERCENT, 1.0, 1.0);
233             }
234             object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
235             break;
236         case SP_ATTR_HEIGHT:
237             if (!root->height.readAbsolute(value) || !(root->height.computed > 0.0)) {
238                 /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
239                 root->height.unset(SVGLength::PERCENT, 1.0, 1.0);
240             }
241             object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
242             break;
243         case SP_ATTR_VIEWBOX:
244             if (value) {
245                 double x, y, width, height;
246                 char *eptr;
247                 /* fixme: We have to take original item affine into account */
248                 /* fixme: Think (Lauris) */
249                 eptr = (gchar *) value;
250                 x = g_ascii_strtod(eptr, &eptr);
251                 while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
252                 y = g_ascii_strtod(eptr, &eptr);
253                 while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
254                 width = g_ascii_strtod(eptr, &eptr);
255                 while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
256                 height = g_ascii_strtod(eptr, &eptr);
257                 while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
258                 if ((width > 0) && (height > 0)) {
259                     /* Set viewbox */
260                     root->viewBox.x0 = x;
261                     root->viewBox.y0 = y;
262                     root->viewBox.x1 = x + width;
263                     root->viewBox.y1 = y + height;
264                     root->viewBox_set = TRUE;
265                 } else {
266                     root->viewBox_set = FALSE;
267                 }
268             } else {
269                 root->viewBox_set = FALSE;
270             }
271             object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
272             break;
273         case SP_ATTR_PRESERVEASPECTRATIO:
274             /* Do setup before, so we can use break to escape */
275             root->aspect_set = FALSE;
276             root->aspect_align = SP_ASPECT_XMID_YMID;
277             root->aspect_clip = SP_ASPECT_MEET;
278             object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
279             if (value) {
280                 int len;
281                 gchar c[256];
282                 gchar const *p, *e;
283                 unsigned int align, clip;
284                 p = value;
285                 while (*p && *p == 32) p += 1;
286                 if (!*p) break;
287                 e = p;
288                 while (*e && *e != 32) e += 1;
289                 len = e - p;
290                 if (len > 8) break;
291                 memcpy(c, value, len);
292                 c[len] = 0;
293                 /* Now the actual part */
294                 if (!strcmp(c, "none")) {
295                     align = SP_ASPECT_NONE;
296                 } else if (!strcmp(c, "xMinYMin")) {
297                     align = SP_ASPECT_XMIN_YMIN;
298                 } else if (!strcmp(c, "xMidYMin")) {
299                     align = SP_ASPECT_XMID_YMIN;
300                 } else if (!strcmp(c, "xMaxYMin")) {
301                     align = SP_ASPECT_XMAX_YMIN;
302                 } else if (!strcmp(c, "xMinYMid")) {
303                     align = SP_ASPECT_XMIN_YMID;
304                 } else if (!strcmp(c, "xMidYMid")) {
305                     align = SP_ASPECT_XMID_YMID;
306                 } else if (!strcmp(c, "xMaxYMid")) {
307                     align = SP_ASPECT_XMAX_YMID;
308                 } else if (!strcmp(c, "xMinYMax")) {
309                     align = SP_ASPECT_XMIN_YMAX;
310                 } else if (!strcmp(c, "xMidYMax")) {
311                     align = SP_ASPECT_XMID_YMAX;
312                 } else if (!strcmp(c, "xMaxYMax")) {
313                     align = SP_ASPECT_XMAX_YMAX;
314                 } else {
315                     break;
316                 }
317                 clip = SP_ASPECT_MEET;
318                 while (*e && *e == 32) e += 1;
319                 if (*e) {
320                     if (!strcmp(e, "meet")) {
321                         clip = SP_ASPECT_MEET;
322                     } else if (!strcmp(e, "slice")) {
323                         clip = SP_ASPECT_SLICE;
324                     } else {
325                         break;
326                     }
327                 }
328                 root->aspect_set = TRUE;
329                 root->aspect_align = align;
330                 root->aspect_clip = clip;
331             }
332             break;
333         case SP_ATTR_ONLOAD:
334             root->onload = (char *) value;
335             break;
336         default:
337             /* Pass the set event to the parent */
338             if (((SPObjectClass *) parent_class)->set) {
339                 ((SPObjectClass *) parent_class)->set(object, key, value);
340             }
341             break;
342     }
345 /**
346  * This routine is for adding a child SVG object to an SPRoot object.
347  * The SPRoot object is taken to be an SPGroup.
348  */
349 static void
350 sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
352     SPRoot *root = (SPRoot *) object;
353     SPGroup *group = (SPGroup *) object;
355     if (((SPObjectClass *) (parent_class))->child_added)
356         (* ((SPObjectClass *) (parent_class))->child_added)(object, child, ref);
358     SPObject *co = object->document->getObjectByRepr(child);
359     g_assert (co != NULL || !strcmp("comment", child->name())); // comment repr node has no object
361     if (co && SP_IS_DEFS(co)) {
362         SPObject *c;
363         /* We search for first <defs> node - it is not beautiful, but works */
364         for (c = SP_OBJECT(group)->first_child() ; c != NULL; c = SP_OBJECT_NEXT(c) ) {
365             if (SP_IS_DEFS(c)) {
366                 root->defs = SP_DEFS(c);
367                 break;
368             }
369         }
370     }
373 /**
374  * Removes the given child from this SPRoot object.
375  */
376 static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child)
378     SPRoot *root = (SPRoot *) object;
380     if ( root->defs && SP_OBJECT_REPR(root->defs) == child ) {
381         SPObject *iter;
382         /* We search for first remaining <defs> node - it is not beautiful, but works */
383         for ( iter = object->first_child() ; iter ; iter = SP_OBJECT_NEXT(iter) ) {
384             if ( SP_IS_DEFS(iter) && (SPDefs *)iter != root->defs ) {
385                 root->defs = (SPDefs *)iter;
386                 break;
387             }
388         }
389         if (!iter) {
390             /* we should probably create a new <defs> here? */
391             root->defs = NULL;
392         }
393     }
395     if (((SPObjectClass *) (parent_class))->remove_child)
396         (* ((SPObjectClass *) (parent_class))->remove_child)(object, child);
399 /**
400  * This callback routine updates the SPRoot object when its attributes have been changed.
401  */
402 static void
403 sp_root_update(SPObject *object, SPCtx *ctx, guint flags)
405     SPItemView *v;
407     SPItem *item = SP_ITEM(object);
408     SPRoot *root = SP_ROOT(object);
409     SPItemCtx *ictx = (SPItemCtx *) ctx;
411     /* fixme: This will be invoked too often (Lauris) */
412     /* fixme: We should calculate only if parent viewport has changed (Lauris) */
413     /* If position is specified as percentage, calculate actual values */
414     if (root->x.unit == SVGLength::PERCENT) {
415         root->x.computed = root->x.value * (ictx->vp.x1 - ictx->vp.x0);
416     }
417     if (root->y.unit == SVGLength::PERCENT) {
418         root->y.computed = root->y.value * (ictx->vp.y1 - ictx->vp.y0);
419     }
420     if (root->width.unit == SVGLength::PERCENT) {
421         root->width.computed = root->width.value * (ictx->vp.x1 - ictx->vp.x0);
422     }
423     if (root->height.unit == SVGLength::PERCENT) {
424         root->height.computed = root->height.value * (ictx->vp.y1 - ictx->vp.y0);
425     }
427     /* Create copy of item context */
428     SPItemCtx rctx = *ictx;
430     /* Calculate child to parent transformation */
431     root->c2p.setIdentity();
433     if (object->parent) {
434         /*
435          * fixme: I am not sure whether setting x and y does or does not
436          * fixme: translate the content of inner SVG.
437          * fixme: Still applying translation and setting viewport to width and
438          * fixme: height seems natural, as this makes the inner svg element
439          * fixme: self-contained. The spec is vague here.
440          */
441         root->c2p = Geom::Matrix(Geom::Translate(root->x.computed,
442                                                  root->y.computed));
443     }
445     if (root->viewBox_set) {
446         double x, y, width, height;
447         /* Determine actual viewbox in viewport coordinates */
448         if (root->aspect_align == SP_ASPECT_NONE) {
449             x = 0.0;
450             y = 0.0;
451             width = root->width.computed;
452             height = root->height.computed;
453         } else {
454             double scalex, scaley, scale;
455             /* Things are getting interesting */
456             scalex = root->width.computed / (root->viewBox.x1 - root->viewBox.x0);
457             scaley = root->height.computed / (root->viewBox.y1 - root->viewBox.y0);
458             scale = (root->aspect_clip == SP_ASPECT_MEET) ? MIN(scalex, scaley) : MAX(scalex, scaley);
459             width = (root->viewBox.x1 - root->viewBox.x0) * scale;
460             height = (root->viewBox.y1 - root->viewBox.y0) * scale;
461             /* Now place viewbox to requested position */
462             /* todo: Use an array lookup to find the 0.0/0.5/1.0 coefficients,
463                as is done for dialogs/align.cpp. */
464             switch (root->aspect_align) {
465                 case SP_ASPECT_XMIN_YMIN:
466                     x = 0.0;
467                     y = 0.0;
468                     break;
469                 case SP_ASPECT_XMID_YMIN:
470                     x = 0.5 * (root->width.computed - width);
471                     y = 0.0;
472                     break;
473                 case SP_ASPECT_XMAX_YMIN:
474                     x = 1.0 * (root->width.computed - width);
475                     y = 0.0;
476                     break;
477                 case SP_ASPECT_XMIN_YMID:
478                     x = 0.0;
479                     y = 0.5 * (root->height.computed - height);
480                     break;
481                 case SP_ASPECT_XMID_YMID:
482                     x = 0.5 * (root->width.computed - width);
483                     y = 0.5 * (root->height.computed - height);
484                     break;
485                 case SP_ASPECT_XMAX_YMID:
486                     x = 1.0 * (root->width.computed - width);
487                     y = 0.5 * (root->height.computed - height);
488                     break;
489                 case SP_ASPECT_XMIN_YMAX:
490                     x = 0.0;
491                     y = 1.0 * (root->height.computed - height);
492                     break;
493                 case SP_ASPECT_XMID_YMAX:
494                     x = 0.5 * (root->width.computed - width);
495                     y = 1.0 * (root->height.computed - height);
496                     break;
497                 case SP_ASPECT_XMAX_YMAX:
498                     x = 1.0 * (root->width.computed - width);
499                     y = 1.0 * (root->height.computed - height);
500                     break;
501                 default:
502                     x = 0.0;
503                     y = 0.0;
504                     break;
505             }
506         }
508         /* Compose additional transformation from scale and position */
509         Geom::Point const viewBox_min(root->viewBox.x0,
510                                     root->viewBox.y0);
511         Geom::Point const viewBox_max(root->viewBox.x1,
512                                     root->viewBox.y1);
513         Geom::Scale const viewBox_length( viewBox_max - viewBox_min );
514         Geom::Scale const new_length(width, height);
516         /* Append viewbox transformation */
517         /* TODO: The below looks suspicious to me (pjrm): I wonder whether the RHS
518            expression should have c2p at the beginning rather than at the end.  Test it. */
519         root->c2p = Geom::Translate(-viewBox_min) * ( new_length * viewBox_length.inverse() ) * Geom::Translate(x, y) * root->c2p;
520     }
522     rctx.i2doc = root->c2p * rctx.i2doc;
524     /* Initialize child viewport */
525     if (root->viewBox_set) {
526         rctx.vp.x0 = root->viewBox.x0;
527         rctx.vp.y0 = root->viewBox.y0;
528         rctx.vp.x1 = root->viewBox.x1;
529         rctx.vp.y1 = root->viewBox.y1;
530     } else {
531         /* fixme: I wonder whether this logic is correct (Lauris) */
532         if (object->parent) {
533             rctx.vp.x0 = root->x.computed;
534             rctx.vp.y0 = root->y.computed;
535         } else {
536             rctx.vp.x0 = 0.0;
537             rctx.vp.y0 = 0.0;
538         }
539         rctx.vp.x1 = root->width.computed;
540         rctx.vp.y1 = root->height.computed;
541     }
543     rctx.i2vp = Geom::identity();
545     /* And invoke parent method */
546     if (((SPObjectClass *) (parent_class))->update)
547         ((SPObjectClass *) (parent_class))->update(object, (SPCtx *) &rctx, flags);
549     /* As last step set additional transform of arena group */
550     for (v = item->display; v != NULL; v = v->next) {
551         nr_arena_group_set_child_transform(NR_ARENA_GROUP(v->arenaitem), root->c2p);
552     }
555 /**
556  * Calls the <tt>modified</tt> routine of the SPRoot object's parent class.
557  * Also, if the viewport has been modified, it sets the document size to the new
558  * height and width.
559  */
560 static void
561 sp_root_modified(SPObject *object, guint flags)
563     SPRoot *root = SP_ROOT(object);
565     if (((SPObjectClass *) (parent_class))->modified)
566         (* ((SPObjectClass *) (parent_class))->modified)(object, flags);
568     /* fixme: (Lauris) */
569     if (!object->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
570         SP_OBJECT_DOCUMENT(root)->resized_signal_emit (root->width.computed, root->height.computed);
571     }
574 /**
575  * Writes the object into the repr object, then calls the parent's write routine.
576  */
577 static Inkscape::XML::Node *
578 sp_root_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
580     SPRoot *root = SP_ROOT(object);
582     if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
583         repr = xml_doc->createElement("svg:svg");
584     }
586     if (flags & SP_OBJECT_WRITE_EXT) {
587         repr->setAttribute("inkscape:version", Inkscape::version_string);
588     }
590     if ( !repr->attribute("version") ) {
591         repr->setAttribute("version", sp_version_to_string(root->version.svg));
592     }
594     if (fabs(root->x.computed) > 1e-9)
595         sp_repr_set_svg_double(repr, "x", root->x.computed);
596     if (fabs(root->y.computed) > 1e-9)
597         sp_repr_set_svg_double(repr, "y", root->y.computed);
599     /* Unlike all other SPObject, here we want to preserve absolute units too (and only here,
600      * according to the recommendation in http://www.w3.org/TR/SVG11/coords.html#Units).
601      */
602     repr->setAttribute("width", sp_svg_length_write_with_units(root->width).c_str());
603     repr->setAttribute("height", sp_svg_length_write_with_units(root->height).c_str());
605     if (root->viewBox_set) {
606         Inkscape::SVGOStringStream os;
607         os << root->viewBox.x0 << " " << root->viewBox.y0 << " " << root->viewBox.x1 - root->viewBox.x0 << " " << root->viewBox.y1 - root->viewBox.y0;
608         repr->setAttribute("viewBox", os.str().c_str());
609     }
611     if (((SPObjectClass *) (parent_class))->write)
612         ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags);
614     return repr;
617 /**
618  * Displays the SPRoot item on the NRArena.
619  */
620 static NRArenaItem *
621 sp_root_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags)
623     SPRoot *root = SP_ROOT(item);
625     NRArenaItem *ai;
626     if (((SPItemClass *) (parent_class))->show) {
627         ai = ((SPItemClass *) (parent_class))->show(item, arena, key, flags);
628         if (ai) {
629             nr_arena_group_set_child_transform(NR_ARENA_GROUP(ai), root->c2p);
630         }
631     } else {
632         ai = NULL;
633     }
635     return ai;
638 /**
639  * Virtual print callback.
640  */
641 static void
642 sp_root_print(SPItem *item, SPPrintContext *ctx)
644     SPRoot *root = SP_ROOT(item);
646     sp_print_bind(ctx, root->c2p, 1.0);
648     if (((SPItemClass *) (parent_class))->print) {
649         ((SPItemClass *) (parent_class))->print(item, ctx);
650     }
652     sp_print_release(ctx);
656 /*
657   Local Variables:
658   mode:c++
659   c-file-style:"stroustrup"
660   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
661   indent-tabs-mode:nil
662   fill-column:99
663   End:
664 */
665 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :