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