~centralelyon2010/inkscape/imagelinks2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
/** \file
 * SVG \<svg\> implementation.
 */
/*
 * Authors:
 *   Lauris Kaplinski <lauris@kaplinski.com>
 *   Jon A. Cruz <jon@joncruz.org>
 *   Abhishek Sharma
 *
 * Copyright (C) 1999-2002 Lauris Kaplinski
 * Copyright (C) 2000-2001 Ximian, Inc.
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <cstring>
#include <string>
#include <2geom/transforms.h>

#include "svg/svg.h"
#include "display/drawing-group.h"
#include "attributes.h"
#include "print.h"
#include "document.h"
#include "sp-defs.h"
#include "sp-root.h"
#include <xml/repr.h>
#include "svg/stringstream.h"
#include "inkscape-version.h"

class SPDesktop;

static void sp_root_class_init(SPRootClass *klass);
static void sp_root_init(SPRoot *root);

static void sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
static void sp_root_release(SPObject *object);
static void sp_root_set(SPObject *object, unsigned int key, gchar const *value);
static void sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child);
static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags);
static void sp_root_modified(SPObject *object, guint flags);
static Inkscape::XML::Node *sp_root_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);

static Inkscape::DrawingItem *sp_root_show(SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags);
static void sp_root_print(SPItem *item, SPPrintContext *ctx);

static SPGroupClass *parent_class;

/**
 * Returns the type info of sp_root, including its class sizes and initialization routines.
 */
GType
sp_root_get_type(void)
{
    static GType type = 0;
    if (!type) {
        GTypeInfo info = {
            sizeof(SPRootClass),
            NULL, NULL,
            (GClassInitFunc) sp_root_class_init,
            NULL, NULL,
            sizeof(SPRoot),
            16,
            (GInstanceInitFunc) sp_root_init,
            NULL,   /* value_table */
        };
        type = g_type_register_static(SP_TYPE_GROUP, "SPRoot", &info, (GTypeFlags)0);
    }
    return type;
}

/**
 * Initializes an SPRootClass object by setting its class and parent class objects, and registering
 * function pointers (i.e.\ gobject-style virtual functions) for various operations.
 */
static void
sp_root_class_init(SPRootClass *klass)
{
    GObjectClass *object_class;
    SPObjectClass *sp_object_class;
    SPItemClass *sp_item_class;

    object_class = G_OBJECT_CLASS(klass);
    sp_object_class = (SPObjectClass *) klass;
    sp_item_class = (SPItemClass *) klass;

    parent_class = (SPGroupClass *)g_type_class_ref(SP_TYPE_GROUP);

    sp_object_class->build = sp_root_build;
    sp_object_class->release = sp_root_release;
    sp_object_class->set = sp_root_set;
    sp_object_class->child_added = sp_root_child_added;
    sp_object_class->remove_child = sp_root_remove_child;
    sp_object_class->update = sp_root_update;
    sp_object_class->modified = sp_root_modified;
    sp_object_class->write = sp_root_write;

    sp_item_class->show = sp_root_show;
    sp_item_class->print = sp_root_print;
}

/**
 * Initializes an SPRoot object by setting its default parameter values.
 */
static void
sp_root_init(SPRoot *root)
{
    static Inkscape::Version const zero_version(0, 0);

    sp_version_from_string(SVG_VERSION, &root->original.svg);
    root->version.svg = zero_version;
    root->original.svg = zero_version;
    root->version.inkscape = zero_version;
    root->original.inkscape = zero_version;

    root->x.unset();
    root->y.unset();
    root->width.unset(SVGLength::PERCENT, 1.0, 1.0);
    root->height.unset(SVGLength::PERCENT, 1.0, 1.0);

    root->viewBox_set = FALSE;

    root->c2p.setIdentity();

    root->defs = NULL;
}

/**
 * Fills in the data for an SPObject from its Inkscape::XML::Node object.
 * It fills in data such as version, x, y, width, height, etc.
 * It then calls the object's parent class object's build function.
 */
static void
sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
{
    SPGroup *group = (SPGroup *) object;
    SPRoot *root = (SPRoot *) object;

    //XML Tree being used directly here while it shouldn't be.
    if ( !object->getRepr()->attribute("version") ) {
        repr->setAttribute("version", SVG_VERSION);
    }

    object->readAttr( "version" );
    object->readAttr( "inkscape:version" );
    /* It is important to parse these here, so objects will have viewport build-time */
    object->readAttr( "x" );
    object->readAttr( "y" );
    object->readAttr( "width" );
    object->readAttr( "height" );
    object->readAttr( "viewBox" );
    object->readAttr( "preserveAspectRatio" );
    object->readAttr( "onload" );

    if (((SPObjectClass *) parent_class)->build)
        (* ((SPObjectClass *) parent_class)->build) (object, document, repr);

    // Search for first <defs> node
    for (SPObject *o = group->firstChild() ; o ; o = o->getNext() ) {
        if (SP_IS_DEFS(o)) {
            root->defs = SP_DEFS(o);
            break;
        }
    }

    // clear transform, if any was read in - SVG does not allow transform= on <svg>
    SP_ITEM(object)->transform = Geom::identity();
}

/**
 * This is a destructor routine for SPRoot objects.  It de-references any \<def\> items and calls
 * the parent class destructor.
 */
static void
sp_root_release(SPObject *object)
{
    SPRoot *root = (SPRoot *) object;
    root->defs = NULL;

    if (((SPObjectClass *) parent_class)->release)
        ((SPObjectClass *) parent_class)->release(object);
}

/**
 * Sets the attribute given by key for SPRoot objects to the value specified by value.
 */
static void
sp_root_set(SPObject *object, unsigned int key, gchar const *value)
{
    SPRoot *root = SP_ROOT(object);

    switch (key) {
        case SP_ATTR_VERSION:
            if (!sp_version_from_string(value, &root->version.svg)) {
                root->version.svg = root->original.svg;
            }
            break;
        case SP_ATTR_INKSCAPE_VERSION:
            if (!sp_version_from_string(value, &root->version.inkscape)) {
                root->version.inkscape = root->original.inkscape;
            }
            break;
        case SP_ATTR_X:
            if (!root->x.readAbsolute(value)) {
                /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
                root->x.unset();
            }
            /* fixme: I am almost sure these do not require viewport flag (Lauris) */
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
            break;
        case SP_ATTR_Y:
            if (!root->y.readAbsolute(value)) {
                /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
                root->y.unset();
            }
            /* fixme: I am almost sure these do not require viewport flag (Lauris) */
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
            break;
        case SP_ATTR_WIDTH:
            if (!root->width.readAbsolute(value) || !(root->width.computed > 0.0)) {
                /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
                root->width.unset(SVGLength::PERCENT, 1.0, 1.0);
            }
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
            break;
        case SP_ATTR_HEIGHT:
            if (!root->height.readAbsolute(value) || !(root->height.computed > 0.0)) {
                /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
                root->height.unset(SVGLength::PERCENT, 1.0, 1.0);
            }
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
            break;
        case SP_ATTR_VIEWBOX:
            if (value) {
                double x, y, width, height;
                char *eptr;
                /* fixme: We have to take original item affine into account */
                /* fixme: Think (Lauris) */
                eptr = (gchar *) value;
                x = g_ascii_strtod(eptr, &eptr);
                while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
                y = g_ascii_strtod(eptr, &eptr);
                while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
                width = g_ascii_strtod(eptr, &eptr);
                while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
                height = g_ascii_strtod(eptr, &eptr);
                while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
                if ((width > 0) && (height > 0)) {
                    /* Set viewbox */
                    root->viewBox = Geom::Rect::from_xywh(x, y, width, height);
                    root->viewBox_set = TRUE;
                } else {
                    root->viewBox_set = FALSE;
                }
            } else {
                root->viewBox_set = FALSE;
            }
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
            break;
        case SP_ATTR_PRESERVEASPECTRATIO:
            /* Do setup before, so we can use break to escape */
            root->aspect_set = FALSE;
            root->aspect_align = SP_ASPECT_XMID_YMID;
            root->aspect_clip = SP_ASPECT_MEET;
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
            if (value) {
                int len;
                gchar c[256];
                gchar const *p, *e;
                unsigned int align, clip;
                p = value;
                while (*p && *p == 32) p += 1;
                if (!*p) break;
                e = p;
                while (*e && *e != 32) e += 1;
                len = e - p;
                if (len > 8) break;
                memcpy(c, value, len);
                c[len] = 0;
                /* Now the actual part */
                if (!strcmp(c, "none")) {
                    align = SP_ASPECT_NONE;
                } else if (!strcmp(c, "xMinYMin")) {
                    align = SP_ASPECT_XMIN_YMIN;
                } else if (!strcmp(c, "xMidYMin")) {
                    align = SP_ASPECT_XMID_YMIN;
                } else if (!strcmp(c, "xMaxYMin")) {
                    align = SP_ASPECT_XMAX_YMIN;
                } else if (!strcmp(c, "xMinYMid")) {
                    align = SP_ASPECT_XMIN_YMID;
                } else if (!strcmp(c, "xMidYMid")) {
                    align = SP_ASPECT_XMID_YMID;
                } else if (!strcmp(c, "xMaxYMid")) {
                    align = SP_ASPECT_XMAX_YMID;
                } else if (!strcmp(c, "xMinYMax")) {
                    align = SP_ASPECT_XMIN_YMAX;
                } else if (!strcmp(c, "xMidYMax")) {
                    align = SP_ASPECT_XMID_YMAX;
                } else if (!strcmp(c, "xMaxYMax")) {
                    align = SP_ASPECT_XMAX_YMAX;
                } else {
                    break;
                }
                clip = SP_ASPECT_MEET;
                while (*e && *e == 32) e += 1;
                if (*e) {
                    if (!strcmp(e, "meet")) {
                        clip = SP_ASPECT_MEET;
                    } else if (!strcmp(e, "slice")) {
                        clip = SP_ASPECT_SLICE;
                    } else {
                        break;
                    }
                }
                root->aspect_set = TRUE;
                root->aspect_align = align;
                root->aspect_clip = clip;
            }
            break;
        case SP_ATTR_ONLOAD:
            root->onload = (char *) value;
            break;
        default:
            /* Pass the set event to the parent */
            if (((SPObjectClass *) parent_class)->set) {
                ((SPObjectClass *) parent_class)->set(object, key, value);
            }
            break;
    }
}

/**
 * This routine is for adding a child SVG object to an SPRoot object.
 * The SPRoot object is taken to be an SPGroup.
 */
static void sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
{
    SPRoot *root = (SPRoot *) object;
    SPGroup *group = (SPGroup *) object;

    if (((SPObjectClass *) (parent_class))->child_added) {
        (* ((SPObjectClass *) (parent_class))->child_added)(object, child, ref);
    }

    SPObject *co = object->document->getObjectByRepr(child);
    g_assert (co != NULL || !strcmp("comment", child->name())); // comment repr node has no object

    if (co && SP_IS_DEFS(co)) {
        // We search for first <defs> node - it is not beautiful, but works
        for (SPObject *c = group->firstChild() ; c ; c = c->getNext() ) {
            if (SP_IS_DEFS(c)) {
                root->defs = SP_DEFS(c);
                break;
            }
        }
    }
}

/**
 * Removes the given child from this SPRoot object.
 */
static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child)
{
    SPRoot *root = (SPRoot *) object;

    if ( root->defs && (root->defs->getRepr() == child) ) {
        SPObject *iter = 0;
        // We search for first remaining <defs> node - it is not beautiful, but works
        for ( iter = object->firstChild() ; iter ; iter = iter->getNext() ) {
            if ( SP_IS_DEFS(iter) && (SPDefs *)iter != root->defs ) {
                root->defs = (SPDefs *)iter;
                break;
            }
        }
        if (!iter) {
            /* we should probably create a new <defs> here? */
            root->defs = NULL;
        }
    }

    if (((SPObjectClass *) (parent_class))->remove_child) {
        (* ((SPObjectClass *) (parent_class))->remove_child)(object, child);
    }
}

/**
 * This callback routine updates the SPRoot object when its attributes have been changed.
 */
static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags)
{
    SPRoot *root = SP_ROOT(object);
    SPItemCtx *ictx = (SPItemCtx *) ctx;

    /* fixme: This will be invoked too often (Lauris) */
    /* fixme: We should calculate only if parent viewport has changed (Lauris) */
    /* If position is specified as percentage, calculate actual values */
    if (root->x.unit == SVGLength::PERCENT) {
        root->x.computed = root->x.value * ictx->viewport.width();
    }
    if (root->y.unit == SVGLength::PERCENT) {
        root->y.computed = root->y.value * ictx->viewport.height();
    }
    if (root->width.unit == SVGLength::PERCENT) {
        root->width.computed = root->width.value * ictx->viewport.width();
    }
    if (root->height.unit == SVGLength::PERCENT) {
        root->height.computed = root->height.value * ictx->viewport.height();
    }

    /* Create copy of item context */
    SPItemCtx rctx = *ictx;

    /* Calculate child to parent transformation */
    root->c2p.setIdentity();

    if (object->parent) {
        /*
         * fixme: I am not sure whether setting x and y does or does not
         * fixme: translate the content of inner SVG.
         * fixme: Still applying translation and setting viewport to width and
         * fixme: height seems natural, as this makes the inner svg element
         * fixme: self-contained. The spec is vague here.
         */
        root->c2p = Geom::Affine(Geom::Translate(root->x.computed,
                                                 root->y.computed));
    }

    if (root->viewBox_set) {
        double x, y, width, height;
        /* Determine actual viewbox in viewport coordinates */
        if (root->aspect_align == SP_ASPECT_NONE) {
            x = 0.0;
            y = 0.0;
            width = root->width.computed;
            height = root->height.computed;
        } else {
            double scalex, scaley, scale;
            /* Things are getting interesting */
            scalex = root->width.computed / root->viewBox.width();
            scaley = root->height.computed / root->viewBox.height();
            scale = (root->aspect_clip == SP_ASPECT_MEET) ? MIN(scalex, scaley) : MAX(scalex, scaley);
            width = root->viewBox.width() * scale;
            height = root->viewBox.height() * scale;
            /* Now place viewbox to requested position */
            /* todo: Use an array lookup to find the 0.0/0.5/1.0 coefficients,
               as is done for dialogs/align.cpp. */
            switch (root->aspect_align) {
                case SP_ASPECT_XMIN_YMIN:
                    x = 0.0;
                    y = 0.0;
                    break;
                case SP_ASPECT_XMID_YMIN:
                    x = 0.5 * (root->width.computed - width);
                    y = 0.0;
                    break;
                case SP_ASPECT_XMAX_YMIN:
                    x = 1.0 * (root->width.computed - width);
                    y = 0.0;
                    break;
                case SP_ASPECT_XMIN_YMID:
                    x = 0.0;
                    y = 0.5 * (root->height.computed - height);
                    break;
                case SP_ASPECT_XMID_YMID:
                    x = 0.5 * (root->width.computed - width);
                    y = 0.5 * (root->height.computed - height);
                    break;
                case SP_ASPECT_XMAX_YMID:
                    x = 1.0 * (root->width.computed - width);
                    y = 0.5 * (root->height.computed - height);
                    break;
                case SP_ASPECT_XMIN_YMAX:
                    x = 0.0;
                    y = 1.0 * (root->height.computed - height);
                    break;
                case SP_ASPECT_XMID_YMAX:
                    x = 0.5 * (root->width.computed - width);
                    y = 1.0 * (root->height.computed - height);
                    break;
                case SP_ASPECT_XMAX_YMAX:
                    x = 1.0 * (root->width.computed - width);
                    y = 1.0 * (root->height.computed - height);
                    break;
                default:
                    x = 0.0;
                    y = 0.0;
                    break;
            }
        }

        /* Compose additional transformation from scale and position */
        Geom::Scale const viewBox_length( root->viewBox.dimensions() );
        Geom::Scale const new_length(width, height);

        /* Append viewbox transformation */
        /* TODO: The below looks suspicious to me (pjrm): I wonder whether the RHS
           expression should have c2p at the beginning rather than at the end.  Test it. */
        root->c2p = Geom::Translate(-root->viewBox.min()) * ( new_length * viewBox_length.inverse() ) * Geom::Translate(x, y) * root->c2p;
    }

    rctx.i2doc = root->c2p * rctx.i2doc;

    /* Initialize child viewport */
    if (root->viewBox_set) {
        rctx.viewport = root->viewBox;
    } else {
        /* fixme: I wonder whether this logic is correct (Lauris) */
        Geom::Point minp(0,0);
        if (object->parent) {
            minp = Geom::Point(root->x.computed, root->y.computed);
        }
        rctx.viewport = Geom::Rect::from_xywh(minp[Geom::X], minp[Geom::Y], root->width.computed, root->height.computed);
    }

    rctx.i2vp = Geom::identity();

    /* And invoke parent method */
    if (((SPObjectClass *) (parent_class))->update)
        ((SPObjectClass *) (parent_class))->update(object, (SPCtx *) &rctx, flags);

    /* As last step set additional transform of drawing group */
    for (SPItemView *v = root->display; v != NULL; v = v->next) {
        Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem);
        g->setChildTransform(root->c2p);
    }
}

/**
 * Calls the <tt>modified</tt> routine of the SPRoot object's parent class.
 * Also, if the viewport has been modified, it sets the document size to the new
 * height and width.
 */
static void
sp_root_modified(SPObject *object, guint flags)
{
    SPRoot *root = SP_ROOT(object);

    if (((SPObjectClass *) (parent_class))->modified)
        (* ((SPObjectClass *) (parent_class))->modified)(object, flags);

    /* fixme: (Lauris) */
    if (!object->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
        root->document->emitResizedSignal(root->width.computed, root->height.computed);
    }
}

/**
 * Writes the object into the repr object, then calls the parent's write routine.
 */
static Inkscape::XML::Node *
sp_root_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
{
    SPRoot *root = SP_ROOT(object);

    if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
        repr = xml_doc->createElement("svg:svg");
    }

    if (flags & SP_OBJECT_WRITE_EXT) {
        repr->setAttribute("inkscape:version", Inkscape::version_string);
    }

    if ( !repr->attribute("version") ) {
        repr->setAttribute("version", sp_version_to_string(root->version.svg));
    }

    if (fabs(root->x.computed) > 1e-9)
        sp_repr_set_svg_double(repr, "x", root->x.computed);
    if (fabs(root->y.computed) > 1e-9)
        sp_repr_set_svg_double(repr, "y", root->y.computed);

    /* Unlike all other SPObject, here we want to preserve absolute units too (and only here,
     * according to the recommendation in http://www.w3.org/TR/SVG11/coords.html#Units).
     */
    repr->setAttribute("width", sp_svg_length_write_with_units(root->width).c_str());
    repr->setAttribute("height", sp_svg_length_write_with_units(root->height).c_str());

    if (root->viewBox_set) {
        Inkscape::SVGOStringStream os;
        os << root->viewBox.left() << " " << root->viewBox.top() << " "
           << root->viewBox.width() << " " << root->viewBox.height();
        repr->setAttribute("viewBox", os.str().c_str());
    }

    if (((SPObjectClass *) (parent_class))->write)
        ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags);

    return repr;
}

/**
 * Displays the SPRoot item on the drawing.
 */
static Inkscape::DrawingItem *
sp_root_show(SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags)
{
    SPRoot *root = SP_ROOT(item);

    Inkscape::DrawingItem *ai;
    if (((SPItemClass *) (parent_class))->show) {
        ai = ((SPItemClass *) (parent_class))->show(item, drawing, key, flags);
        if (ai) {
            Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(ai);
            g->setChildTransform(root->c2p);
        }
    } else {
        ai = NULL;
    }

    return ai;
}

/**
 * Virtual print callback.
 */
static void
sp_root_print(SPItem *item, SPPrintContext *ctx)
{
    SPRoot *root = SP_ROOT(item);

    sp_print_bind(ctx, root->c2p, 1.0);

    if (((SPItemClass *) (parent_class))->print) {
        ((SPItemClass *) (parent_class))->print(item, ctx);
    }

    sp_print_release(ctx);
}


/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :