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;
109 }
111 /**
112 * Initializes an SPRoot object by setting its default parameter values.
113 */
114 static void
115 sp_root_init(SPRoot *root)
116 {
117 static Inkscape::Version const zero_version(0, 0);
119 sp_version_from_string(SVG_VERSION, &root->original.svg);
120 root->version.svg = root->original.svg;
121 root->version.inkscape = root->original.inkscape =
122 root->version.sodipodi = root->original.sodipodi = zero_version;
124 root->x.unset();
125 root->y.unset();
126 root->width.unset(SVGLength::PERCENT, 1.0, 1.0);
127 root->height.unset(SVGLength::PERCENT, 1.0, 1.0);
129 /* root->viewbox.set_identity(); */
130 root->viewBox_set = FALSE;
132 root->c2p.setIdentity();
134 root->defs = NULL;
135 }
137 /**
138 * Fills in the data for an SPObject from its Inkscape::XML::Node object.
139 * It fills in data such as version, x, y, width, height, etc.
140 * It then calls the object's parent class object's build function.
141 */
142 static void
143 sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
144 {
145 SPGroup *group = (SPGroup *) object;
146 SPRoot *root = (SPRoot *) object;
148 if (repr->attribute("sodipodi:docname") || repr->attribute("SP-DOCNAME")) {
149 /* so we have a nonzero initial version */
150 root->original.sodipodi.major = 0;
151 root->original.sodipodi.minor = 1;
152 }
153 sp_object_read_attr(object, "version");
154 sp_object_read_attr(object, "sodipodi:version");
155 sp_object_read_attr(object, "inkscape:version");
156 /* It is important to parse these here, so objects will have viewport build-time */
157 sp_object_read_attr(object, "x");
158 sp_object_read_attr(object, "y");
159 sp_object_read_attr(object, "width");
160 sp_object_read_attr(object, "height");
161 sp_object_read_attr(object, "viewBox");
162 sp_object_read_attr(object, "preserveAspectRatio");
163 sp_object_read_attr(object, "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_first_child(SP_OBJECT(group)) ; 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();
178 }
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)
186 {
187 SPRoot *root = (SPRoot *) object;
188 root->defs = NULL;
190 if (((SPObjectClass *) parent_class)->release)
191 ((SPObjectClass *) parent_class)->release(object);
192 }
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)
199 {
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_SODIPODI_VERSION:
209 if (!sp_version_from_string(value, &root->version.sodipodi)) {
210 root->version.sodipodi = root->original.sodipodi;
211 }
212 case SP_ATTR_INKSCAPE_VERSION:
213 if (!sp_version_from_string(value, &root->version.inkscape)) {
214 root->version.inkscape = root->original.inkscape;
215 }
216 break;
217 case SP_ATTR_X:
218 if (!root->x.readAbsolute(value)) {
219 /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
220 root->x.unset();
221 }
222 /* fixme: I am almost sure these do not require viewport flag (Lauris) */
223 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
224 break;
225 case SP_ATTR_Y:
226 if (!root->y.readAbsolute(value)) {
227 /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
228 root->y.unset();
229 }
230 /* fixme: I am almost sure these do not require viewport flag (Lauris) */
231 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
232 break;
233 case SP_ATTR_WIDTH:
234 if (!root->width.readAbsolute(value) || !(root->width.computed > 0.0)) {
235 /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
236 root->width.unset(SVGLength::PERCENT, 1.0, 1.0);
237 }
238 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
239 break;
240 case SP_ATTR_HEIGHT:
241 if (!root->height.readAbsolute(value) || !(root->height.computed > 0.0)) {
242 /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
243 root->height.unset(SVGLength::PERCENT, 1.0, 1.0);
244 }
245 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
246 break;
247 case SP_ATTR_VIEWBOX:
248 if (value) {
249 double x, y, width, height;
250 char *eptr;
251 /* fixme: We have to take original item affine into account */
252 /* fixme: Think (Lauris) */
253 eptr = (gchar *) value;
254 x = g_ascii_strtod(eptr, &eptr);
255 while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
256 y = g_ascii_strtod(eptr, &eptr);
257 while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
258 width = g_ascii_strtod(eptr, &eptr);
259 while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
260 height = g_ascii_strtod(eptr, &eptr);
261 while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
262 if ((width > 0) && (height > 0)) {
263 /* Set viewbox */
264 root->viewBox.x0 = x;
265 root->viewBox.y0 = y;
266 root->viewBox.x1 = x + width;
267 root->viewBox.y1 = y + height;
268 root->viewBox_set = TRUE;
269 } else {
270 root->viewBox_set = FALSE;
271 }
272 } else {
273 root->viewBox_set = FALSE;
274 }
275 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
276 break;
277 case SP_ATTR_PRESERVEASPECTRATIO:
278 /* Do setup before, so we can use break to escape */
279 root->aspect_set = FALSE;
280 root->aspect_align = SP_ASPECT_XMID_YMID;
281 root->aspect_clip = SP_ASPECT_MEET;
282 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
283 if (value) {
284 int len;
285 gchar c[256];
286 gchar const *p, *e;
287 unsigned int align, clip;
288 p = value;
289 while (*p && *p == 32) p += 1;
290 if (!*p) break;
291 e = p;
292 while (*e && *e != 32) e += 1;
293 len = e - p;
294 if (len > 8) break;
295 memcpy(c, value, len);
296 c[len] = 0;
297 /* Now the actual part */
298 if (!strcmp(c, "none")) {
299 align = SP_ASPECT_NONE;
300 } else if (!strcmp(c, "xMinYMin")) {
301 align = SP_ASPECT_XMIN_YMIN;
302 } else if (!strcmp(c, "xMidYMin")) {
303 align = SP_ASPECT_XMID_YMIN;
304 } else if (!strcmp(c, "xMaxYMin")) {
305 align = SP_ASPECT_XMAX_YMIN;
306 } else if (!strcmp(c, "xMinYMid")) {
307 align = SP_ASPECT_XMIN_YMID;
308 } else if (!strcmp(c, "xMidYMid")) {
309 align = SP_ASPECT_XMID_YMID;
310 } else if (!strcmp(c, "xMaxYMid")) {
311 align = SP_ASPECT_XMAX_YMID;
312 } else if (!strcmp(c, "xMinYMax")) {
313 align = SP_ASPECT_XMIN_YMAX;
314 } else if (!strcmp(c, "xMidYMax")) {
315 align = SP_ASPECT_XMID_YMAX;
316 } else if (!strcmp(c, "xMaxYMax")) {
317 align = SP_ASPECT_XMAX_YMAX;
318 } else {
319 break;
320 }
321 clip = SP_ASPECT_MEET;
322 while (*e && *e == 32) e += 1;
323 if (*e) {
324 if (!strcmp(e, "meet")) {
325 clip = SP_ASPECT_MEET;
326 } else if (!strcmp(e, "slice")) {
327 clip = SP_ASPECT_SLICE;
328 } else {
329 break;
330 }
331 }
332 root->aspect_set = TRUE;
333 root->aspect_align = align;
334 root->aspect_clip = clip;
335 }
336 break;
337 case SP_ATTR_ONLOAD:
338 root->onload = (char *) value;
339 break;
340 default:
341 /* Pass the set event to the parent */
342 if (((SPObjectClass *) parent_class)->set) {
343 ((SPObjectClass *) parent_class)->set(object, key, value);
344 }
345 break;
346 }
347 }
349 /**
350 * This routine is for adding a child SVG object to an SPRoot object.
351 * The SPRoot object is taken to be an SPGroup.
352 */
353 static void
354 sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
355 {
356 SPRoot *root = (SPRoot *) object;
357 SPGroup *group = (SPGroup *) object;
359 if (((SPObjectClass *) (parent_class))->child_added)
360 (* ((SPObjectClass *) (parent_class))->child_added)(object, child, ref);
362 SPObject *co = object->document->getObjectByRepr(child);
363 g_assert (co != NULL || !strcmp("comment", child->name())); // comment repr node has no object
365 if (co && SP_IS_DEFS(co)) {
366 SPObject *c;
367 /* We search for first <defs> node - it is not beautiful, but works */
368 for (c = sp_object_first_child(SP_OBJECT(group)) ; c != NULL; c = SP_OBJECT_NEXT(c) ) {
369 if (SP_IS_DEFS(c)) {
370 root->defs = SP_DEFS(c);
371 break;
372 }
373 }
374 }
375 }
377 /**
378 * Removes the given child from this SPRoot object.
379 */
380 static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child)
381 {
382 SPRoot *root = (SPRoot *) object;
384 if ( root->defs && SP_OBJECT_REPR(root->defs) == child ) {
385 SPObject *iter;
386 /* We search for first remaining <defs> node - it is not beautiful, but works */
387 for ( iter = sp_object_first_child(object) ; iter ; iter = SP_OBJECT_NEXT(iter) ) {
388 if ( SP_IS_DEFS(iter) && (SPDefs *)iter != root->defs ) {
389 root->defs = (SPDefs *)iter;
390 break;
391 }
392 }
393 if (!iter) {
394 /* we should probably create a new <defs> here? */
395 root->defs = NULL;
396 }
397 }
399 if (((SPObjectClass *) (parent_class))->remove_child)
400 (* ((SPObjectClass *) (parent_class))->remove_child)(object, child);
401 }
403 /**
404 * This callback routine updates the SPRoot object when its attributes have been changed.
405 */
406 static void
407 sp_root_update(SPObject *object, SPCtx *ctx, guint flags)
408 {
409 SPItemView *v;
411 SPItem *item = SP_ITEM(object);
412 SPRoot *root = SP_ROOT(object);
413 SPItemCtx *ictx = (SPItemCtx *) ctx;
415 /* fixme: This will be invoked too often (Lauris) */
416 /* fixme: We should calculate only if parent viewport has changed (Lauris) */
417 /* If position is specified as percentage, calculate actual values */
418 if (root->x.unit == SVGLength::PERCENT) {
419 root->x.computed = root->x.value * (ictx->vp.x1 - ictx->vp.x0);
420 }
421 if (root->y.unit == SVGLength::PERCENT) {
422 root->y.computed = root->y.value * (ictx->vp.y1 - ictx->vp.y0);
423 }
424 if (root->width.unit == SVGLength::PERCENT) {
425 root->width.computed = root->width.value * (ictx->vp.x1 - ictx->vp.x0);
426 }
427 if (root->height.unit == SVGLength::PERCENT) {
428 root->height.computed = root->height.value * (ictx->vp.y1 - ictx->vp.y0);
429 }
431 /* Create copy of item context */
432 SPItemCtx rctx = *ictx;
434 /* Calculate child to parent transformation */
435 root->c2p.setIdentity();
437 if (object->parent) {
438 /*
439 * fixme: I am not sure whether setting x and y does or does not
440 * fixme: translate the content of inner SVG.
441 * fixme: Still applying translation and setting viewport to width and
442 * fixme: height seems natural, as this makes the inner svg element
443 * fixme: self-contained. The spec is vague here.
444 */
445 root->c2p = Geom::Matrix(Geom::Translate(root->x.computed,
446 root->y.computed));
447 }
449 if (root->viewBox_set) {
450 double x, y, width, height;
451 /* Determine actual viewbox in viewport coordinates */
452 if (root->aspect_align == SP_ASPECT_NONE) {
453 x = 0.0;
454 y = 0.0;
455 width = root->width.computed;
456 height = root->height.computed;
457 } else {
458 double scalex, scaley, scale;
459 /* Things are getting interesting */
460 scalex = root->width.computed / (root->viewBox.x1 - root->viewBox.x0);
461 scaley = root->height.computed / (root->viewBox.y1 - root->viewBox.y0);
462 scale = (root->aspect_clip == SP_ASPECT_MEET) ? MIN(scalex, scaley) : MAX(scalex, scaley);
463 width = (root->viewBox.x1 - root->viewBox.x0) * scale;
464 height = (root->viewBox.y1 - root->viewBox.y0) * scale;
465 /* Now place viewbox to requested position */
466 /* todo: Use an array lookup to find the 0.0/0.5/1.0 coefficients,
467 as is done for dialogs/align.cpp. */
468 switch (root->aspect_align) {
469 case SP_ASPECT_XMIN_YMIN:
470 x = 0.0;
471 y = 0.0;
472 break;
473 case SP_ASPECT_XMID_YMIN:
474 x = 0.5 * (root->width.computed - width);
475 y = 0.0;
476 break;
477 case SP_ASPECT_XMAX_YMIN:
478 x = 1.0 * (root->width.computed - width);
479 y = 0.0;
480 break;
481 case SP_ASPECT_XMIN_YMID:
482 x = 0.0;
483 y = 0.5 * (root->height.computed - height);
484 break;
485 case SP_ASPECT_XMID_YMID:
486 x = 0.5 * (root->width.computed - width);
487 y = 0.5 * (root->height.computed - height);
488 break;
489 case SP_ASPECT_XMAX_YMID:
490 x = 1.0 * (root->width.computed - width);
491 y = 0.5 * (root->height.computed - height);
492 break;
493 case SP_ASPECT_XMIN_YMAX:
494 x = 0.0;
495 y = 1.0 * (root->height.computed - height);
496 break;
497 case SP_ASPECT_XMID_YMAX:
498 x = 0.5 * (root->width.computed - width);
499 y = 1.0 * (root->height.computed - height);
500 break;
501 case SP_ASPECT_XMAX_YMAX:
502 x = 1.0 * (root->width.computed - width);
503 y = 1.0 * (root->height.computed - height);
504 break;
505 default:
506 x = 0.0;
507 y = 0.0;
508 break;
509 }
510 }
512 /* Compose additional transformation from scale and position */
513 Geom::Point const viewBox_min(root->viewBox.x0,
514 root->viewBox.y0);
515 Geom::Point const viewBox_max(root->viewBox.x1,
516 root->viewBox.y1);
517 Geom::Scale const viewBox_length( viewBox_max - viewBox_min );
518 Geom::Scale const new_length(width, height);
520 /* Append viewbox transformation */
521 /* TODO: The below looks suspicious to me (pjrm): I wonder whether the RHS
522 expression should have c2p at the beginning rather than at the end. Test it. */
523 root->c2p = Geom::Translate(-viewBox_min) * ( new_length * viewBox_length.inverse() ) * Geom::Translate(x, y) * root->c2p;
524 }
526 rctx.i2doc = root->c2p * rctx.i2doc;
528 /* Initialize child viewport */
529 if (root->viewBox_set) {
530 rctx.vp.x0 = root->viewBox.x0;
531 rctx.vp.y0 = root->viewBox.y0;
532 rctx.vp.x1 = root->viewBox.x1;
533 rctx.vp.y1 = root->viewBox.y1;
534 } else {
535 /* fixme: I wonder whether this logic is correct (Lauris) */
536 if (object->parent) {
537 rctx.vp.x0 = root->x.computed;
538 rctx.vp.y0 = root->y.computed;
539 } else {
540 rctx.vp.x0 = 0.0;
541 rctx.vp.y0 = 0.0;
542 }
543 rctx.vp.x1 = root->width.computed;
544 rctx.vp.y1 = root->height.computed;
545 }
547 rctx.i2vp = Geom::identity();
549 /* And invoke parent method */
550 if (((SPObjectClass *) (parent_class))->update)
551 ((SPObjectClass *) (parent_class))->update(object, (SPCtx *) &rctx, flags);
553 /* As last step set additional transform of arena group */
554 for (v = item->display; v != NULL; v = v->next) {
555 nr_arena_group_set_child_transform(NR_ARENA_GROUP(v->arenaitem), root->c2p);
556 }
557 }
559 /**
560 * Calls the <tt>modified</tt> routine of the SPRoot object's parent class.
561 * Also, if the viewport has been modified, it sets the document size to the new
562 * height and width.
563 */
564 static void
565 sp_root_modified(SPObject *object, guint flags)
566 {
567 SPRoot *root = SP_ROOT(object);
569 if (((SPObjectClass *) (parent_class))->modified)
570 (* ((SPObjectClass *) (parent_class))->modified)(object, flags);
572 /* fixme: (Lauris) */
573 if (!object->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
574 sp_document_resized_signal_emit (SP_OBJECT_DOCUMENT(root), root->width.computed, root->height.computed);
575 }
576 }
578 /**
579 * Writes the object into the repr object, then calls the parent's write routine.
580 */
581 static Inkscape::XML::Node *
582 sp_root_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
583 {
584 SPRoot *root = SP_ROOT(object);
586 if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
587 repr = xml_doc->createElement("svg:svg");
588 }
590 if (flags & SP_OBJECT_WRITE_EXT) {
591 repr->setAttribute("sodipodi:version", SODIPODI_VERSION);
592 repr->setAttribute("inkscape:version", Inkscape::version_string);
593 }
595 repr->setAttribute("version", SVG_VERSION);
597 if (fabs(root->x.computed) > 1e-9)
598 sp_repr_set_svg_double(repr, "x", root->x.computed);
599 if (fabs(root->y.computed) > 1e-9)
600 sp_repr_set_svg_double(repr, "y", root->y.computed);
602 /* Unlike all other SPObject, here we want to preserve absolute units too (and only here,
603 * according to the recommendation in http://www.w3.org/TR/SVG11/coords.html#Units).
604 */
605 repr->setAttribute("width", sp_svg_length_write_with_units(root->width).c_str());
606 repr->setAttribute("height", sp_svg_length_write_with_units(root->height).c_str());
608 if (root->viewBox_set) {
609 Inkscape::SVGOStringStream os;
610 os << root->viewBox.x0 << " " << root->viewBox.y0 << " " << root->viewBox.x1 - root->viewBox.x0 << " " << root->viewBox.y1 - root->viewBox.y0;
611 repr->setAttribute("viewBox", os.str().c_str());
612 }
614 if (((SPObjectClass *) (parent_class))->write)
615 ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags);
617 return repr;
618 }
620 /**
621 * Displays the SPRoot item on the NRArena.
622 */
623 static NRArenaItem *
624 sp_root_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags)
625 {
626 SPRoot *root = SP_ROOT(item);
628 NRArenaItem *ai;
629 if (((SPItemClass *) (parent_class))->show) {
630 ai = ((SPItemClass *) (parent_class))->show(item, arena, key, flags);
631 if (ai) {
632 nr_arena_group_set_child_transform(NR_ARENA_GROUP(ai), root->c2p);
633 }
634 } else {
635 ai = NULL;
636 }
638 return ai;
639 }
641 /**
642 * Virtual print callback.
643 */
644 static void
645 sp_root_print(SPItem *item, SPPrintContext *ctx)
646 {
647 SPRoot *root = SP_ROOT(item);
649 sp_print_bind(ctx, root->c2p, 1.0);
651 if (((SPItemClass *) (parent_class))->print) {
652 ((SPItemClass *) (parent_class))->print(item, ctx);
653 }
655 sp_print_release(ctx);
656 }
659 /*
660 Local Variables:
661 mode:c++
662 c-file-style:"stroustrup"
663 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
664 indent-tabs-mode:nil
665 fill-column:99
666 End:
667 */
668 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :