93
85
sp_item_class->print = sp_symbol_print;
97
sp_symbol_init (SPSymbol *symbol)
88
static void sp_symbol_init(SPSymbol *symbol)
99
90
symbol->viewBox_set = FALSE;
101
92
symbol->c2p = Geom::identity();
105
sp_symbol_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
95
static void sp_symbol_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
110
group = (SPGroup *) object;
111
symbol = (SPSymbol *) object;
113
sp_object_read_attr (object, "viewBox");
114
sp_object_read_attr (object, "preserveAspectRatio");
116
if (((SPObjectClass *) parent_class)->build)
97
object->readAttr( "viewBox" );
98
object->readAttr( "preserveAspectRatio" );
100
if (((SPObjectClass *) parent_class)->build) {
117
101
((SPObjectClass *) parent_class)->build (object, document, repr);
121
sp_symbol_release (SPObject *object)
105
static void sp_symbol_release(SPObject *object)
125
symbol = (SPSymbol *) object;
127
if (((SPObjectClass *) parent_class)->release)
107
if (((SPObjectClass *) parent_class)->release) {
128
108
((SPObjectClass *) parent_class)->release (object);
132
sp_symbol_set (SPObject *object, unsigned int key, const gchar *value)
112
static void sp_symbol_set(SPObject *object, unsigned int key, const gchar *value)
137
item = SP_ITEM (object);
138
symbol = SP_SYMBOL (object);
114
SPSymbol *symbol = SP_SYMBOL(object);
141
117
case SP_ATTR_VIEWBOX:
297
258
case SP_ASPECT_XMID_YMIN:
298
x = 0.5 * ((rctx.vp.x1 - rctx.vp.x0) - width);
259
x = 0.5 * (rctx.viewport.width() - width);
301
262
case SP_ASPECT_XMAX_YMIN:
302
x = 1.0 * ((rctx.vp.x1 - rctx.vp.x0) - width);
263
x = 1.0 * (rctx.viewport.width() - width);
305
266
case SP_ASPECT_XMIN_YMID:
307
y = 0.5 * ((rctx.vp.y1 - rctx.vp.y0) - height);
268
y = 0.5 * (rctx.viewport.height() - height);
309
270
case SP_ASPECT_XMID_YMID:
310
x = 0.5 * ((rctx.vp.x1 - rctx.vp.x0) - width);
311
y = 0.5 * ((rctx.vp.y1 - rctx.vp.y0) - height);
271
x = 0.5 * (rctx.viewport.width() - width);
272
y = 0.5 * (rctx.viewport.height() - height);
313
274
case SP_ASPECT_XMAX_YMID:
314
x = 1.0 * ((rctx.vp.x1 - rctx.vp.x0) - width);
315
y = 0.5 * ((rctx.vp.y1 - rctx.vp.y0) - height);
275
x = 1.0 * (rctx.viewport.width() - width);
276
y = 0.5 * (rctx.viewport.height() - height);
317
278
case SP_ASPECT_XMIN_YMAX:
319
y = 1.0 * ((rctx.vp.y1 - rctx.vp.y0) - height);
280
y = 1.0 * (rctx.viewport.height() - height);
321
282
case SP_ASPECT_XMID_YMAX:
322
x = 0.5 * ((rctx.vp.x1 - rctx.vp.x0) - width);
323
y = 1.0 * ((rctx.vp.y1 - rctx.vp.y0) - height);
283
x = 0.5 * (rctx.viewport.width() - width);
284
y = 1.0 * (rctx.viewport.height() - height);
325
286
case SP_ASPECT_XMAX_YMAX:
326
x = 1.0 * ((rctx.vp.x1 - rctx.vp.x0) - width);
327
y = 1.0 * ((rctx.vp.y1 - rctx.vp.y0) - height);
287
x = 1.0 * (rctx.viewport.width() - width);
288
y = 1.0 * (rctx.viewport.height() - height);
335
296
/* Compose additional transformation from scale and position */
337
q[0] = width / (symbol->viewBox.x1 - symbol->viewBox.x0);
298
q[0] = width / symbol->viewBox.width();
340
q[3] = height / (symbol->viewBox.y1 - symbol->viewBox.y0);
341
q[4] = -symbol->viewBox.x0 * q[0] + x;
342
q[5] = -symbol->viewBox.y0 * q[3] + y;
301
q[3] = height / symbol->viewBox.height();
302
q[4] = -symbol->viewBox.left() * q[0] + x;
303
q[5] = -symbol->viewBox.top() * q[3] + y;
343
304
/* Append viewbox transformation */
344
305
symbol->c2p = q * symbol->c2p;
347
rctx.i2doc = symbol->c2p * (Geom::Matrix)rctx.i2doc;
308
rctx.i2doc = symbol->c2p * (Geom::Affine)rctx.i2doc;
349
310
/* If viewBox is set initialize child viewport */
350
311
/* Otherwise <use> has set it up already */
351
312
if (symbol->viewBox_set) {
352
rctx.vp.x0 = symbol->viewBox.x0;
353
rctx.vp.y0 = symbol->viewBox.y0;
354
rctx.vp.x1 = symbol->viewBox.x1;
355
rctx.vp.y1 = symbol->viewBox.y1;
313
rctx.viewport = symbol->viewBox;
356
314
rctx.i2vp = Geom::identity();
359
/* And invoke parent method */
360
if (((SPObjectClass *) (parent_class))->update)
317
// And invoke parent method
318
if (((SPObjectClass *) (parent_class))->update) {
361
319
((SPObjectClass *) (parent_class))->update (object, (SPCtx *) &rctx, flags);
363
/* As last step set additional transform of arena group */
364
for (v = item->display; v != NULL; v = v->next) {
365
nr_arena_group_set_child_transform(NR_ARENA_GROUP(v->arenaitem), symbol->c2p);
322
// As last step set additional transform of drawing group
323
for (SPItemView *v = symbol->display; v != NULL; v = v->next) {
324
Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem);
325
g->setChildTransform(symbol->c2p);
369
if (((SPObjectClass *) (parent_class))->update)
329
if (((SPObjectClass *) (parent_class))->update) {
370
330
((SPObjectClass *) (parent_class))->update (object, ctx, flags);
375
sp_symbol_modified (SPObject *object, guint flags)
335
static void sp_symbol_modified(SPObject *object, guint flags)
379
symbol = SP_SYMBOL (object);
381
if (((SPObjectClass *) (parent_class))->modified)
339
if (((SPObjectClass *) (parent_class))->modified) {
382
340
(* ((SPObjectClass *) (parent_class))->modified) (object, flags);
385
static Inkscape::XML::Node *
386
sp_symbol_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
344
static Inkscape::XML::Node *sp_symbol_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
390
symbol = SP_SYMBOL (object);
392
348
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
393
349
repr = xml_doc->createElement("svg:symbol");
396
repr->setAttribute("viewBox", object->repr->attribute("viewBox"));
397
repr->setAttribute("preserveAspectRatio", object->repr->attribute("preserveAspectRatio"));
352
//XML Tree being used directly here while it shouldn't be.
353
repr->setAttribute("viewBox", object->getRepr()->attribute("viewBox"));
355
//XML Tree being used directly here while it shouldn't be.
356
repr->setAttribute("preserveAspectRatio", object->getRepr()->attribute("preserveAspectRatio"));
399
if (((SPObjectClass *) (parent_class))->write)
358
if (((SPObjectClass *) (parent_class))->write) {
400
359
((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags);
406
sp_symbol_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags)
365
static Inkscape::DrawingItem *sp_symbol_show(SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags)
411
symbol = SP_SYMBOL (item);
413
if (SP_OBJECT_IS_CLONED (symbol)) {
414
/* Cloned <symbol> is actually renderable */
367
SPSymbol *symbol = SP_SYMBOL(item);
368
Inkscape::DrawingItem *ai = 0;
370
if (symbol->cloned) {
371
// Cloned <symbol> is actually renderable
415
372
if (((SPItemClass *) (parent_class))->show) {
416
ai = ((SPItemClass *) (parent_class))->show (item, arena, key, flags);
418
nr_arena_group_set_child_transform(NR_ARENA_GROUP(ai), symbol->c2p);
373
ai = ((SPItemClass *) (parent_class))->show (item, drawing, key, flags);
374
Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(ai);
376
g->setChildTransform(symbol->c2p);
431
sp_symbol_hide (SPItem *item, unsigned int key)
384
static void sp_symbol_hide(SPItem *item, unsigned int key)
435
symbol = SP_SYMBOL (item);
437
if (SP_OBJECT_IS_CLONED (symbol)) {
386
SPSymbol *symbol = SP_SYMBOL(item);
388
if (symbol->cloned) {
438
389
/* Cloned <symbol> is actually renderable */
439
if (((SPItemClass *) (parent_class))->hide)
390
if (((SPItemClass *) (parent_class))->hide) {
440
391
((SPItemClass *) (parent_class))->hide (item, key);
445
sp_symbol_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags)
396
static Geom::OptRect sp_symbol_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type)
447
398
SPSymbol const *symbol = SP_SYMBOL(item);
449
if (SP_OBJECT_IS_CLONED (symbol)) {
450
/* Cloned <symbol> is actually renderable */
401
if (symbol->cloned) {
402
// Cloned <symbol> is actually renderable
452
404
if (((SPItemClass *) (parent_class))->bbox) {
453
Geom::Matrix const a( symbol->c2p * transform );
454
((SPItemClass *) (parent_class))->bbox(item, bbox, a, flags);
405
Geom::Affine const a( symbol->c2p * transform );
406
bbox = ((SPItemClass *) (parent_class))->bbox(item, a, type);
460
sp_symbol_print (SPItem *item, SPPrintContext *ctx)
412
static void sp_symbol_print(SPItem *item, SPPrintContext *ctx)
462
414
SPSymbol *symbol = SP_SYMBOL(item);
463
if (SP_OBJECT_IS_CLONED (symbol)) {
464
/* Cloned <symbol> is actually renderable */
415
if (symbol->cloned) {
416
// Cloned <symbol> is actually renderable
466
sp_print_bind(ctx, &symbol->c2p, 1.0);
418
sp_print_bind(ctx, symbol->c2p, 1.0);
468
420
if (((SPItemClass *) (parent_class))->print) {
469
421
((SPItemClass *) (parent_class))->print (item, ctx);