diff options
| author | Andrew Higginson <at.higginson@gmail.com> | 2011-12-27 21:04:47 +0000 |
|---|---|---|
| committer | Andrew <at.higginson@gmail.com> | 2011-12-27 21:04:47 +0000 |
| commit | 80960b623a99aae1402ab651b2974ef544ed3b03 (patch) | |
| tree | ba49d42c2789e9e11f805e2d5263e10f9fedeef8 /src/sp-symbol.cpp | |
| parent | try to fix bug (diff) | |
| parent | GDL: Cherry-pick upstream patch 73852 (2011-03-23) - Add missing return value. (diff) | |
| download | inkscape-80960b623a99aae1402ab651b2974ef544ed3b03.tar.gz inkscape-80960b623a99aae1402ab651b2974ef544ed3b03.zip | |
merged with trunk so I can build again...
(bzr r10092.1.36)
Diffstat (limited to 'src/sp-symbol.cpp')
| -rw-r--r-- | src/sp-symbol.cpp | 219 |
1 files changed, 84 insertions, 135 deletions
diff --git a/src/sp-symbol.cpp b/src/sp-symbol.cpp index 70ab4d173..87cd210e4 100644 --- a/src/sp-symbol.cpp +++ b/src/sp-symbol.cpp @@ -4,6 +4,7 @@ * Authors: * Lauris Kaplinski <lauris@kaplinski.com> * Abhishek Sharma + * Jon A. Cruz <jon@joncruz.org> * * Copyright (C) 1999-2003 Lauris Kaplinski * @@ -17,10 +18,8 @@ #include <cstring> #include <string> -#include "libnr/nr-matrix-fns.h" -#include "libnr/nr-matrix-ops.h" #include <2geom/transforms.h> -#include "display/nr-arena-group.h" +#include "display/drawing-group.h" #include "xml/repr.h" #include "attributes.h" #include "print.h" @@ -38,9 +37,9 @@ static void sp_symbol_update (SPObject *object, SPCtx *ctx, guint flags); static void sp_symbol_modified (SPObject *object, guint flags); static Inkscape::XML::Node *sp_symbol_write (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); -static NRArenaItem *sp_symbol_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags); +static Inkscape::DrawingItem *sp_symbol_show (SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); static void sp_symbol_hide (SPItem *item, unsigned int key); -static void sp_symbol_bbox(SPItem const *item, NRRect *bbox, Geom::Affine const &transform, unsigned const flags); +static Geom::OptRect sp_symbol_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type); static void sp_symbol_print (SPItem *item, SPPrintContext *ctx); static SPGroupClass *parent_class; @@ -65,16 +64,10 @@ sp_symbol_get_type (void) return type; } -static void -sp_symbol_class_init (SPSymbolClass *klass) +static void sp_symbol_class_init(SPSymbolClass *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; + SPObjectClass *sp_object_class = (SPObjectClass *) klass; + SPItemClass *sp_item_class = (SPItemClass *) klass; parent_class = (SPGroupClass *)g_type_class_ref (SP_TYPE_GROUP); @@ -92,49 +85,33 @@ sp_symbol_class_init (SPSymbolClass *klass) sp_item_class->print = sp_symbol_print; } -static void -sp_symbol_init (SPSymbol *symbol) +static void sp_symbol_init(SPSymbol *symbol) { symbol->viewBox_set = FALSE; symbol->c2p = Geom::identity(); } -static void -sp_symbol_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) +static void sp_symbol_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - SPGroup *group; - SPSymbol *symbol; - - group = (SPGroup *) object; - symbol = (SPSymbol *) object; - object->readAttr( "viewBox" ); object->readAttr( "preserveAspectRatio" ); - if (((SPObjectClass *) parent_class)->build) + if (((SPObjectClass *) parent_class)->build) { ((SPObjectClass *) parent_class)->build (object, document, repr); + } } -static void -sp_symbol_release (SPObject *object) +static void sp_symbol_release(SPObject *object) { - SPSymbol * symbol; - - symbol = (SPSymbol *) object; - - if (((SPObjectClass *) parent_class)->release) + if (((SPObjectClass *) parent_class)->release) { ((SPObjectClass *) parent_class)->release (object); + } } -static void -sp_symbol_set (SPObject *object, unsigned int key, const gchar *value) +static void sp_symbol_set(SPObject *object, unsigned int key, const gchar *value) { - SPItem *item; - SPSymbol *symbol; - - item = SP_ITEM (object); - symbol = SP_SYMBOL (object); + SPSymbol *symbol = SP_SYMBOL(object); switch (key) { case SP_ATTR_VIEWBOX: @@ -154,10 +131,7 @@ sp_symbol_set (SPObject *object, unsigned int key, const gchar *value) while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; if ((width > 0) && (height > 0)) { /* Set viewbox */ - symbol->viewBox.x0 = x; - symbol->viewBox.y0 = y; - symbol->viewBox.x1 = x + width; - symbol->viewBox.y1 = y + height; + symbol->viewBox = Geom::Rect::from_xywh(x, y, width, height); symbol->viewBox_set = TRUE; } else { symbol->viewBox_set = FALSE; @@ -234,30 +208,18 @@ sp_symbol_set (SPObject *object, unsigned int key, const gchar *value) } } -static void -sp_symbol_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) +static void sp_symbol_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { - SPSymbol *symbol; - SPGroup *group; - - symbol = (SPSymbol *) object; - group = (SPGroup *) object; - - if (((SPObjectClass *) (parent_class))->child_added) + if (((SPObjectClass *) (parent_class))->child_added) { ((SPObjectClass *) (parent_class))->child_added (object, child, ref); + } } -static void -sp_symbol_update (SPObject *object, SPCtx *ctx, guint flags) +static void sp_symbol_update(SPObject *object, SPCtx *ctx, guint flags) { - SPItem *item; - SPSymbol *symbol; - SPItemCtx *ictx, rctx; - SPItemView *v; - - item = SP_ITEM (object); - symbol = SP_SYMBOL (object); - ictx = (SPItemCtx *) ctx; + SPSymbol *symbol = SP_SYMBOL(object); + SPItemCtx *ictx = (SPItemCtx *) ctx; + SPItemCtx rctx; if (object->cloned) { /* Cloned <symbol> is actually renderable */ @@ -269,7 +231,7 @@ sp_symbol_update (SPObject *object, SPCtx *ctx, guint flags) /* Calculate child to parent transformation */ /* Apply parent <use> translation (set up as vewport) */ - symbol->c2p = Geom::Affine(Geom::Translate(rctx.vp.x0, rctx.vp.y0)); + symbol->c2p = Geom::Translate(rctx.viewport.min()); if (symbol->viewBox_set) { double x, y, width, height; @@ -277,16 +239,16 @@ sp_symbol_update (SPObject *object, SPCtx *ctx, guint flags) if (symbol->aspect_align == SP_ASPECT_NONE) { x = 0.0; y = 0.0; - width = rctx.vp.x1 - rctx.vp.x0; - height = rctx.vp.y1 - rctx.vp.y0; + width = rctx.viewport.width(); + height = rctx.viewport.height(); } else { double scalex, scaley, scale; /* Things are getting interesting */ - scalex = (rctx.vp.x1 - rctx.vp.x0) / (symbol->viewBox.x1 - symbol->viewBox.x0); - scaley = (rctx.vp.y1 - rctx.vp.y0) / (symbol->viewBox.y1 - symbol->viewBox.y0); + scalex = rctx.viewport.width() / symbol->viewBox.width(); + scaley = rctx.viewport.height() / symbol->viewBox.height(); scale = (symbol->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley); - width = (symbol->viewBox.x1 - symbol->viewBox.x0) * scale; - height = (symbol->viewBox.y1 - symbol->viewBox.y0) * scale; + width = symbol->viewBox.width() * scale; + height = symbol->viewBox.height() * scale; /* Now place viewbox to requested position */ switch (symbol->aspect_align) { case SP_ASPECT_XMIN_YMIN: @@ -294,36 +256,36 @@ sp_symbol_update (SPObject *object, SPCtx *ctx, guint flags) y = 0.0; break; case SP_ASPECT_XMID_YMIN: - x = 0.5 * ((rctx.vp.x1 - rctx.vp.x0) - width); + x = 0.5 * (rctx.viewport.width() - width); y = 0.0; break; case SP_ASPECT_XMAX_YMIN: - x = 1.0 * ((rctx.vp.x1 - rctx.vp.x0) - width); + x = 1.0 * (rctx.viewport.width() - width); y = 0.0; break; case SP_ASPECT_XMIN_YMID: x = 0.0; - y = 0.5 * ((rctx.vp.y1 - rctx.vp.y0) - height); + y = 0.5 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMID_YMID: - x = 0.5 * ((rctx.vp.x1 - rctx.vp.x0) - width); - y = 0.5 * ((rctx.vp.y1 - rctx.vp.y0) - height); + x = 0.5 * (rctx.viewport.width() - width); + y = 0.5 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMAX_YMID: - x = 1.0 * ((rctx.vp.x1 - rctx.vp.x0) - width); - y = 0.5 * ((rctx.vp.y1 - rctx.vp.y0) - height); + x = 1.0 * (rctx.viewport.width() - width); + y = 0.5 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMIN_YMAX: x = 0.0; - y = 1.0 * ((rctx.vp.y1 - rctx.vp.y0) - height); + y = 1.0 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMID_YMAX: - x = 0.5 * ((rctx.vp.x1 - rctx.vp.x0) - width); - y = 1.0 * ((rctx.vp.y1 - rctx.vp.y0) - height); + x = 0.5 * (rctx.viewport.width() - width); + y = 1.0 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMAX_YMAX: - x = 1.0 * ((rctx.vp.x1 - rctx.vp.x0) - width); - y = 1.0 * ((rctx.vp.y1 - rctx.vp.y0) - height); + x = 1.0 * (rctx.viewport.width() - width); + y = 1.0 * (rctx.viewport.height() - height); break; default: x = 0.0; @@ -333,12 +295,12 @@ sp_symbol_update (SPObject *object, SPCtx *ctx, guint flags) } /* Compose additional transformation from scale and position */ Geom::Affine q; - q[0] = width / (symbol->viewBox.x1 - symbol->viewBox.x0); + q[0] = width / symbol->viewBox.width(); q[1] = 0.0; q[2] = 0.0; - q[3] = height / (symbol->viewBox.y1 - symbol->viewBox.y0); - q[4] = -symbol->viewBox.x0 * q[0] + x; - q[5] = -symbol->viewBox.y0 * q[3] + y; + q[3] = height / symbol->viewBox.height(); + q[4] = -symbol->viewBox.left() * q[0] + x; + q[5] = -symbol->viewBox.top() * q[3] + y; /* Append viewbox transformation */ symbol->c2p = q * symbol->c2p; } @@ -348,45 +310,40 @@ sp_symbol_update (SPObject *object, SPCtx *ctx, guint flags) /* If viewBox is set initialize child viewport */ /* Otherwise <use> has set it up already */ if (symbol->viewBox_set) { - rctx.vp.x0 = symbol->viewBox.x0; - rctx.vp.y0 = symbol->viewBox.y0; - rctx.vp.x1 = symbol->viewBox.x1; - rctx.vp.y1 = symbol->viewBox.y1; + rctx.viewport = symbol->viewBox; rctx.i2vp = Geom::identity(); } - /* And invoke parent method */ - if (((SPObjectClass *) (parent_class))->update) + // And invoke parent method + if (((SPObjectClass *) (parent_class))->update) { ((SPObjectClass *) (parent_class))->update (object, (SPCtx *) &rctx, flags); + } - /* As last step set additional transform of arena group */ - for (v = item->display; v != NULL; v = v->next) { - nr_arena_group_set_child_transform(NR_ARENA_GROUP(v->arenaitem), symbol->c2p); + // As last step set additional transform of drawing group + for (SPItemView *v = symbol->display; v != NULL; v = v->next) { + Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem); + g->setChildTransform(symbol->c2p); } } else { - /* No-op */ - if (((SPObjectClass *) (parent_class))->update) + // No-op + if (((SPObjectClass *) (parent_class))->update) { ((SPObjectClass *) (parent_class))->update (object, ctx, flags); + } } } -static void -sp_symbol_modified (SPObject *object, guint flags) +static void sp_symbol_modified(SPObject *object, guint flags) { - SPSymbol *symbol; + SP_SYMBOL(object); - symbol = SP_SYMBOL (object); - - if (((SPObjectClass *) (parent_class))->modified) + if (((SPObjectClass *) (parent_class))->modified) { (* ((SPObjectClass *) (parent_class))->modified) (object, flags); + } } -static Inkscape::XML::Node * -sp_symbol_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static Inkscape::XML::Node *sp_symbol_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPSymbol *symbol; - - symbol = SP_SYMBOL (object); + SP_SYMBOL(object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:symbol"); @@ -405,68 +362,60 @@ sp_symbol_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::X return repr; } -static NRArenaItem * -sp_symbol_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags) +static Inkscape::DrawingItem *sp_symbol_show(SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { - SPSymbol *symbol; - NRArenaItem *ai; - - symbol = SP_SYMBOL (item); + SPSymbol *symbol = SP_SYMBOL(item); + Inkscape::DrawingItem *ai = 0; if (symbol->cloned) { - /* Cloned <symbol> is actually renderable */ + // Cloned <symbol> is actually renderable if (((SPItemClass *) (parent_class))->show) { - ai = ((SPItemClass *) (parent_class))->show (item, arena, key, flags); - if (ai) { - nr_arena_group_set_child_transform(NR_ARENA_GROUP(ai), symbol->c2p); + ai = ((SPItemClass *) (parent_class))->show (item, drawing, key, flags); + Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(ai); + if (g) { + g->setChildTransform(symbol->c2p); } - } else { - ai = NULL; } - } else { - ai = NULL; } return ai; } -static void -sp_symbol_hide (SPItem *item, unsigned int key) +static void sp_symbol_hide(SPItem *item, unsigned int key) { - SPSymbol *symbol; - - symbol = SP_SYMBOL (item); + SPSymbol *symbol = SP_SYMBOL(item); if (symbol->cloned) { /* Cloned <symbol> is actually renderable */ - if (((SPItemClass *) (parent_class))->hide) + if (((SPItemClass *) (parent_class))->hide) { ((SPItemClass *) (parent_class))->hide (item, key); + } } } -static void -sp_symbol_bbox(SPItem const *item, NRRect *bbox, Geom::Affine const &transform, unsigned const flags) +static Geom::OptRect sp_symbol_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) { SPSymbol const *symbol = SP_SYMBOL(item); + Geom::OptRect bbox; if (symbol->cloned) { - /* Cloned <symbol> is actually renderable */ + // Cloned <symbol> is actually renderable if (((SPItemClass *) (parent_class))->bbox) { Geom::Affine const a( symbol->c2p * transform ); - ((SPItemClass *) (parent_class))->bbox(item, bbox, a, flags); + bbox = ((SPItemClass *) (parent_class))->bbox(item, a, type); } } + return bbox; } -static void -sp_symbol_print (SPItem *item, SPPrintContext *ctx) +static void sp_symbol_print(SPItem *item, SPPrintContext *ctx) { SPSymbol *symbol = SP_SYMBOL(item); if (symbol->cloned) { - /* Cloned <symbol> is actually renderable */ + // Cloned <symbol> is actually renderable - sp_print_bind(ctx, &symbol->c2p, 1.0); + sp_print_bind(ctx, symbol->c2p, 1.0); if (((SPItemClass *) (parent_class))->print) { ((SPItemClass *) (parent_class))->print (item, ctx); |
