Code

No more NRMatrix or NRPoint.
[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::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_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
55 static void sp_root_print(SPItem *item, SPPrintContext *ctx);
57 static SPGroupClass *parent_class;
59 /**
60  * Returns the type info of sp_root, including its class sizes and initialization routines.
61  */
62 GType
63 sp_root_get_type(void)
64 {
65     static GType type = 0;
66     if (!type) {
67         GTypeInfo info = {
68             sizeof(SPRootClass),
69             NULL, NULL,
70             (GClassInitFunc) sp_root_class_init,
71             NULL, NULL,
72             sizeof(SPRoot),
73             16,
74             (GInstanceInitFunc) sp_root_init,
75             NULL,   /* value_table */
76         };
77         type = g_type_register_static(SP_TYPE_GROUP, "SPRoot", &info, (GTypeFlags)0);
78     }
79     return type;
80 }
82 /**
83  * Initializes an SPRootClass object by setting its class and parent class objects, and registering
84  * function pointers (i.e.\ gobject-style virtual functions) for various operations.
85  */
86 static void
87 sp_root_class_init(SPRootClass *klass)
88 {
89     GObjectClass *object_class;
90     SPObjectClass *sp_object_class;
91     SPItemClass *sp_item_class;
93     object_class = G_OBJECT_CLASS(klass);
94     sp_object_class = (SPObjectClass *) klass;
95     sp_item_class = (SPItemClass *) klass;
97     parent_class = (SPGroupClass *)g_type_class_ref(SP_TYPE_GROUP);
99     sp_object_class->build = sp_root_build;
100     sp_object_class->release = sp_root_release;
101     sp_object_class->set = sp_root_set;
102     sp_object_class->child_added = sp_root_child_added;
103     sp_object_class->remove_child = sp_root_remove_child;
104     sp_object_class->update = sp_root_update;
105     sp_object_class->modified = sp_root_modified;
106     sp_object_class->write = sp_root_write;
108     sp_item_class->show = sp_root_show;
109     sp_item_class->bbox = sp_root_bbox;
110     sp_item_class->print = sp_root_print;
113 /**
114  * Initializes an SPRoot object by setting its default parameter values.
115  */
116 static void
117 sp_root_init(SPRoot *root)
119     static Inkscape::Version const zero_version(0, 0);
121     sp_version_from_string(SVG_VERSION, &root->original.svg);
122     root->version.svg = root->original.svg;
123     root->version.inkscape = root->original.inkscape =
124         root->version.sodipodi = root->original.sodipodi = zero_version;
126     root->x.unset();
127     root->y.unset();
128     root->width.unset(SVGLength::PERCENT, 1.0, 1.0);
129     root->height.unset(SVGLength::PERCENT, 1.0, 1.0);
131     /* root->viewbox.set_identity(); */
132     root->viewBox_set = FALSE;
134     root->c2p.set_identity();
136     root->defs = NULL;
139 /**
140  * Fills in the data for an SPObject from its Inkscape::XML::Node object.
141  * It fills in data such as version, x, y, width, height, etc.
142  * It then calls the object's parent class object's build function.
143  */
144 static void
145 sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
147     SPGroup *group = (SPGroup *) object;
148     SPRoot *root = (SPRoot *) object;
150     if (repr->attribute("sodipodi:docname") || repr->attribute("SP-DOCNAME")) {
151         /* so we have a nonzero initial version */
152         root->original.sodipodi.major = 0;
153         root->original.sodipodi.minor = 1;
154     }
155     sp_object_read_attr(object, "version");
156     sp_object_read_attr(object, "sodipodi:version");
157     sp_object_read_attr(object, "inkscape:version");
158     /* It is important to parse these here, so objects will have viewport build-time */
159     sp_object_read_attr(object, "x");
160     sp_object_read_attr(object, "y");
161     sp_object_read_attr(object, "width");
162     sp_object_read_attr(object, "height");
163     sp_object_read_attr(object, "viewBox");
164     sp_object_read_attr(object, "preserveAspectRatio");
166     if (((SPObjectClass *) parent_class)->build)
167         (* ((SPObjectClass *) parent_class)->build) (object, document, repr);
169     /* Search for first <defs> node */
170     for (SPObject *o = sp_object_first_child(SP_OBJECT(group)) ; o != NULL; o = SP_OBJECT_NEXT(o) ) {
171         if (SP_IS_DEFS(o)) {
172             root->defs = SP_DEFS(o);
173             break;
174         }
175     }
177     // clear transform, if any was read in - SVG does not allow transform= on <svg>
178     SP_ITEM(object)->transform = NR::identity();
181 /**
182  * This is a destructor routine for SPRoot objects.  It de-references any \<def\> items and calls
183  * the parent class destructor.
184  */
185 static void
186 sp_root_release(SPObject *object)
188     SPRoot *root = (SPRoot *) object;
189     root->defs = NULL;
191     if (((SPObjectClass *) parent_class)->release)
192         ((SPObjectClass *) parent_class)->release(object);
195 /**
196  * Sets the attribute given by key for SPRoot objects to the value specified by value.
197  */
198 static void
199 sp_root_set(SPObject *object, unsigned int key, gchar const *value)
201     SPRoot *root = SP_ROOT(object);
203     switch (key) {
204         case SP_ATTR_VERSION:
205             if (!sp_version_from_string(value, &root->version.svg)) {
206                 root->version.svg = root->original.svg;
207             }
208             break;
209         case SP_ATTR_SODIPODI_VERSION:
210             if (!sp_version_from_string(value, &root->version.sodipodi)) {
211                 root->version.sodipodi = root->original.sodipodi;
212             }
213         case SP_ATTR_INKSCAPE_VERSION:
214             if (!sp_version_from_string(value, &root->version.inkscape)) {
215                 root->version.inkscape = root->original.inkscape;
216             }
217             break;
218         case SP_ATTR_X:
219             if (!root->x.readAbsolute(value)) {
220                 /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
221                 root->x.unset();
222             }
223             /* fixme: I am almost sure these do not require viewport flag (Lauris) */
224             object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
225             break;
226         case SP_ATTR_Y:
227             if (!root->y.readAbsolute(value)) {
228                 /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
229                 root->y.unset();
230             }
231             /* fixme: I am almost sure these do not require viewport flag (Lauris) */
232             object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
233             break;
234         case SP_ATTR_WIDTH:
235             if (!root->width.readAbsolute(value) || !(root->width.computed > 0.0)) {
236                 /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
237                 root->width.unset(SVGLength::PERCENT, 1.0, 1.0);
238             }
239             object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
240             break;
241         case SP_ATTR_HEIGHT:
242             if (!root->height.readAbsolute(value) || !(root->height.computed > 0.0)) {
243                 /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
244                 root->height.unset(SVGLength::PERCENT, 1.0, 1.0);
245             }
246             object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
247             break;
248         case SP_ATTR_VIEWBOX:
249             if (value) {
250                 double x, y, width, height;
251                 char *eptr;
252                 /* fixme: We have to take original item affine into account */
253                 /* fixme: Think (Lauris) */
254                 eptr = (gchar *) value;
255                 x = g_ascii_strtod(eptr, &eptr);
256                 while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
257                 y = g_ascii_strtod(eptr, &eptr);
258                 while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
259                 width = g_ascii_strtod(eptr, &eptr);
260                 while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
261                 height = g_ascii_strtod(eptr, &eptr);
262                 while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
263                 if ((width > 0) && (height > 0)) {
264                     /* Set viewbox */
265                     root->viewBox.x0 = x;
266                     root->viewBox.y0 = y;
267                     root->viewBox.x1 = x + width;
268                     root->viewBox.y1 = y + height;
269                     root->viewBox_set = TRUE;
270                 } else {
271                     root->viewBox_set = FALSE;
272                 }
273             } else {
274                 root->viewBox_set = FALSE;
275             }
276             object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
277             break;
278         case SP_ATTR_PRESERVEASPECTRATIO:
279             /* Do setup before, so we can use break to escape */
280             root->aspect_set = FALSE;
281             root->aspect_align = SP_ASPECT_XMID_YMID;
282             root->aspect_clip = SP_ASPECT_MEET;
283             object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
284             if (value) {
285                 int len;
286                 gchar c[256];
287                 gchar const *p, *e;
288                 unsigned int align, clip;
289                 p = value;
290                 while (*p && *p == 32) p += 1;
291                 if (!*p) break;
292                 e = p;
293                 while (*e && *e != 32) e += 1;
294                 len = e - p;
295                 if (len > 8) break;
296                 memcpy(c, value, len);
297                 c[len] = 0;
298                 /* Now the actual part */
299                 if (!strcmp(c, "none")) {
300                     align = SP_ASPECT_NONE;
301                 } else if (!strcmp(c, "xMinYMin")) {
302                     align = SP_ASPECT_XMIN_YMIN;
303                 } else if (!strcmp(c, "xMidYMin")) {
304                     align = SP_ASPECT_XMID_YMIN;
305                 } else if (!strcmp(c, "xMaxYMin")) {
306                     align = SP_ASPECT_XMAX_YMIN;
307                 } else if (!strcmp(c, "xMinYMid")) {
308                     align = SP_ASPECT_XMIN_YMID;
309                 } else if (!strcmp(c, "xMidYMid")) {
310                     align = SP_ASPECT_XMID_YMID;
311                 } else if (!strcmp(c, "xMaxYMin")) {
312                     align = SP_ASPECT_XMAX_YMID;
313                 } else if (!strcmp(c, "xMinYMax")) {
314                     align = SP_ASPECT_XMIN_YMAX;
315                 } else if (!strcmp(c, "xMidYMax")) {
316                     align = SP_ASPECT_XMID_YMAX;
317                 } else if (!strcmp(c, "xMaxYMax")) {
318                     align = SP_ASPECT_XMAX_YMAX;
319                 } else {
320                     break;
321                 }
322                 clip = SP_ASPECT_MEET;
323                 while (*e && *e == 32) e += 1;
324                 if (e) {
325                     if (!strcmp(e, "meet")) {
326                         clip = SP_ASPECT_MEET;
327                     } else if (!strcmp(e, "slice")) {
328                         clip = SP_ASPECT_SLICE;
329                     } else {
330                         break;
331                     }
332                 }
333                 root->aspect_set = TRUE;
334                 root->aspect_align = align;
335                 root->aspect_clip = clip;
336             }
337             break;
338         default:
339             /* Pass the set event to the parent */
340             if (((SPObjectClass *) parent_class)->set) {
341                 ((SPObjectClass *) parent_class)->set(object, key, value);
342             }
343             break;
344     }
347 /**
348  * This routine is for adding a child SVG object to an SPRoot object.
349  * The SPRoot object is taken to be an SPGroup.
350  */
351 static void
352 sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
354     SPRoot *root = (SPRoot *) object;
355     SPGroup *group = (SPGroup *) object;
357     if (((SPObjectClass *) (parent_class))->child_added)
358         (* ((SPObjectClass *) (parent_class))->child_added)(object, child, ref);
360     SPObject *co = object->document->getObjectByRepr(child);
361     g_assert (co != NULL || !strcmp("comment", child->name())); // comment repr node has no object
363     if (co && SP_IS_DEFS(co)) {
364         SPObject *c;
365         /* We search for first <defs> node - it is not beautiful, but works */
366         for (c = sp_object_first_child(SP_OBJECT(group)) ; c != NULL; c = SP_OBJECT_NEXT(c) ) {
367             if (SP_IS_DEFS(c)) {
368                 root->defs = SP_DEFS(c);
369                 break;
370             }
371         }
372     }
375 /**
376  * Removes the given child from this SPRoot object.
377  */
378 static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child)
380     SPRoot *root = (SPRoot *) object;
382     if ( root->defs && SP_OBJECT_REPR(root->defs) == child ) {
383         SPObject *iter;
384         /* We search for first remaining <defs> node - it is not beautiful, but works */
385         for ( iter = sp_object_first_child(object) ; iter ; iter = SP_OBJECT_NEXT(iter) ) {
386             if ( SP_IS_DEFS(iter) && (SPDefs *)iter != root->defs ) {
387                 root->defs = (SPDefs *)iter;
388                 break;
389             }
390         }
391         if (!iter) {
392             /* we should probably create a new <defs> here? */
393             root->defs = NULL;
394         }
395     }
397     if (((SPObjectClass *) (parent_class))->remove_child)
398         (* ((SPObjectClass *) (parent_class))->remove_child)(object, child);
401 /**
402  * This callback routine updates the SPRoot object when its attributes have been changed.
403  */
404 static void
405 sp_root_update(SPObject *object, SPCtx *ctx, guint flags)
407     SPItemView *v;
409     SPItem *item = SP_ITEM(object);
410     SPRoot *root = SP_ROOT(object);
411     SPItemCtx *ictx = (SPItemCtx *) ctx;
413     /* fixme: This will be invoked too often (Lauris) */
414     /* fixme: We should calculate only if parent viewport has changed (Lauris) */
415     /* If position is specified as percentage, calculate actual values */
416     if (root->x.unit == SVGLength::PERCENT) {
417         root->x.computed = root->x.value * (ictx->vp.x1 - ictx->vp.x0);
418     }
419     if (root->y.unit == SVGLength::PERCENT) {
420         root->y.computed = root->y.value * (ictx->vp.y1 - ictx->vp.y0);
421     }
422     if (root->width.unit == SVGLength::PERCENT) {
423         root->width.computed = root->width.value * (ictx->vp.x1 - ictx->vp.x0);
424     }
425     if (root->height.unit == SVGLength::PERCENT) {
426         root->height.computed = root->height.value * (ictx->vp.y1 - ictx->vp.y0);
427     }
429     /* Create copy of item context */
430     SPItemCtx rctx = *ictx;
432     /* Calculate child to parent transformation */
433     root->c2p.set_identity();
435     if (object->parent) {
436         /*
437          * fixme: I am not sure whether setting x and y does or does not
438          * fixme: translate the content of inner SVG.
439          * fixme: Still applying translation and setting viewport to width and
440          * fixme: height seems natural, as this makes the inner svg element
441          * fixme: self-contained. The spec is vague here.
442          */
443         root->c2p = NR::Matrix(NR::translate(root->x.computed,
444                                              root->y.computed));
445     }
447     if (root->viewBox_set) {
448         double x, y, width, height;
449         /* Determine actual viewbox in viewport coordinates */
450         if (root->aspect_align == SP_ASPECT_NONE) {
451             x = 0.0;
452             y = 0.0;
453             width = root->width.computed;
454             height = root->height.computed;
455         } else {
456             double scalex, scaley, scale;
457             /* Things are getting interesting */
458             scalex = root->width.computed / (root->viewBox.x1 - root->viewBox.x0);
459             scaley = root->height.computed / (root->viewBox.y1 - root->viewBox.y0);
460             scale = (root->aspect_clip == SP_ASPECT_MEET) ? MIN(scalex, scaley) : MAX(scalex, scaley);
461             width = (root->viewBox.x1 - root->viewBox.x0) * scale;
462             height = (root->viewBox.y1 - root->viewBox.y0) * scale;
463             /* Now place viewbox to requested position */
464             /* todo: Use an array lookup to find the 0.0/0.5/1.0 coefficients,
465                as is done for dialogs/align.cpp. */
466             switch (root->aspect_align) {
467                 case SP_ASPECT_XMIN_YMIN:
468                     x = 0.0;
469                     y = 0.0;
470                     break;
471                 case SP_ASPECT_XMID_YMIN:
472                     x = 0.5 * (root->width.computed - width);
473                     y = 0.0;
474                     break;
475                 case SP_ASPECT_XMAX_YMIN:
476                     x = 1.0 * (root->width.computed - width);
477                     y = 0.0;
478                     break;
479                 case SP_ASPECT_XMIN_YMID:
480                     x = 0.0;
481                     y = 0.5 * (root->height.computed - height);
482                     break;
483                 case SP_ASPECT_XMID_YMID:
484                     x = 0.5 * (root->width.computed - width);
485                     y = 0.5 * (root->height.computed - height);
486                     break;
487                 case SP_ASPECT_XMAX_YMID:
488                     x = 1.0 * (root->width.computed - width);
489                     y = 0.5 * (root->height.computed - height);
490                     break;
491                 case SP_ASPECT_XMIN_YMAX:
492                     x = 0.0;
493                     y = 1.0 * (root->height.computed - height);
494                     break;
495                 case SP_ASPECT_XMID_YMAX:
496                     x = 0.5 * (root->width.computed - width);
497                     y = 1.0 * (root->height.computed - height);
498                     break;
499                 case SP_ASPECT_XMAX_YMAX:
500                     x = 1.0 * (root->width.computed - width);
501                     y = 1.0 * (root->height.computed - height);
502                     break;
503                 default:
504                     x = 0.0;
505                     y = 0.0;
506                     break;
507             }
508         }
510         /* Compose additional transformation from scale and position */
511         NR::Point const viewBox_min(root->viewBox.x0,
512                                     root->viewBox.y0);
513         NR::Point const viewBox_max(root->viewBox.x1,
514                                     root->viewBox.y1);
515         NR::scale const viewBox_length( viewBox_max - viewBox_min );
516         NR::scale const new_length(width, height);
518         /* Append viewbox transformation */
519         /* TODO: The below looks suspicious to me (pjrm): I wonder whether the RHS
520            expression should have c2p at the beginning rather than at the end.  Test it. */
521         root->c2p = NR::translate(-viewBox_min) * ( new_length / viewBox_length ) * NR::translate(x, y) * root->c2p;
522     }
524     rctx.i2doc = root->c2p * rctx.i2doc;
526     /* Initialize child viewport */
527     if (root->viewBox_set) {
528         rctx.vp.x0 = root->viewBox.x0;
529         rctx.vp.y0 = root->viewBox.y0;
530         rctx.vp.x1 = root->viewBox.x1;
531         rctx.vp.y1 = root->viewBox.y1;
532     } else {
533         /* fixme: I wonder whether this logic is correct (Lauris) */
534         if (object->parent) {
535             rctx.vp.x0 = root->x.computed;
536             rctx.vp.y0 = root->y.computed;
537         } else {
538             rctx.vp.x0 = 0.0;
539             rctx.vp.y0 = 0.0;
540         }
541         rctx.vp.x1 = root->width.computed;
542         rctx.vp.y1 = root->height.computed;
543     }
545     rctx.i2vp = NR::identity();
547     /* And invoke parent method */
548     if (((SPObjectClass *) (parent_class))->update)
549         ((SPObjectClass *) (parent_class))->update(object, (SPCtx *) &rctx, flags);
551     /* As last step set additional transform of arena group */
552     for (v = item->display; v != NULL; v = v->next) {
553         nr_arena_group_set_child_transform(NR_ARENA_GROUP(v->arenaitem), root->c2p);
554     }
557 /**
558  * Calls the <tt>modified</tt> routine of the SPRoot object's parent class.
559  * Also, if the viewport has been modified, it sets the document size to the new
560  * height and width.
561  */
562 static void
563 sp_root_modified(SPObject *object, guint flags)
565     SPRoot *root = SP_ROOT(object);
567     if (((SPObjectClass *) (parent_class))->modified)
568         (* ((SPObjectClass *) (parent_class))->modified)(object, flags);
570     /* fixme: (Lauris) */
571     if (!object->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
572         sp_document_resized_signal_emit (SP_OBJECT_DOCUMENT(root), root->width.computed, root->height.computed);
573     }
576 /**
577  * Writes the object into the repr object, then calls the parent's write routine.
578  */
579 static Inkscape::XML::Node *
580 sp_root_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
582     SPRoot *root = SP_ROOT(object);
584     if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
585         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
586         repr = xml_doc->createElement("svg:svg");
587     }
589     if (flags & SP_OBJECT_WRITE_EXT) {
590         repr->setAttribute("sodipodi:version", SODIPODI_VERSION);
591         repr->setAttribute("inkscape:version", INKSCAPE_VERSION);
592     }
594     repr->setAttribute("version", SVG_VERSION);
596     if (fabs(root->x.computed) > 1e-9)
597         sp_repr_set_svg_double(repr, "x", root->x.computed);
598     if (fabs(root->y.computed) > 1e-9)
599         sp_repr_set_svg_double(repr, "y", root->y.computed);
601     /* Unlike all other SPObject, here we want to preserve absolute units too (and only here,
602      * according to the recommendation in http://www.w3.org/TR/SVG11/coords.html#Units).
603      */
604     repr->setAttribute("width", sp_svg_length_write_with_units(root->width).c_str());
605     repr->setAttribute("height", sp_svg_length_write_with_units(root->height).c_str());
607     if (root->viewBox_set) {
608         Inkscape::SVGOStringStream os;
609         os << root->viewBox.x0 << " " << root->viewBox.y0 << " " << root->viewBox.x1 - root->viewBox.x0 << " " << root->viewBox.y1 - root->viewBox.y0;
610         repr->setAttribute("viewBox", os.str().c_str());
611     }
613     if (((SPObjectClass *) (parent_class))->write)
614         ((SPObjectClass *) (parent_class))->write(object, repr, flags);
616     return repr;
619 /**
620  * Displays the SPRoot item on the NRArena.
621  */
622 static NRArenaItem *
623 sp_root_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags)
625     SPRoot *root = SP_ROOT(item);
627     NRArenaItem *ai;
628     if (((SPItemClass *) (parent_class))->show) {
629         ai = ((SPItemClass *) (parent_class))->show(item, arena, key, flags);
630         if (ai) {
631             nr_arena_group_set_child_transform(NR_ARENA_GROUP(ai), root->c2p);
632         }
633     } else {
634         ai = NULL;
635     }
637     return ai;
640 /**
641  * Virtual bbox callback.
642  */
643 static void
644 sp_root_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags)
646     SPRoot const *root = SP_ROOT(item);
648     if (((SPItemClass *) (parent_class))->bbox) {
649         NR::Matrix const product( root->c2p * transform );
650         ((SPItemClass *) (parent_class))->bbox(item, bbox,
651                                                product,
652                                                flags);
653     }
656 /**
657  * Virtual print callback.
658  */
659 static void
660 sp_root_print(SPItem *item, SPPrintContext *ctx)
662     SPRoot *root = SP_ROOT(item);
664     sp_print_bind(ctx, root->c2p, 1.0);
666     if (((SPItemClass *) (parent_class))->print) {
667         ((SPItemClass *) (parent_class))->print(item, ctx);
668     }
670     sp_print_release(ctx);
674 /*
675   Local Variables:
676   mode:c++
677   c-file-style:"stroustrup"
678   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
679   indent-tabs-mode:nil
680   fill-column:99
681   End:
682 */
683 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :