Code

start switching sp_repr_new* over to XML::Document::create*, and rename create method...
[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 #include "config.h"
18 #include "svg/svg.h"
19 #include "display/nr-arena-group.h"
20 #include "attributes.h"
21 #include "print.h"
22 #include "document.h"
23 #include "sp-defs.h"
24 #include "sp-root.h"
25 #include <libnr/nr-matrix-fns.h>
26 #include <libnr/nr-matrix-ops.h>
27 #include <libnr/nr-matrix-translate-ops.h>
28 #include <libnr/nr-scale-ops.h>
29 #include <libnr/nr-translate-scale-ops.h>
30 #include <xml/repr.h>
31 #include "svg/stringstream.h"
32 #include "inkscape_version.h"
34 class SPDesktop;
36 static void sp_root_class_init(SPRootClass *klass);
37 static void sp_root_init(SPRoot *root);
39 static void sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
40 static void sp_root_release(SPObject *object);
41 static void sp_root_set(SPObject *object, unsigned int key, gchar const *value);
42 static void sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
43 static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child);
44 static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags);
45 static void sp_root_modified(SPObject *object, guint flags);
46 static Inkscape::XML::Node *sp_root_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
48 static NRArenaItem *sp_root_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
49 static void sp_root_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
50 static void sp_root_print(SPItem *item, SPPrintContext *ctx);
52 static SPGroupClass *parent_class;
54 /**
55  * Returns the type info of sp_root, including its class sizes and initialization routines.
56  */
57 GType
58 sp_root_get_type(void)
59 {
60     static GType type = 0;
61     if (!type) {
62         GTypeInfo info = {
63             sizeof(SPRootClass),
64             NULL, NULL,
65             (GClassInitFunc) sp_root_class_init,
66             NULL, NULL,
67             sizeof(SPRoot),
68             16,
69             (GInstanceInitFunc) sp_root_init,
70             NULL,   /* value_table */
71         };
72         type = g_type_register_static(SP_TYPE_GROUP, "SPRoot", &info, (GTypeFlags)0);
73     }
74     return type;
75 }
77 /**
78  * Initializes an SPRootClass object by setting its class and parent class objects, and registering
79  * function pointers (i.e.\ gobject-style virtual functions) for various operations.
80  */
81 static void
82 sp_root_class_init(SPRootClass *klass)
83 {
84     GObjectClass *object_class;
85     SPObjectClass *sp_object_class;
86     SPItemClass *sp_item_class;
88     object_class = G_OBJECT_CLASS(klass);
89     sp_object_class = (SPObjectClass *) klass;
90     sp_item_class = (SPItemClass *) klass;
92     parent_class = (SPGroupClass *)g_type_class_ref(SP_TYPE_GROUP);
94     sp_object_class->build = sp_root_build;
95     sp_object_class->release = sp_root_release;
96     sp_object_class->set = sp_root_set;
97     sp_object_class->child_added = sp_root_child_added;
98     sp_object_class->remove_child = sp_root_remove_child;
99     sp_object_class->update = sp_root_update;
100     sp_object_class->modified = sp_root_modified;
101     sp_object_class->write = sp_root_write;
103     sp_item_class->show = sp_root_show;
104     sp_item_class->bbox = sp_root_bbox;
105     sp_item_class->print = sp_root_print;
108 /**
109  * Initializes an SPRoot object by setting its default parameter values.
110  */
111 static void
112 sp_root_init(SPRoot *root)
114     static Inkscape::Version const zero_version(0, 0);
116     sp_version_from_string(SVG_VERSION, &root->original.svg);
117     root->version.svg = root->original.svg;
118     root->version.inkscape = root->original.inkscape =
119         root->version.sodipodi = root->original.sodipodi = zero_version;
121     root->x.unset();
122     root->y.unset();
123     root->width.unset(SVGLength::PERCENT, 1.0, 1.0);
124     root->height.unset(SVGLength::PERCENT, 1.0, 1.0);
126     /* nr_matrix_set_identity(&root->viewbox); */
127     root->viewBox_set = FALSE;
129     root->c2p.set_identity();
131     root->defs = NULL;
134 /**
135  * Fills in the data for an SPObject from its Inkscape::XML::Node object.
136  * It fills in data such as version, x, y, width, height, etc.
137  * It then calls the object's parent class object's build function.
138  */
139 static void
140 sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
142     SPGroup *group = (SPGroup *) object;
143     SPRoot *root = (SPRoot *) object;
145     if (repr->attribute("sodipodi:docname") || repr->attribute("SP-DOCNAME")) {
146         /* so we have a nonzero initial version */
147         root->original.sodipodi.major = 0;
148         root->original.sodipodi.minor = 1;
149     }
150     sp_object_read_attr(object, "version");
151     sp_object_read_attr(object, "sodipodi:version");
152     sp_object_read_attr(object, "inkscape:version");
153     /* It is important to parse these here, so objects will have viewport build-time */
154     sp_object_read_attr(object, "x");
155     sp_object_read_attr(object, "y");
156     sp_object_read_attr(object, "width");
157     sp_object_read_attr(object, "height");
158     sp_object_read_attr(object, "viewBox");
159     sp_object_read_attr(object, "preserveAspectRatio");
161     if (((SPObjectClass *) parent_class)->build)
162         (* ((SPObjectClass *) parent_class)->build) (object, document, repr);
164     /* Search for first <defs> node */
165     for (SPObject *o = sp_object_first_child(SP_OBJECT(group)) ; o != NULL; o = SP_OBJECT_NEXT(o) ) {
166         if (SP_IS_DEFS(o)) {
167             root->defs = SP_DEFS(o);
168             break;
169         }
170     }
172     // clear transform, if any was read in - SVG does not allow transform= on <svg>
173     SP_ITEM(object)->transform = NR::identity();
176 /**
177  * This is a destructor routine for SPRoot objects.  It de-references any \<def\> items and calls
178  * the parent class destructor.
179  */
180 static void
181 sp_root_release(SPObject *object)
183     SPRoot *root = (SPRoot *) object;
184     root->defs = NULL;
186     if (((SPObjectClass *) parent_class)->release)
187         ((SPObjectClass *) parent_class)->release(object);
190 /**
191  * Sets the attribute given by key for SPRoot objects to the value specified by value.
192  */
193 static void
194 sp_root_set(SPObject *object, unsigned int key, gchar const *value)
196     SPRoot *root = SP_ROOT(object);
198     switch (key) {
199         case SP_ATTR_VERSION:
200             if (!sp_version_from_string(value, &root->version.svg)) {
201                 root->version.svg = root->original.svg;
202             }
203             break;
204         case SP_ATTR_SODIPODI_VERSION:
205             if (!sp_version_from_string(value, &root->version.sodipodi)) {
206                 root->version.sodipodi = root->original.sodipodi;
207             }
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, "xMaxYMin")) {
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         default:
334             /* Pass the set event to the parent */
335             if (((SPObjectClass *) parent_class)->set) {
336                 ((SPObjectClass *) parent_class)->set(object, key, value);
337             }
338             break;
339     }
342 /**
343  * This routine is for adding a child SVG object to an SPRoot object.
344  * The SPRoot object is taken to be an SPGroup.
345  */
346 static void
347 sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
349     SPRoot *root = (SPRoot *) object;
350     SPGroup *group = (SPGroup *) object;
352     if (((SPObjectClass *) (parent_class))->child_added)
353         (* ((SPObjectClass *) (parent_class))->child_added)(object, child, ref);
355     SPObject *co = object->document->getObjectByRepr(child);
356     g_assert(co != NULL);
358     if (SP_IS_DEFS(co)) {
359         SPObject *c;
360         /* We search for first <defs> node - it is not beautiful, but works */
361         for (c = sp_object_first_child(SP_OBJECT(group)) ; c != NULL; c = SP_OBJECT_NEXT(c) ) {
362             if (SP_IS_DEFS(c)) {
363                 root->defs = SP_DEFS(c);
364                 break;
365             }
366         }
367     }
370 /**
371  * Removes the given child from this SPRoot object.
372  */
373 static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child)
375     SPRoot *root = (SPRoot *) object;
377     if ( root->defs && SP_OBJECT_REPR(root->defs) == child ) {
378         SPObject *iter;
379         /* We search for first remaining <defs> node - it is not beautiful, but works */
380         for ( iter = sp_object_first_child(object) ; iter ; iter = SP_OBJECT_NEXT(iter) ) {
381             if ( SP_IS_DEFS(iter) && (SPDefs *)iter != root->defs ) {
382                 root->defs = (SPDefs *)iter;
383                 break;
384             }
385         }
386         if (!iter) {
387             /* we should probably create a new <defs> here? */
388             root->defs = NULL;
389         }
390     }
392     if (((SPObjectClass *) (parent_class))->remove_child)
393         (* ((SPObjectClass *) (parent_class))->remove_child)(object, child);
396 /**
397  * This callback routine updates the SPRoot object when its attributes have been changed.
398  */
399 static void
400 sp_root_update(SPObject *object, SPCtx *ctx, guint flags)
402     SPItemView *v;
404     SPItem *item = SP_ITEM(object);
405     SPRoot *root = SP_ROOT(object);
406     SPItemCtx *ictx = (SPItemCtx *) ctx;
408     /* fixme: This will be invoked too often (Lauris) */
409     /* fixme: We should calculate only if parent viewport has changed (Lauris) */
410     /* If position is specified as percentage, calculate actual values */
411     if (root->x.unit == SVGLength::PERCENT) {
412         root->x.computed = root->x.value * (ictx->vp.x1 - ictx->vp.x0);
413     }
414     if (root->y.unit == SVGLength::PERCENT) {
415         root->y.computed = root->y.value * (ictx->vp.y1 - ictx->vp.y0);
416     }
417     if (root->width.unit == SVGLength::PERCENT) {
418         root->width.computed = root->width.value * (ictx->vp.x1 - ictx->vp.x0);
419     }
420     if (root->height.unit == SVGLength::PERCENT) {
421         root->height.computed = root->height.value * (ictx->vp.y1 - ictx->vp.y0);
422     }
424     /* Create copy of item context */
425     SPItemCtx rctx = *ictx;
427     /* Calculate child to parent transformation */
428     root->c2p.set_identity();
430     if (object->parent) {
431         /*
432          * fixme: I am not sure whether setting x and y does or does not
433          * fixme: translate the content of inner SVG.
434          * fixme: Still applying translation and setting viewport to width and
435          * fixme: height seems natural, as this makes the inner svg element
436          * fixme: self-contained. The spec is vague here.
437          */
438         root->c2p = NR::Matrix(NR::translate(root->x.computed,
439                                              root->y.computed));
440     }
442     if (root->viewBox_set) {
443         double x, y, width, height;
444         /* Determine actual viewbox in viewport coordinates */
445         if (root->aspect_align == SP_ASPECT_NONE) {
446             x = 0.0;
447             y = 0.0;
448             width = root->width.computed;
449             height = root->height.computed;
450         } else {
451             double scalex, scaley, scale;
452             /* Things are getting interesting */
453             scalex = root->width.computed / (root->viewBox.x1 - root->viewBox.x0);
454             scaley = root->height.computed / (root->viewBox.y1 - root->viewBox.y0);
455             scale = (root->aspect_clip == SP_ASPECT_MEET) ? MIN(scalex, scaley) : MAX(scalex, scaley);
456             width = (root->viewBox.x1 - root->viewBox.x0) * scale;
457             height = (root->viewBox.y1 - root->viewBox.y0) * scale;
458             /* Now place viewbox to requested position */
459             /* todo: Use an array lookup to find the 0.0/0.5/1.0 coefficients,
460                as is done for dialogs/align.cpp. */
461             switch (root->aspect_align) {
462                 case SP_ASPECT_XMIN_YMIN:
463                     x = 0.0;
464                     y = 0.0;
465                     break;
466                 case SP_ASPECT_XMID_YMIN:
467                     x = 0.5 * (root->width.computed - width);
468                     y = 0.0;
469                     break;
470                 case SP_ASPECT_XMAX_YMIN:
471                     x = 1.0 * (root->width.computed - width);
472                     y = 0.0;
473                     break;
474                 case SP_ASPECT_XMIN_YMID:
475                     x = 0.0;
476                     y = 0.5 * (root->height.computed - height);
477                     break;
478                 case SP_ASPECT_XMID_YMID:
479                     x = 0.5 * (root->width.computed - width);
480                     y = 0.5 * (root->height.computed - height);
481                     break;
482                 case SP_ASPECT_XMAX_YMID:
483                     x = 1.0 * (root->width.computed - width);
484                     y = 0.5 * (root->height.computed - height);
485                     break;
486                 case SP_ASPECT_XMIN_YMAX:
487                     x = 0.0;
488                     y = 1.0 * (root->height.computed - height);
489                     break;
490                 case SP_ASPECT_XMID_YMAX:
491                     x = 0.5 * (root->width.computed - width);
492                     y = 1.0 * (root->height.computed - height);
493                     break;
494                 case SP_ASPECT_XMAX_YMAX:
495                     x = 1.0 * (root->width.computed - width);
496                     y = 1.0 * (root->height.computed - height);
497                     break;
498                 default:
499                     x = 0.0;
500                     y = 0.0;
501                     break;
502             }
503         }
505         /* Compose additional transformation from scale and position */
506         NR::Point const viewBox_min(root->viewBox.x0,
507                                     root->viewBox.y0);
508         NR::Point const viewBox_max(root->viewBox.x1,
509                                     root->viewBox.y1);
510         NR::scale const viewBox_length( viewBox_max - viewBox_min );
511         NR::scale const new_length(width, height);
513         /* Append viewbox transformation */
514         /* TODO: The below looks suspicious to me (pjrm): I wonder whether the RHS
515            expression should have c2p at the beginning rather than at the end.  Test it. */
516         root->c2p = NR::translate(-viewBox_min) * ( new_length / viewBox_length ) * NR::translate(x, y) * root->c2p;
517     }
519     rctx.i2doc = root->c2p * rctx.i2doc;
521     /* Initialize child viewport */
522     if (root->viewBox_set) {
523         rctx.vp.x0 = root->viewBox.x0;
524         rctx.vp.y0 = root->viewBox.y0;
525         rctx.vp.x1 = root->viewBox.x1;
526         rctx.vp.y1 = root->viewBox.y1;
527     } else {
528         /* fixme: I wonder whether this logic is correct (Lauris) */
529         if (object->parent) {
530             rctx.vp.x0 = root->x.computed;
531             rctx.vp.y0 = root->y.computed;
532         } else {
533             rctx.vp.x0 = 0.0;
534             rctx.vp.y0 = 0.0;
535         }
536         rctx.vp.x1 = root->width.computed;
537         rctx.vp.y1 = root->height.computed;
538     }
540     rctx.i2vp = NR::identity();
542     /* And invoke parent method */
543     if (((SPObjectClass *) (parent_class))->update)
544         ((SPObjectClass *) (parent_class))->update(object, (SPCtx *) &rctx, flags);
546     /* As last step set additional transform of arena group */
547     for (v = item->display; v != NULL; v = v->next) {
548         nr_arena_group_set_child_transform(NR_ARENA_GROUP(v->arenaitem), root->c2p);
549     }
552 /**
553  * Calls the <tt>modified</tt> routine of the SPRoot object's parent class.
554  * Also, if the viewport has been modified, it sets the document size to the new
555  * height and width.
556  */
557 static void
558 sp_root_modified(SPObject *object, guint flags)
560     SPRoot *root = SP_ROOT(object);
562     if (((SPObjectClass *) (parent_class))->modified)
563         (* ((SPObjectClass *) (parent_class))->modified)(object, flags);
565     /* fixme: (Lauris) */
566     if (!object->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
567         sp_document_resized_signal_emit (SP_OBJECT_DOCUMENT(root), root->width.computed, root->height.computed);
568     }
571 /**
572  * Writes the object into the repr object, then calls the parent's write routine.
573  */
574 static Inkscape::XML::Node *
575 sp_root_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
577     SPRoot *root = SP_ROOT(object);
579     if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
580         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
581         repr = xml_doc->createElement("svg:svg");
582     }
584     if (flags & SP_OBJECT_WRITE_EXT) {
585         repr->setAttribute("sodipodi:version", SODIPODI_VERSION);
586         repr->setAttribute("inkscape:version", INKSCAPE_VERSION);
587     }
589     repr->setAttribute("version", SVG_VERSION);
591     if (fabs(root->x.computed) > 1e-9)
592         sp_repr_set_svg_double(repr, "x", root->x.computed);
593     if (fabs(root->y.computed) > 1e-9)
594         sp_repr_set_svg_double(repr, "y", root->y.computed);
596     /* Unlike all other SPObject, here we want to preserve absolute units too (and only here,
597      * according to the recommendation in http://www.w3.org/TR/SVG11/coords.html#Units).
598      */
599     repr->setAttribute("width", sp_svg_length_write_with_units(root->width).c_str());
600     repr->setAttribute("height", sp_svg_length_write_with_units(root->height).c_str());
602     if (root->viewBox_set) {
603         Inkscape::SVGOStringStream os;
604         os << root->viewBox.x0 << " " << root->viewBox.y0 << " " << root->viewBox.x1 - root->viewBox.x0 << " " << root->viewBox.y1 - root->viewBox.y0;
605         repr->setAttribute("viewBox", os.str().c_str());
606     }
608     if (((SPObjectClass *) (parent_class))->write)
609         ((SPObjectClass *) (parent_class))->write(object, repr, flags);
611     return repr;
614 /**
615  * Displays the SPRoot item on the NRArena.
616  */
617 static NRArenaItem *
618 sp_root_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags)
620     SPRoot *root = SP_ROOT(item);
622     NRArenaItem *ai;
623     if (((SPItemClass *) (parent_class))->show) {
624         ai = ((SPItemClass *) (parent_class))->show(item, arena, key, flags);
625         if (ai) {
626             nr_arena_group_set_child_transform(NR_ARENA_GROUP(ai), root->c2p);
627         }
628     } else {
629         ai = NULL;
630     }
632     return ai;
635 /**
636  * Virtual bbox callback.
637  */
638 static void
639 sp_root_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags)
641     SPRoot const *root = SP_ROOT(item);
643     if (((SPItemClass *) (parent_class))->bbox) {
644         NR::Matrix const product( root->c2p * transform );
645         ((SPItemClass *) (parent_class))->bbox(item, bbox,
646                                                product,
647                                                flags);
648     }
651 /**
652  * Virtual print callback.
653  */
654 static void
655 sp_root_print(SPItem *item, SPPrintContext *ctx)
657     SPRoot *root = SP_ROOT(item);
659     sp_print_bind(ctx, root->c2p, 1.0);
661     if (((SPItemClass *) (parent_class))->print) {
662         ((SPItemClass *) (parent_class))->print(item, ctx);
663     }
665     sp_print_release(ctx);
669 /*
670   Local Variables:
671   mode:c++
672   c-file-style:"stroustrup"
673   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
674   indent-tabs-mode:nil
675   fill-column:99
676   End:
677 */
678 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :