From 578d85febc1afde9024c335ae9d88358b82e40a1 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 19 Aug 2012 02:54:53 +0200 Subject: Added "virtual pad" to SPRoot. (bzr r11608.1.20) --- src/sp-root.cpp | 188 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 128 insertions(+), 60 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 393c70895..2b1ab3884 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -96,11 +96,24 @@ static void sp_root_class_init(SPRootClass *klass) sp_item_class->print = sp_root_print; } +CRoot::CRoot(SPRoot* root) : CGroup(root) { + this->sproot = root; +} + +CRoot::~CRoot() { +} + /** * Initializes an SPRoot object by setting its default parameter values. */ static void sp_root_init(SPRoot *root) { + root->croot = new CRoot(root); + root->cgroup = root->croot; + root->clpeitem = root->croot; + root->citem = root->croot; + root->cobject = root->croot; + static Inkscape::Version const zero_version(0, 0); sp_version_from_string(SVG_VERSION, &root->original.svg); @@ -121,13 +134,9 @@ static void sp_root_init(SPRoot *root) 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) -{ +void CRoot::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPRoot* object = this->sproot; + SPGroup *group = (SPGroup *) object; SPRoot *root = (SPRoot *) object; @@ -147,8 +156,7 @@ static void sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML: object->readAttr( "preserveAspectRatio" ); object->readAttr( "onload" ); - if (((SPObjectClass *) parent_class)->build) - (* ((SPObjectClass *) parent_class)->build) (object, document, repr); + CGroup::onBuild(document, repr); // Search for first node for (SPObject *o = group->firstChild() ; o ; o = o->getNext() ) { @@ -162,25 +170,39 @@ static void sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML: SP_ITEM(object)->transform = Geom::identity(); } +// CPPIFY: remove /** - * This is a destructor routine for SPRoot objects. It de-references any \ items and calls - * the parent class destructor. + * 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_release(SPObject *object) +static void sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { + ((SPRoot*)object)->croot->onBuild(document, repr); +} + +void CRoot::onRelease() { + SPRoot* object = this->sproot; + SPRoot *root = (SPRoot *) object; root->defs = NULL; - if (((SPObjectClass *) parent_class)->release) - ((SPObjectClass *) parent_class)->release(object); + CGroup::onRelease(); } +// CPPIFY: remove /** - * Sets the attribute given by key for SPRoot objects to the value specified by value. + * This is a destructor routine for SPRoot objects. It de-references any \ items and calls + * the parent class destructor. */ -static void sp_root_set(SPObject *object, unsigned int key, gchar const *value) +static void sp_root_release(SPObject *object) { - SPRoot *root = SP_ROOT(object); + ((SPRoot*)object)->croot->onRelease(); +} + +void CRoot::onSet(unsigned int key, const gchar* value) { + SPRoot* object = this->sproot; + SPRoot *root = object; switch (key) { case SP_ATTR_VERSION: @@ -315,25 +337,27 @@ static void sp_root_set(SPObject *object, unsigned int key, gchar const *value) break; default: /* Pass the set event to the parent */ - if (((SPObjectClass *) parent_class)->set) { - ((SPObjectClass *) parent_class)->set(object, key, value); - } + CGroup::onSet(key, value); break; } } +// CPPIFY: remove /** - * This routine is for adding a child SVG object to an SPRoot object. - * The SPRoot object is taken to be an SPGroup. + * Sets the attribute given by key for SPRoot objects to the value specified by value. */ -static void sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) +static void sp_root_set(SPObject *object, unsigned int key, gchar const *value) { + ((SPRoot*)object)->croot->onSet(key, value); +} + +void CRoot::onChildAdded(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { + SPRoot* object = this->sproot; + SPRoot *root = (SPRoot *) object; SPGroup *group = (SPGroup *) object; - if (((SPObjectClass *) (parent_class))->child_added) { - (* ((SPObjectClass *) (parent_class))->child_added)(object, child, ref); - } + CGroup::onChildAdded(child, ref); SPObject *co = object->document->getObjectByRepr(child); g_assert (co != NULL || !strcmp("comment", child->name())); // comment repr node has no object @@ -349,11 +373,19 @@ static void sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, In } } +// CPPIFY: remove /** - * Removes the given child from this SPRoot object. + * 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_remove_child(SPObject *object, Inkscape::XML::Node *child) +static void sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { + ((SPRoot*)object)->croot->onChildAdded(child, ref); +} + +void CRoot::onRemoveChild(Inkscape::XML::Node* child) { + SPRoot* object = this->sproot; + SPRoot *root = (SPRoot *) object; if ( root->defs && (root->defs->getRepr() == child) ) { @@ -371,16 +403,21 @@ static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child) } } - if (((SPObjectClass *) (parent_class))->remove_child) { - (* ((SPObjectClass *) (parent_class))->remove_child)(object, child); - } + CGroup::onRemoveChild(child); } +// CPPIFY: remove /** - * This callback routine updates the SPRoot object when its attributes have been changed. + * Removes the given child from this SPRoot object. */ -static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags) +static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child) { + ((SPRoot*)object)->croot->onRemoveChild(child); +} + +void CRoot::onUpdate(SPCtx *ctx, guint flags) { + SPRoot* object = this->sproot; + SPRoot *root = SP_ROOT(object); SPItemCtx *ictx = (SPItemCtx *) ctx; @@ -508,8 +545,7 @@ static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags) rctx.i2vp = Geom::identity(); /* And invoke parent method */ - if (((SPObjectClass *) (parent_class))->update) - ((SPObjectClass *) (parent_class))->update(object, (SPCtx *) &rctx, flags); + CGroup::onUpdate((SPCtx *) &rctx, flags); /* As last step set additional transform of drawing group */ for (SPItemView *v = root->display; v != NULL; v = v->next) { @@ -518,17 +554,21 @@ static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags) } } +// CPPIFY: remove /** - * Calls the modified 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. + * This callback routine updates the SPRoot object when its attributes have been changed. */ -static void sp_root_modified(SPObject *object, guint flags) +static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags) { + ((SPRoot*)object)->croot->onUpdate(ctx, flags); +} + +void CRoot::onModified(unsigned int flags) { + SPRoot* object = this->sproot; + SPRoot *root = SP_ROOT(object); - if (((SPObjectClass *) (parent_class))->modified) - (* ((SPObjectClass *) (parent_class))->modified)(object, flags); + CGroup::onModified(flags); /* fixme: (Lauris) */ if (!object->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { @@ -536,12 +576,20 @@ static void sp_root_modified(SPObject *object, guint flags) } } +// CPPIFY: remove /** - * Writes the object into the repr object, then calls the parent's write routine. + * Calls the modified 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 Inkscape::XML::Node * -sp_root_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void sp_root_modified(SPObject *object, guint flags) { + ((SPRoot*)object)->croot->onModified(flags); +} + +Inkscape::XML::Node* CRoot::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPRoot* object = this->sproot; + SPRoot *root = SP_ROOT(object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { @@ -576,39 +624,51 @@ sp_root_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML: repr->setAttribute("viewBox", os.str().c_str()); } - if (((SPObjectClass *) (parent_class))->write) - ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); + CGroup::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove /** - * Displays the SPRoot item on the drawing. + * Writes the object into the repr object, then calls the parent's write routine. */ -static Inkscape::DrawingItem * -sp_root_show(SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) +static Inkscape::XML::Node * +sp_root_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + return ((SPRoot*)object)->croot->onWrite(xml_doc, repr, flags); +} + +Inkscape::DrawingItem* CRoot::onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { + SPRoot* item = this->sproot; + 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(ai); - g->setChildTransform(root->c2p); - } - } else { - ai = NULL; + Inkscape::DrawingItem *ai = 0; + + ai = CGroup::onShow(drawing, key, flags); + + if (ai) { + Inkscape::DrawingGroup *g = dynamic_cast(ai); + g->setChildTransform(root->c2p); } return ai; } +// CPPIFY: remove /** - * Virtual print callback. + * Displays the SPRoot item on the drawing. */ -static void sp_root_print(SPItem *item, SPPrintContext *ctx) +static Inkscape::DrawingItem * +sp_root_show(SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { + return ((SPRoot*)item)->croot->onShow(drawing, key, flags); +} + +void CRoot::onPrint(SPPrintContext* ctx) { + SPRoot* item = this->sproot; + SPRoot *root = SP_ROOT(item); sp_print_bind(ctx, root->c2p, 1.0); @@ -620,6 +680,14 @@ static void sp_root_print(SPItem *item, SPPrintContext *ctx) sp_print_release(ctx); } +// CPPIFY: remove +/** + * Virtual print callback. + */ +static void sp_root_print(SPItem *item, SPPrintContext *ctx) +{ + ((SPRoot*)item)->croot->onPrint(ctx); +} /* Local Variables: -- cgit v1.2.3 From 99cb30e28d4ee193f39e23464abbd7630cac8a2d Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 6 Oct 2012 23:56:27 +0200 Subject: Added virtual pad to SPFlowtext; removed old calls to virtual SPItem methods. (bzr r11608.1.46) --- src/sp-root.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 2b1ab3884..96b9f4ef9 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -92,8 +92,8 @@ static void sp_root_class_init(SPRootClass *klass) 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; +// sp_item_class->show = sp_root_show; +// sp_item_class->print = sp_root_print; } CRoot::CRoot(SPRoot* root) : CGroup(root) { @@ -673,9 +673,11 @@ void CRoot::onPrint(SPPrintContext* ctx) { sp_print_bind(ctx, root->c2p, 1.0); - if (((SPItemClass *) (parent_class))->print) { - ((SPItemClass *) (parent_class))->print(item, ctx); - } +// if (((SPItemClass *) (parent_class))->print) { +// ((SPItemClass *) (parent_class))->print(item, ctx); +// } + // CPPIFY: correct one? + CGroup::onPrint(ctx); sp_print_release(ctx); } -- cgit v1.2.3 From d5640b0cc2463ee3470d18891fbd8304ba3339ee Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Thu, 24 Jan 2013 11:43:26 +0000 Subject: More GObject boilerplate cleanup (bzr r12059) --- src/sp-root.cpp | 71 +++++++++++++++++---------------------------------------- 1 file changed, 21 insertions(+), 50 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 393c70895..e9ae6dff4 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -31,11 +31,6 @@ #include "svg/svg.h" #include "xml/repr.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); @@ -48,29 +43,7 @@ static Inkscape::XML::Node *sp_root_write(SPObject *object, Inkscape::XML::Docum 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; -} +G_DEFINE_TYPE(SPRoot, sp_root, SP_TYPE_GROUP); /** * Initializes an SPRootClass object by setting its class and parent class objects, and registering @@ -81,8 +54,6 @@ static void sp_root_class_init(SPRootClass *klass) SPObjectClass *sp_object_class = reinterpret_cast(klass); SPItemClass *sp_item_class = reinterpret_cast(klass); - parent_class = reinterpret_cast(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; @@ -147,8 +118,8 @@ static void sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML: object->readAttr( "preserveAspectRatio" ); object->readAttr( "onload" ); - if (((SPObjectClass *) parent_class)->build) - (* ((SPObjectClass *) parent_class)->build) (object, document, repr); + if (((SPObjectClass *) sp_root_parent_class)->build) + (* ((SPObjectClass *) sp_root_parent_class)->build) (object, document, repr); // Search for first node for (SPObject *o = group->firstChild() ; o ; o = o->getNext() ) { @@ -171,8 +142,8 @@ static void sp_root_release(SPObject *object) SPRoot *root = (SPRoot *) object; root->defs = NULL; - if (((SPObjectClass *) parent_class)->release) - ((SPObjectClass *) parent_class)->release(object); + if (((SPObjectClass *) sp_root_parent_class)->release) + ((SPObjectClass *) sp_root_parent_class)->release(object); } /** @@ -315,8 +286,8 @@ static void sp_root_set(SPObject *object, unsigned int key, gchar const *value) break; default: /* Pass the set event to the parent */ - if (((SPObjectClass *) parent_class)->set) { - ((SPObjectClass *) parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_root_parent_class)->set) { + ((SPObjectClass *) sp_root_parent_class)->set(object, key, value); } break; } @@ -331,8 +302,8 @@ static void sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, In SPRoot *root = (SPRoot *) object; SPGroup *group = (SPGroup *) object; - if (((SPObjectClass *) (parent_class))->child_added) { - (* ((SPObjectClass *) (parent_class))->child_added)(object, child, ref); + if (((SPObjectClass *) (sp_root_parent_class))->child_added) { + (* ((SPObjectClass *) (sp_root_parent_class))->child_added)(object, child, ref); } SPObject *co = object->document->getObjectByRepr(child); @@ -371,8 +342,8 @@ static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child) } } - if (((SPObjectClass *) (parent_class))->remove_child) { - (* ((SPObjectClass *) (parent_class))->remove_child)(object, child); + if (((SPObjectClass *) (sp_root_parent_class))->remove_child) { + (* ((SPObjectClass *) (sp_root_parent_class))->remove_child)(object, child); } } @@ -508,8 +479,8 @@ static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags) rctx.i2vp = Geom::identity(); /* And invoke parent method */ - if (((SPObjectClass *) (parent_class))->update) - ((SPObjectClass *) (parent_class))->update(object, (SPCtx *) &rctx, flags); + if (((SPObjectClass *) (sp_root_parent_class))->update) + ((SPObjectClass *) (sp_root_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) { @@ -527,8 +498,8 @@ 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); + if (((SPObjectClass *) (sp_root_parent_class))->modified) + (* ((SPObjectClass *) (sp_root_parent_class))->modified)(object, flags); /* fixme: (Lauris) */ if (!object->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { @@ -576,8 +547,8 @@ sp_root_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML: repr->setAttribute("viewBox", os.str().c_str()); } - if (((SPObjectClass *) (parent_class))->write) - ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); + if (((SPObjectClass *) (sp_root_parent_class))->write) + ((SPObjectClass *) (sp_root_parent_class))->write(object, xml_doc, repr, flags); return repr; } @@ -591,8 +562,8 @@ sp_root_show(SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigne SPRoot *root = SP_ROOT(item); Inkscape::DrawingItem *ai; - if (((SPItemClass *) (parent_class))->show) { - ai = ((SPItemClass *) (parent_class))->show(item, drawing, key, flags); + if (((SPItemClass *) (sp_root_parent_class))->show) { + ai = ((SPItemClass *) (sp_root_parent_class))->show(item, drawing, key, flags); if (ai) { Inkscape::DrawingGroup *g = dynamic_cast(ai); g->setChildTransform(root->c2p); @@ -613,8 +584,8 @@ static void sp_root_print(SPItem *item, SPPrintContext *ctx) sp_print_bind(ctx, root->c2p, 1.0); - if (((SPItemClass *) (parent_class))->print) { - ((SPItemClass *) (parent_class))->print(item, ctx); + if (((SPItemClass *) (sp_root_parent_class))->print) { + ((SPItemClass *) (sp_root_parent_class))->print(item, ctx); } sp_print_release(ctx); -- cgit v1.2.3 From a0a8d020201e0e38a63d9aa3dce228d7d9e6fb35 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Thu, 14 Mar 2013 12:42:39 +0100 Subject: Various changes. (bzr r11608.1.48) --- src/sp-root.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 96b9f4ef9..2d6cf0fc4 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -83,7 +83,7 @@ static void sp_root_class_init(SPRootClass *klass) parent_class = reinterpret_cast(g_type_class_ref(SP_TYPE_GROUP)); - sp_object_class->build = sp_root_build; + //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; -- cgit v1.2.3 From 957c3e4b7909d42c5a13f1b1dd583f877fc32259 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 30 Mar 2013 00:46:57 +0100 Subject: Removed function pointers from SPObject and subclasses. Added some missing virtual pads for classes that were hidden by preprocessor macros. (bzr r11608.1.55) --- src/sp-root.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 2d6cf0fc4..d19629a24 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -84,13 +84,13 @@ static void sp_root_class_init(SPRootClass *klass) parent_class = reinterpret_cast(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_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; -- cgit v1.2.3 From 7df6616da5ea2debb86838366ddf746841549cdb Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 30 Mar 2013 00:56:13 +0100 Subject: Renamed virtual function names. (bzr r11608.1.57) --- src/sp-root.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 9a38cd05d..715d4659e 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -81,7 +81,7 @@ static void sp_root_init(SPRoot *root) root->defs = NULL; } -void CRoot::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { +void CRoot::build(SPDocument *document, Inkscape::XML::Node *repr) { SPRoot* object = this->sproot; SPGroup *group = (SPGroup *) object; @@ -103,7 +103,7 @@ void CRoot::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { object->readAttr( "preserveAspectRatio" ); object->readAttr( "onload" ); - CGroup::onBuild(document, repr); + CGroup::build(document, repr); // Search for first node for (SPObject *o = group->firstChild() ; o ; o = o->getNext() ) { @@ -117,17 +117,17 @@ void CRoot::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { SP_ITEM(object)->transform = Geom::identity(); } -void CRoot::onRelease() { +void CRoot::release() { SPRoot* object = this->sproot; SPRoot *root = (SPRoot *) object; root->defs = NULL; - CGroup::onRelease(); + CGroup::release(); } -void CRoot::onSet(unsigned int key, const gchar* value) { +void CRoot::set(unsigned int key, const gchar* value) { SPRoot* object = this->sproot; SPRoot *root = object; @@ -264,18 +264,18 @@ void CRoot::onSet(unsigned int key, const gchar* value) { break; default: /* Pass the set event to the parent */ - CGroup::onSet(key, value); + CGroup::set(key, value); break; } } -void CRoot::onChildAdded(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { +void CRoot::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { SPRoot* object = this->sproot; SPRoot *root = (SPRoot *) object; SPGroup *group = (SPGroup *) object; - CGroup::onChildAdded(child, ref); + CGroup::child_added(child, ref); SPObject *co = object->document->getObjectByRepr(child); g_assert (co != NULL || !strcmp("comment", child->name())); // comment repr node has no object @@ -291,7 +291,7 @@ void CRoot::onChildAdded(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { } } -void CRoot::onRemoveChild(Inkscape::XML::Node* child) { +void CRoot::remove_child(Inkscape::XML::Node* child) { SPRoot* object = this->sproot; SPRoot *root = (SPRoot *) object; @@ -311,10 +311,10 @@ void CRoot::onRemoveChild(Inkscape::XML::Node* child) { } } - CGroup::onRemoveChild(child); + CGroup::remove_child(child); } -void CRoot::onUpdate(SPCtx *ctx, guint flags) { +void CRoot::update(SPCtx *ctx, guint flags) { SPRoot* object = this->sproot; SPRoot *root = SP_ROOT(object); @@ -444,7 +444,7 @@ void CRoot::onUpdate(SPCtx *ctx, guint flags) { rctx.i2vp = Geom::identity(); /* And invoke parent method */ - CGroup::onUpdate((SPCtx *) &rctx, flags); + CGroup::update((SPCtx *) &rctx, flags); /* As last step set additional transform of drawing group */ for (SPItemView *v = root->display; v != NULL; v = v->next) { @@ -453,12 +453,12 @@ void CRoot::onUpdate(SPCtx *ctx, guint flags) { } } -void CRoot::onModified(unsigned int flags) { +void CRoot::modified(unsigned int flags) { SPRoot* object = this->sproot; SPRoot *root = SP_ROOT(object); - CGroup::onModified(flags); + CGroup::modified(flags); /* fixme: (Lauris) */ if (!object->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { @@ -467,7 +467,7 @@ void CRoot::onModified(unsigned int flags) { } -Inkscape::XML::Node* CRoot::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { +Inkscape::XML::Node* CRoot::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPRoot* object = this->sproot; SPRoot *root = SP_ROOT(object); @@ -504,19 +504,19 @@ Inkscape::XML::Node* CRoot::onWrite(Inkscape::XML::Document *xml_doc, Inkscape:: repr->setAttribute("viewBox", os.str().c_str()); } - CGroup::onWrite(xml_doc, repr, flags); + CGroup::write(xml_doc, repr, flags); return repr; } -Inkscape::DrawingItem* CRoot::onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { +Inkscape::DrawingItem* CRoot::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { SPRoot* item = this->sproot; SPRoot *root = SP_ROOT(item); Inkscape::DrawingItem *ai = 0; - ai = CGroup::onShow(drawing, key, flags); + ai = CGroup::show(drawing, key, flags); if (ai) { Inkscape::DrawingGroup *g = dynamic_cast(ai); @@ -526,14 +526,14 @@ Inkscape::DrawingItem* CRoot::onShow(Inkscape::Drawing &drawing, unsigned int ke return ai; } -void CRoot::onPrint(SPPrintContext* ctx) { +void CRoot::print(SPPrintContext* ctx) { SPRoot* item = this->sproot; SPRoot *root = SP_ROOT(item); sp_print_bind(ctx, root->c2p, 1.0); - CGroup::onPrint(ctx); + CGroup::print(ctx); sp_print_release(ctx); } -- cgit v1.2.3 From a5d6e692d661f0bf7648e64e8fcb04588bb8f3ab Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Mon, 1 Apr 2013 00:07:00 +0200 Subject: Prepared exchange of casting macros. (bzr r11608.1.63) --- src/sp-root.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 715d4659e..1767c4cd2 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -54,6 +54,7 @@ CRoot::~CRoot() { static void sp_root_init(SPRoot *root) { root->croot = new CRoot(root); + root->typeHierarchy.insert(typeid(SPRoot)); delete root->cgroup; root->cgroup = root->croot; -- cgit v1.2.3 From 69f3b6f1abb2bb422935d43262e1e99aab359954 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 01:41:30 +0200 Subject: Added constructors to SP classes. (bzr r11608.1.67) --- src/sp-root.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 1767c4cd2..ac2ffdbf7 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -31,7 +31,7 @@ #include "svg/svg.h" #include "xml/repr.h" -G_DEFINE_TYPE(SPRoot, sp_root, SP_TYPE_GROUP); +G_DEFINE_TYPE(SPRoot, sp_root, G_TYPE_OBJECT); /** * Initializes an SPRootClass object by setting its class and parent class objects, and registering @@ -48,11 +48,9 @@ CRoot::CRoot(SPRoot* root) : CGroup(root) { CRoot::~CRoot() { } -/** - * Initializes an SPRoot object by setting its default parameter values. - */ -static void sp_root_init(SPRoot *root) -{ +SPRoot::SPRoot() : SPGroup() { + SPRoot* root = this; + root->croot = new CRoot(root); root->typeHierarchy.insert(typeid(SPRoot)); @@ -62,6 +60,11 @@ static void sp_root_init(SPRoot *root) root->citem = root->croot; root->cobject = root->croot; + root->aspect_set = 0; + root->aspect_align = 0; + root->onload = NULL; + root->aspect_clip = 0; + static Inkscape::Version const zero_version(0, 0); sp_version_from_string(SVG_VERSION, &root->original.svg); @@ -82,6 +85,14 @@ static void sp_root_init(SPRoot *root) root->defs = NULL; } +/** + * Initializes an SPRoot object by setting its default parameter values. + */ +static void sp_root_init(SPRoot *root) +{ + new (root) SPRoot(); +} + void CRoot::build(SPDocument *document, Inkscape::XML::Node *repr) { SPRoot* object = this->sproot; -- cgit v1.2.3 From d1af3566872dfff2aeec84859c87f1f8d13f79df Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 19:14:36 +0200 Subject: Registered classes with new factory. Hkern, Vkern and FeFuncX have to be rewritten, as they aren't real classes. (bzr r11608.1.69) --- src/sp-root.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index ac2ffdbf7..8dcae05be 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -31,6 +31,16 @@ #include "svg/svg.h" #include "xml/repr.h" +#include "sp-factory.h" + +namespace { + SPObject* createRoot() { + return new SPRoot(); + } + + bool rootRegistered = SPFactory::instance().registerObject("svg:svg", createRoot); +} + G_DEFINE_TYPE(SPRoot, sp_root, G_TYPE_OBJECT); /** -- cgit v1.2.3 From dbda80349e95767e390a178cda7c05787fbce1fe Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 17:51:29 +0200 Subject: Merged Group and subclasses. (bzr r11608.1.77) --- src/sp-root.cpp | 459 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 233 insertions(+), 226 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 8dcae05be..77ae15f85 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -41,206 +41,214 @@ namespace { bool rootRegistered = SPFactory::instance().registerObject("svg:svg", createRoot); } -G_DEFINE_TYPE(SPRoot, sp_root, G_TYPE_OBJECT); - -/** - * 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) -{ -} - -CRoot::CRoot(SPRoot* root) : CGroup(root) { - this->sproot = root; -} - -CRoot::~CRoot() { -} - SPRoot::SPRoot() : SPGroup() { - SPRoot* root = this; - - root->croot = new CRoot(root); - root->typeHierarchy.insert(typeid(SPRoot)); + this->clpeitem = this; + this->citem = this; + this->cobject = this; - delete root->cgroup; - root->cgroup = root->croot; - root->clpeitem = root->croot; - root->citem = root->croot; - root->cobject = root->croot; - - root->aspect_set = 0; - root->aspect_align = 0; - root->onload = NULL; - root->aspect_clip = 0; + this->aspect_set = 0; + this->aspect_align = 0; + this->onload = NULL; + this->aspect_clip = 0; 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; + sp_version_from_string(SVG_VERSION, &this->original.svg); + this->version.svg = zero_version; + this->original.svg = zero_version; + this->version.inkscape = zero_version; + this->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); + this->x.unset(); + this->y.unset(); + this->width.unset(SVGLength::PERCENT, 1.0, 1.0); + this->height.unset(SVGLength::PERCENT, 1.0, 1.0); - root->viewBox_set = FALSE; + this->viewBox_set = FALSE; - root->c2p.setIdentity(); + this->c2p.setIdentity(); - root->defs = NULL; + this->defs = NULL; } -/** - * Initializes an SPRoot object by setting its default parameter values. - */ -static void sp_root_init(SPRoot *root) -{ - new (root) SPRoot(); +SPRoot::~SPRoot() { } -void CRoot::build(SPDocument *document, Inkscape::XML::Node *repr) { - SPRoot* object = this->sproot; - - SPGroup *group = (SPGroup *) object; - SPRoot *root = (SPRoot *) object; - +void SPRoot::build(SPDocument *document, Inkscape::XML::Node *repr) { //XML Tree being used directly here while it shouldn't be. - if ( !object->getRepr()->attribute("version") ) { + if ( !this->getRepr()->attribute("version") ) { repr->setAttribute("version", SVG_VERSION); } - object->readAttr( "version" ); - object->readAttr( "inkscape:version" ); + this->readAttr( "version" ); + this->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" ); + this->readAttr( "x" ); + this->readAttr( "y" ); + this->readAttr( "width" ); + this->readAttr( "height" ); + this->readAttr( "viewBox" ); + this->readAttr( "preserveAspectRatio" ); + this->readAttr( "onload" ); - CGroup::build(document, repr); + SPGroup::build(document, repr); // Search for first node - for (SPObject *o = group->firstChild() ; o ; o = o->getNext() ) { + for (SPObject *o = this->firstChild() ; o ; o = o->getNext() ) { if (SP_IS_DEFS(o)) { - root->defs = SP_DEFS(o); + this->defs = SP_DEFS(o); break; } } // clear transform, if any was read in - SVG does not allow transform= on - SP_ITEM(object)->transform = Geom::identity(); + SP_ITEM(this)->transform = Geom::identity(); } -void CRoot::release() { - SPRoot* object = this->sproot; - - SPRoot *root = (SPRoot *) object; - root->defs = NULL; +void SPRoot::release() { + this->defs = NULL; - CGroup::release(); + SPGroup::release(); } -void CRoot::set(unsigned int key, const gchar* value) { - SPRoot* object = this->sproot; - SPRoot *root = object; - +void SPRoot::set(unsigned int key, const gchar* value) { switch (key) { case SP_ATTR_VERSION: - if (!sp_version_from_string(value, &root->version.svg)) { - root->version.svg = root->original.svg; + if (!sp_version_from_string(value, &this->version.svg)) { + this->version.svg = this->original.svg; } break; + case SP_ATTR_INKSCAPE_VERSION: - if (!sp_version_from_string(value, &root->version.inkscape)) { - root->version.inkscape = root->original.inkscape; + if (!sp_version_from_string(value, &this->version.inkscape)) { + this->version.inkscape = this->original.inkscape; } break; + case SP_ATTR_X: - if (!root->x.readAbsolute(value)) { + if (!this->x.readAbsolute(value)) { /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ - root->x.unset(); + this->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); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); break; + case SP_ATTR_Y: - if (!root->y.readAbsolute(value)) { + if (!this->y.readAbsolute(value)) { /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ - root->y.unset(); + this->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); + this->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)) { + if (!this->width.readAbsolute(value) || !(this->width.computed > 0.0)) { /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ - root->width.unset(SVGLength::PERCENT, 1.0, 1.0); + this->width.unset(SVGLength::PERCENT, 1.0, 1.0); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); + + this->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)) { + if (!this->height.readAbsolute(value) || !(this->height.computed > 0.0)) { /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ - root->height.unset(SVGLength::PERCENT, 1.0, 1.0); + this->height.unset(SVGLength::PERCENT, 1.0, 1.0); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); + + this->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++; + + while (*eptr && ((*eptr == ',') || (*eptr == ' '))) { + eptr++; + } + y = g_ascii_strtod(eptr, &eptr); - while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; + + while (*eptr && ((*eptr == ',') || (*eptr == ' '))) { + eptr++; + } + width = g_ascii_strtod(eptr, &eptr); - while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; + + while (*eptr && ((*eptr == ',') || (*eptr == ' '))) { + eptr++; + } + height = g_ascii_strtod(eptr, &eptr); - while (*eptr && ((*eptr == ',') || (*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; + this->viewBox = Geom::Rect::from_xywh(x, y, width, height); + this->viewBox_set = TRUE; } else { - root->viewBox_set = FALSE; + this->viewBox_set = FALSE; } } else { - root->viewBox_set = FALSE; + this->viewBox_set = FALSE; } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); + + this->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); + this->aspect_set = FALSE; + this->aspect_align = SP_ASPECT_XMID_YMID; + this->aspect_clip = SP_ASPECT_MEET; + + this->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; + + while (*p && *p == 32) { + p += 1; + } + + if (!*p) { + break; + } + e = p; - while (*e && *e != 32) e += 1; + + while (*e && *e != 32) { + e += 1; + } + len = e - p; - if (len > 8) break; + + if (len > 8) { + break; + } + memcpy(c, value, len); + c[len] = 0; + /* Now the actual part */ if (!strcmp(c, "none")) { align = SP_ASPECT_NONE; @@ -265,8 +273,13 @@ void CRoot::set(unsigned int key, const gchar* value) { } else { break; } + clip = SP_ASPECT_MEET; - while (*e && *e == 32) e += 1; + + while (*e && *e == 32) { + e += 1; + } + if (*e) { if (!strcmp(e, "meet")) { clip = SP_ASPECT_MEET; @@ -276,95 +289,91 @@ void CRoot::set(unsigned int key, const gchar* value) { break; } } - root->aspect_set = TRUE; - root->aspect_align = align; - root->aspect_clip = clip; + + this->aspect_set = TRUE; + this->aspect_align = align; + this->aspect_clip = clip; } break; + case SP_ATTR_ONLOAD: - root->onload = (char *) value; + this->onload = (char *) value; break; + default: /* Pass the set event to the parent */ - CGroup::set(key, value); + SPGroup::set(key, value); break; } } -void CRoot::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { - SPRoot* object = this->sproot; - - SPRoot *root = (SPRoot *) object; - SPGroup *group = (SPGroup *) object; +void SPRoot::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { + SPGroup::child_added(child, ref); - CGroup::child_added(child, ref); - - SPObject *co = object->document->getObjectByRepr(child); + SPObject *co = this->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 node - it is not beautiful, but works - for (SPObject *c = group->firstChild() ; c ; c = c->getNext() ) { + for (SPObject *c = this->firstChild() ; c ; c = c->getNext() ) { if (SP_IS_DEFS(c)) { - root->defs = SP_DEFS(c); + this->defs = SP_DEFS(c); break; } } } } -void CRoot::remove_child(Inkscape::XML::Node* child) { - SPRoot* object = this->sproot; - - SPRoot *root = (SPRoot *) object; - - if ( root->defs && (root->defs->getRepr() == child) ) { +void SPRoot::remove_child(Inkscape::XML::Node* child) { + if ( this->defs && (this->defs->getRepr() == child) ) { SPObject *iter = 0; + // We search for first remaining 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; + for ( iter = this->firstChild() ; iter ; iter = iter->getNext() ) { + if ( SP_IS_DEFS(iter) && (SPDefs *)iter != this->defs ) { + this->defs = (SPDefs *)iter; break; } } + if (!iter) { /* we should probably create a new here? */ - root->defs = NULL; + this->defs = NULL; } } - CGroup::remove_child(child); + SPGroup::remove_child(child); } -void CRoot::update(SPCtx *ctx, guint flags) { - SPRoot* object = this->sproot; - - SPRoot *root = SP_ROOT(object); +void SPRoot::update(SPCtx *ctx, guint flags) { 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 (this->x.unit == SVGLength::PERCENT) { + this->x.computed = this->x.value * ictx->viewport.width(); } - if (root->y.unit == SVGLength::PERCENT) { - root->y.computed = root->y.value * ictx->viewport.height(); + + if (this->y.unit == SVGLength::PERCENT) { + this->y.computed = this->y.value * ictx->viewport.height(); } - if (root->width.unit == SVGLength::PERCENT) { - root->width.computed = root->width.value * ictx->viewport.width(); + + if (this->width.unit == SVGLength::PERCENT) { + this->width.computed = this->width.value * ictx->viewport.width(); } - if (root->height.unit == SVGLength::PERCENT) { - root->height.computed = root->height.value * ictx->viewport.height(); + + if (this->height.unit == SVGLength::PERCENT) { + this->height.computed = this->height.value * ictx->viewport.height(); } /* Create copy of item context */ SPItemCtx rctx = *ictx; /* Calculate child to parent transformation */ - root->c2p.setIdentity(); + this->c2p.setIdentity(); - if (object->parent) { + if (this->parent) { /* * fixme: I am not sure whether setting x and y does or does not * fixme: translate the content of inner SVG. @@ -372,66 +381,75 @@ void CRoot::update(SPCtx *ctx, guint flags) { * 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)); + this->c2p = Geom::Affine(Geom::Translate(this->x.computed, this->y.computed)); } - if (root->viewBox_set) { + if (this->viewBox_set) { double x, y, width, height; /* Determine actual viewbox in viewport coordinates */ - if (root->aspect_align == SP_ASPECT_NONE) { + if (this->aspect_align == SP_ASPECT_NONE) { x = 0.0; y = 0.0; - width = root->width.computed; - height = root->height.computed; + width = this->width.computed; + height = this->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; + scalex = this->width.computed / this->viewBox.width(); + scaley = this->height.computed / this->viewBox.height(); + scale = (this->aspect_clip == SP_ASPECT_MEET) ? MIN(scalex, scaley) : MAX(scalex, scaley); + width = this->viewBox.width() * scale; + height = this->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) { + switch (this->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); + x = 0.5 * (this->width.computed - width); y = 0.0; break; + case SP_ASPECT_XMAX_YMIN: - x = 1.0 * (root->width.computed - width); + x = 1.0 * (this->width.computed - width); y = 0.0; break; + case SP_ASPECT_XMIN_YMID: x = 0.0; - y = 0.5 * (root->height.computed - height); + y = 0.5 * (this->height.computed - height); break; + case SP_ASPECT_XMID_YMID: - x = 0.5 * (root->width.computed - width); - y = 0.5 * (root->height.computed - height); + x = 0.5 * (this->width.computed - width); + y = 0.5 * (this->height.computed - height); break; + case SP_ASPECT_XMAX_YMID: - x = 1.0 * (root->width.computed - width); - y = 0.5 * (root->height.computed - height); + x = 1.0 * (this->width.computed - width); + y = 0.5 * (this->height.computed - height); break; + case SP_ASPECT_XMIN_YMAX: x = 0.0; - y = 1.0 * (root->height.computed - height); + y = 1.0 * (this->height.computed - height); break; + case SP_ASPECT_XMID_YMAX: - x = 0.5 * (root->width.computed - width); - y = 1.0 * (root->height.computed - height); + x = 0.5 * (this->width.computed - width); + y = 1.0 * (this->height.computed - height); break; + case SP_ASPECT_XMAX_YMAX: - x = 1.0 * (root->width.computed - width); - y = 1.0 * (root->height.computed - height); + x = 1.0 * (this->width.computed - width); + y = 1.0 * (this->height.computed - height); break; + default: x = 0.0; y = 0.0; @@ -440,60 +458,53 @@ void CRoot::update(SPCtx *ctx, guint flags) { } /* Compose additional transformation from scale and position */ - Geom::Scale const viewBox_length( root->viewBox.dimensions() ); + Geom::Scale const viewBox_length( this->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; + this->c2p = Geom::Translate(-this->viewBox.min()) * ( new_length * viewBox_length.inverse() ) * Geom::Translate(x, y) * this->c2p; } - rctx.i2doc = root->c2p * rctx.i2doc; + rctx.i2doc = this->c2p * rctx.i2doc; /* Initialize child viewport */ - if (root->viewBox_set) { - rctx.viewport = root->viewBox; + if (this->viewBox_set) { + rctx.viewport = this->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); + if (this->parent) { + minp = Geom::Point(this->x.computed, this->y.computed); } - rctx.viewport = Geom::Rect::from_xywh(minp[Geom::X], minp[Geom::Y], root->width.computed, root->height.computed); + + rctx.viewport = Geom::Rect::from_xywh(minp[Geom::X], minp[Geom::Y], this->width.computed, this->height.computed); } rctx.i2vp = Geom::identity(); /* And invoke parent method */ - CGroup::update((SPCtx *) &rctx, flags); + SPGroup::update((SPCtx *) &rctx, flags); /* As last step set additional transform of drawing group */ - for (SPItemView *v = root->display; v != NULL; v = v->next) { + for (SPItemView *v = this->display; v != NULL; v = v->next) { Inkscape::DrawingGroup *g = dynamic_cast(v->arenaitem); - g->setChildTransform(root->c2p); + g->setChildTransform(this->c2p); } } -void CRoot::modified(unsigned int flags) { - SPRoot* object = this->sproot; - - SPRoot *root = SP_ROOT(object); - - CGroup::modified(flags); +void SPRoot::modified(unsigned int flags) { + SPGroup::modified(flags); /* fixme: (Lauris) */ - if (!object->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - root->document->emitResizedSignal(root->width.computed, root->height.computed); + if (!this->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + this->document->emitResizedSignal(this->width.computed, this->height.computed); } } -Inkscape::XML::Node* CRoot::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPRoot* object = this->sproot; - - SPRoot *root = SP_ROOT(object); - +Inkscape::XML::Node* SPRoot::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:svg"); } @@ -503,59 +514,55 @@ Inkscape::XML::Node* CRoot::write(Inkscape::XML::Document *xml_doc, Inkscape::XM } if ( !repr->attribute("version") ) { - gchar* myversion = sp_version_to_string(root->version.svg); + gchar* myversion = sp_version_to_string(this->version.svg); repr->setAttribute("version", myversion); g_free(myversion); } - 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); + if (fabs(this->x.computed) > 1e-9) { + sp_repr_set_svg_double(repr, "x", this->x.computed); + } + + if (fabs(this->y.computed) > 1e-9) { + sp_repr_set_svg_double(repr, "y", this->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()); + repr->setAttribute("width", sp_svg_length_write_with_units(this->width).c_str()); + repr->setAttribute("height", sp_svg_length_write_with_units(this->height).c_str()); - if (root->viewBox_set) { + if (this->viewBox_set) { Inkscape::SVGOStringStream os; - os << root->viewBox.left() << " " << root->viewBox.top() << " " - << root->viewBox.width() << " " << root->viewBox.height(); + os << this->viewBox.left() << " " << this->viewBox.top() << " " + << this->viewBox.width() << " " << this->viewBox.height(); + repr->setAttribute("viewBox", os.str().c_str()); } - CGroup::write(xml_doc, repr, flags); + SPGroup::write(xml_doc, repr, flags); return repr; } -Inkscape::DrawingItem* CRoot::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { - SPRoot* item = this->sproot; - - SPRoot *root = SP_ROOT(item); - +Inkscape::DrawingItem* SPRoot::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { Inkscape::DrawingItem *ai = 0; - ai = CGroup::show(drawing, key, flags); + ai = SPGroup::show(drawing, key, flags); if (ai) { Inkscape::DrawingGroup *g = dynamic_cast(ai); - g->setChildTransform(root->c2p); + g->setChildTransform(this->c2p); } return ai; } -void CRoot::print(SPPrintContext* ctx) { - SPRoot* item = this->sproot; - - SPRoot *root = SP_ROOT(item); - - sp_print_bind(ctx, root->c2p, 1.0); +void SPRoot::print(SPPrintContext* ctx) { + sp_print_bind(ctx, this->c2p, 1.0); - CGroup::print(ctx); + SPGroup::print(ctx); sp_print_release(ctx); } -- cgit v1.2.3 From 19d00efa85cfc42ccae9bd17ef575602f0d22c50 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 19:42:32 +0200 Subject: Merged more classes. (bzr r11608.1.78) --- src/sp-root.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 77ae15f85..c0e71ed2c 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -42,7 +42,6 @@ namespace { } SPRoot::SPRoot() : SPGroup() { - this->clpeitem = this; this->citem = this; this->cobject = this; -- cgit v1.2.3 From 8073924aacdda310fb7492750f78d5389b3186af Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 22:45:01 +0200 Subject: Merged Item. (bzr r11608.1.81) --- src/sp-root.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index c0e71ed2c..b1484759d 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -42,7 +42,6 @@ namespace { } SPRoot::SPRoot() : SPGroup() { - this->citem = this; this->cobject = this; this->aspect_set = 0; -- cgit v1.2.3 From 27e2102f96a5554bcd5310ec11435d155773b279 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 7 Apr 2013 18:28:22 +0200 Subject: Merge Object and subclasses. Merging of SP- and C-classes complete. (bzr r11608.1.86) --- src/sp-root.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index b1484759d..4faefabef 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -42,8 +42,6 @@ namespace { } SPRoot::SPRoot() : SPGroup() { - this->cobject = this; - this->aspect_set = 0; this->aspect_align = 0; this->onload = NULL; -- cgit v1.2.3 From 72a748b2303caf2c16a98c175d7f444d3b558ca5 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Fri, 20 Sep 2013 00:30:19 +0200 Subject: Fix assertion failure on Ctrl+C (bzr r12548) --- src/sp-root.cpp | 490 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 253 insertions(+), 237 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 4faefabef..c87c8397d 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -34,18 +34,20 @@ #include "sp-factory.h" namespace { - SPObject* createRoot() { - return new SPRoot(); - } +SPObject *createRoot() +{ + return new SPRoot(); +} - bool rootRegistered = SPFactory::instance().registerObject("svg:svg", createRoot); +bool rootRegistered = SPFactory::instance().registerObject("svg:svg", createRoot); } -SPRoot::SPRoot() : SPGroup() { - this->aspect_set = 0; - this->aspect_align = 0; - this->onload = NULL; - this->aspect_clip = 0; +SPRoot::SPRoot() : SPGroup() +{ + this->aspect_set = 0; + this->aspect_align = 0; + this->onload = NULL; + this->aspect_clip = 0; static Inkscape::Version const zero_version(0, 0); @@ -67,30 +69,32 @@ SPRoot::SPRoot() : SPGroup() { this->defs = NULL; } -SPRoot::~SPRoot() { +SPRoot::~SPRoot() +{ } -void SPRoot::build(SPDocument *document, Inkscape::XML::Node *repr) { +void SPRoot::build(SPDocument *document, Inkscape::XML::Node *repr) +{ //XML Tree being used directly here while it shouldn't be. - if ( !this->getRepr()->attribute("version") ) { + if (!this->getRepr()->attribute("version")) { repr->setAttribute("version", SVG_VERSION); } - this->readAttr( "version" ); - this->readAttr( "inkscape:version" ); + this->readAttr("version"); + this->readAttr("inkscape:version"); /* It is important to parse these here, so objects will have viewport build-time */ - this->readAttr( "x" ); - this->readAttr( "y" ); - this->readAttr( "width" ); - this->readAttr( "height" ); - this->readAttr( "viewBox" ); - this->readAttr( "preserveAspectRatio" ); - this->readAttr( "onload" ); + this->readAttr("x"); + this->readAttr("y"); + this->readAttr("width"); + this->readAttr("height"); + this->readAttr("viewBox"); + this->readAttr("preserveAspectRatio"); + this->readAttr("onload"); SPGroup::build(document, repr); // Search for first node - for (SPObject *o = this->firstChild() ; o ; o = o->getNext() ) { + for (SPObject *o = this->firstChild() ; o ; o = o->getNext()) { if (SP_IS_DEFS(o)) { this->defs = SP_DEFS(o); break; @@ -101,232 +105,239 @@ void SPRoot::build(SPDocument *document, Inkscape::XML::Node *repr) { SP_ITEM(this)->transform = Geom::identity(); } -void SPRoot::release() { +void SPRoot::release() +{ this->defs = NULL; SPGroup::release(); } -void SPRoot::set(unsigned int key, const gchar* value) { +void SPRoot::set(unsigned int key, const gchar *value) +{ switch (key) { - case SP_ATTR_VERSION: - if (!sp_version_from_string(value, &this->version.svg)) { - this->version.svg = this->original.svg; - } - break; + case SP_ATTR_VERSION: + if (!sp_version_from_string(value, &this->version.svg)) { + this->version.svg = this->original.svg; + } + break; - case SP_ATTR_INKSCAPE_VERSION: - if (!sp_version_from_string(value, &this->version.inkscape)) { - this->version.inkscape = this->original.inkscape; - } - break; + case SP_ATTR_INKSCAPE_VERSION: + if (!sp_version_from_string(value, &this->version.inkscape)) { + this->version.inkscape = this->original.inkscape; + } + break; - case SP_ATTR_X: - if (!this->x.readAbsolute(value)) { - /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ - this->x.unset(); - } + case SP_ATTR_X: + if (!this->x.readAbsolute(value)) { + /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ + this->x.unset(); + } - /* fixme: I am almost sure these do not require viewport flag (Lauris) */ - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); - break; + /* fixme: I am almost sure these do not require viewport flag (Lauris) */ + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); + break; - case SP_ATTR_Y: - if (!this->y.readAbsolute(value)) { - /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ - this->y.unset(); - } + case SP_ATTR_Y: + if (!this->y.readAbsolute(value)) { + /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ + this->y.unset(); + } - /* fixme: I am almost sure these do not require viewport flag (Lauris) */ - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); - break; + /* fixme: I am almost sure these do not require viewport flag (Lauris) */ + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); + break; - case SP_ATTR_WIDTH: - if (!this->width.readAbsolute(value) || !(this->width.computed > 0.0)) { - /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ - this->width.unset(SVGLength::PERCENT, 1.0, 1.0); - } + case SP_ATTR_WIDTH: + if (!this->width.readAbsolute(value) || !(this->width.computed > 0.0)) { + /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ + this->width.unset(SVGLength::PERCENT, 1.0, 1.0); + } - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); - break; + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); + break; - case SP_ATTR_HEIGHT: - if (!this->height.readAbsolute(value) || !(this->height.computed > 0.0)) { - /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ - this->height.unset(SVGLength::PERCENT, 1.0, 1.0); - } + case SP_ATTR_HEIGHT: + if (!this->height.readAbsolute(value) || !(this->height.computed > 0.0)) { + /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ + this->height.unset(SVGLength::PERCENT, 1.0, 1.0); + } - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); - break; + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); + break; - case SP_ATTR_VIEWBOX: - if (value) { - double x, y, width, height; - char *eptr; + 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); + /* 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++; - } + while (*eptr && ((*eptr == ',') || (*eptr == ' '))) { + eptr++; + } - y = g_ascii_strtod(eptr, &eptr); + y = g_ascii_strtod(eptr, &eptr); - while (*eptr && ((*eptr == ',') || (*eptr == ' '))) { - eptr++; - } + while (*eptr && ((*eptr == ',') || (*eptr == ' '))) { + eptr++; + } - width = g_ascii_strtod(eptr, &eptr); + width = g_ascii_strtod(eptr, &eptr); - while (*eptr && ((*eptr == ',') || (*eptr == ' '))) { - eptr++; - } + while (*eptr && ((*eptr == ',') || (*eptr == ' '))) { + eptr++; + } - height = g_ascii_strtod(eptr, &eptr); + height = g_ascii_strtod(eptr, &eptr); - while (*eptr && ((*eptr == ',') || (*eptr == ' '))) { - eptr++; - } + while (*eptr && ((*eptr == ',') || (*eptr == ' '))) { + eptr++; + } - if ((width > 0) && (height > 0)) { - /* Set viewbox */ - this->viewBox = Geom::Rect::from_xywh(x, y, width, height); - this->viewBox_set = TRUE; - } else { - this->viewBox_set = FALSE; - } + if ((width > 0) && (height > 0)) { + /* Set viewbox */ + this->viewBox = Geom::Rect::from_xywh(x, y, width, height); + this->viewBox_set = TRUE; } else { this->viewBox_set = FALSE; } + } else { + this->viewBox_set = FALSE; + } - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); - break; + this->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 */ - this->aspect_set = FALSE; - this->aspect_align = SP_ASPECT_XMID_YMID; - this->aspect_clip = SP_ASPECT_MEET; + case SP_ATTR_PRESERVEASPECTRATIO: + /* Do setup before, so we can use break to escape */ + this->aspect_set = FALSE; + this->aspect_align = SP_ASPECT_XMID_YMID; + this->aspect_clip = SP_ASPECT_MEET; - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); + this->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; + if (value) { + int len; + gchar c[256]; + gchar const *p, *e; + unsigned int align, clip; + p = value; - while (*p && *p == 32) { - p += 1; - } + while (*p && *p == 32) { + p += 1; + } - if (!*p) { - break; - } + if (!*p) { + break; + } - e = p; + e = p; - while (*e && *e != 32) { - e += 1; - } + while (*e && *e != 32) { + e += 1; + } - len = e - p; + len = e - p; - if (len > 8) { - break; - } + 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; - } + 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; + clip = SP_ASPECT_MEET; - while (*e && *e == 32) { - e += 1; - } + 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; - } + if (*e) { + if (!strcmp(e, "meet")) { + clip = SP_ASPECT_MEET; + } else if (!strcmp(e, "slice")) { + clip = SP_ASPECT_SLICE; + } else { + break; } - - this->aspect_set = TRUE; - this->aspect_align = align; - this->aspect_clip = clip; } - break; - case SP_ATTR_ONLOAD: - this->onload = (char *) value; - break; + this->aspect_set = TRUE; + this->aspect_align = align; + this->aspect_clip = clip; + } + break; - default: - /* Pass the set event to the parent */ - SPGroup::set(key, value); - break; + case SP_ATTR_ONLOAD: + this->onload = (char *) value; + break; + + default: + /* Pass the set event to the parent */ + SPGroup::set(key, value); + break; } } -void SPRoot::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { +void SPRoot::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) +{ SPGroup::child_added(child, ref); SPObject *co = this->document->getObjectByRepr(child); - g_assert (co != NULL || !strcmp("comment", child->name())); // comment repr node has no object + // NOTE: some XML nodes do not have corresponding SP objects, + // for instance inkscape:clipboard used in the clipboard code. + // See LP bug #1227827 + //g_assert (co != NULL || !strcmp("comment", child->name())); // comment repr node has no object if (co && SP_IS_DEFS(co)) { // We search for first node - it is not beautiful, but works - for (SPObject *c = this->firstChild() ; c ; c = c->getNext() ) { + for (SPObject *c = this->firstChild() ; c ; c = c->getNext()) { if (SP_IS_DEFS(c)) { - this->defs = SP_DEFS(c); + this->defs = SP_DEFS(c); break; } } } } -void SPRoot::remove_child(Inkscape::XML::Node* child) { - if ( this->defs && (this->defs->getRepr() == child) ) { +void SPRoot::remove_child(Inkscape::XML::Node *child) +{ + if (this->defs && (this->defs->getRepr() == child)) { SPObject *iter = 0; // We search for first remaining node - it is not beautiful, but works - for ( iter = this->firstChild() ; iter ; iter = iter->getNext() ) { - if ( SP_IS_DEFS(iter) && (SPDefs *)iter != this->defs ) { + for (iter = this->firstChild() ; iter ; iter = iter->getNext()) { + if (SP_IS_DEFS(iter) && (SPDefs *)iter != this->defs) { this->defs = (SPDefs *)iter; break; } @@ -341,14 +352,15 @@ void SPRoot::remove_child(Inkscape::XML::Node* child) { SPGroup::remove_child(child); } -void SPRoot::update(SPCtx *ctx, guint flags) { +void SPRoot::update(SPCtx *ctx, guint flags) +{ 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 (this->x.unit == SVGLength::PERCENT) { - this->x.computed = this->x.value * ictx->viewport.width(); + this->x.computed = this->x.value * ictx->viewport.width(); } if (this->y.unit == SVGLength::PERCENT) { @@ -377,7 +389,7 @@ void SPRoot::update(SPCtx *ctx, guint flags) { * fixme: height seems natural, as this makes the inner svg element * fixme: self-contained. The spec is vague here. */ - this->c2p = Geom::Affine(Geom::Translate(this->x.computed, this->y.computed)); + this->c2p = Geom::Affine(Geom::Translate(this->x.computed, this->y.computed)); } if (this->viewBox_set) { @@ -401,66 +413,66 @@ void SPRoot::update(SPCtx *ctx, guint flags) { /* todo: Use an array lookup to find the 0.0/0.5/1.0 coefficients, as is done for dialogs/align.cpp. */ switch (this->aspect_align) { - case SP_ASPECT_XMIN_YMIN: - x = 0.0; - y = 0.0; - break; + case SP_ASPECT_XMIN_YMIN: + x = 0.0; + y = 0.0; + break; - case SP_ASPECT_XMID_YMIN: - x = 0.5 * (this->width.computed - width); - y = 0.0; - break; + case SP_ASPECT_XMID_YMIN: + x = 0.5 * (this->width.computed - width); + y = 0.0; + break; - case SP_ASPECT_XMAX_YMIN: - x = 1.0 * (this->width.computed - width); - y = 0.0; - break; + case SP_ASPECT_XMAX_YMIN: + x = 1.0 * (this->width.computed - width); + y = 0.0; + break; - case SP_ASPECT_XMIN_YMID: - x = 0.0; - y = 0.5 * (this->height.computed - height); - break; + case SP_ASPECT_XMIN_YMID: + x = 0.0; + y = 0.5 * (this->height.computed - height); + break; - case SP_ASPECT_XMID_YMID: - x = 0.5 * (this->width.computed - width); - y = 0.5 * (this->height.computed - height); - break; + case SP_ASPECT_XMID_YMID: + x = 0.5 * (this->width.computed - width); + y = 0.5 * (this->height.computed - height); + break; - case SP_ASPECT_XMAX_YMID: - x = 1.0 * (this->width.computed - width); - y = 0.5 * (this->height.computed - height); - break; + case SP_ASPECT_XMAX_YMID: + x = 1.0 * (this->width.computed - width); + y = 0.5 * (this->height.computed - height); + break; - case SP_ASPECT_XMIN_YMAX: - x = 0.0; - y = 1.0 * (this->height.computed - height); - break; + case SP_ASPECT_XMIN_YMAX: + x = 0.0; + y = 1.0 * (this->height.computed - height); + break; - case SP_ASPECT_XMID_YMAX: - x = 0.5 * (this->width.computed - width); - y = 1.0 * (this->height.computed - height); - break; + case SP_ASPECT_XMID_YMAX: + x = 0.5 * (this->width.computed - width); + y = 1.0 * (this->height.computed - height); + break; - case SP_ASPECT_XMAX_YMAX: - x = 1.0 * (this->width.computed - width); - y = 1.0 * (this->height.computed - height); - break; + case SP_ASPECT_XMAX_YMAX: + x = 1.0 * (this->width.computed - width); + y = 1.0 * (this->height.computed - height); + break; - default: - x = 0.0; - y = 0.0; - break; + default: + x = 0.0; + y = 0.0; + break; } } /* Compose additional transformation from scale and position */ - Geom::Scale const viewBox_length( this->viewBox.dimensions() ); + Geom::Scale const viewBox_length(this->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. */ - this->c2p = Geom::Translate(-this->viewBox.min()) * ( new_length * viewBox_length.inverse() ) * Geom::Translate(x, y) * this->c2p; + this->c2p = Geom::Translate(-this->viewBox.min()) * (new_length * viewBox_length.inverse()) * Geom::Translate(x, y) * this->c2p; } rctx.i2doc = this->c2p * rctx.i2doc; @@ -470,7 +482,7 @@ void SPRoot::update(SPCtx *ctx, guint flags) { rctx.viewport = this->viewBox; } else { /* fixme: I wonder whether this logic is correct (Lauris) */ - Geom::Point minp(0,0); + Geom::Point minp(0, 0); if (this->parent) { minp = Geom::Point(this->x.computed, this->y.computed); } @@ -490,17 +502,19 @@ void SPRoot::update(SPCtx *ctx, guint flags) { } } -void SPRoot::modified(unsigned int flags) { +void SPRoot::modified(unsigned int flags) +{ SPGroup::modified(flags); /* fixme: (Lauris) */ if (!this->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - this->document->emitResizedSignal(this->width.computed, this->height.computed); + this->document->emitResizedSignal(this->width.computed, this->height.computed); } } -Inkscape::XML::Node* SPRoot::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { +Inkscape::XML::Node *SPRoot::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:svg"); } @@ -509,8 +523,8 @@ Inkscape::XML::Node* SPRoot::write(Inkscape::XML::Document *xml_doc, Inkscape::X repr->setAttribute("inkscape:version", Inkscape::version_string); } - if ( !repr->attribute("version") ) { - gchar* myversion = sp_version_to_string(this->version.svg); + if (!repr->attribute("version")) { + gchar *myversion = sp_version_to_string(this->version.svg); repr->setAttribute("version", myversion); g_free(myversion); } @@ -542,20 +556,22 @@ Inkscape::XML::Node* SPRoot::write(Inkscape::XML::Document *xml_doc, Inkscape::X return repr; } -Inkscape::DrawingItem* SPRoot::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { +Inkscape::DrawingItem *SPRoot::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) +{ Inkscape::DrawingItem *ai = 0; ai = SPGroup::show(drawing, key, flags); if (ai) { - Inkscape::DrawingGroup *g = dynamic_cast(ai); - g->setChildTransform(this->c2p); + Inkscape::DrawingGroup *g = dynamic_cast(ai); + g->setChildTransform(this->c2p); } return ai; } -void SPRoot::print(SPPrintContext* ctx) { +void SPRoot::print(SPPrintContext *ctx) +{ sp_print_bind(ctx, this->c2p, 1.0); SPGroup::print(ctx); -- cgit v1.2.3 From 0e4d9c434c10d21a3134a674c742acf251a684d8 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Tue, 22 Oct 2013 00:06:59 +0200 Subject: remove confusing bitfield declaration. bitfield not even needed here. (bzr r12708) --- src/sp-root.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index c87c8397d..5466649a2 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -62,7 +62,7 @@ SPRoot::SPRoot() : SPGroup() this->width.unset(SVGLength::PERCENT, 1.0, 1.0); this->height.unset(SVGLength::PERCENT, 1.0, 1.0); - this->viewBox_set = FALSE; + this->viewBox_set = false; this->c2p.setIdentity(); -- cgit v1.2.3 From 7dd239eed97761b22ef635b6896a8f65c4939462 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 6 Feb 2014 15:29:15 +0100 Subject: Added new base class to handle viewBox and preserveAspectRatio. Updated sp-root, sp-symbol, sp-image, sp-pattern, marker to use new class. Fixed some viewport issues when % used. (bzr r13002) --- src/sp-root.cpp | 327 +++++++++++--------------------------------------------- 1 file changed, 64 insertions(+), 263 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 5466649a2..bc870b116 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -42,12 +42,9 @@ SPObject *createRoot() bool rootRegistered = SPFactory::instance().registerObject("svg:svg", createRoot); } -SPRoot::SPRoot() : SPGroup() +SPRoot::SPRoot() : SPGroup(), SPViewBox() { - this->aspect_set = 0; - this->aspect_align = 0; this->onload = NULL; - this->aspect_clip = 0; static Inkscape::Version const zero_version(0, 0); @@ -57,15 +54,11 @@ SPRoot::SPRoot() : SPGroup() this->version.inkscape = zero_version; this->original.inkscape = zero_version; - this->x.unset(); - this->y.unset(); + this->x.unset(SVGLength::PERCENT, 0.0, 0.0); // Ignored for root SVG element + this->y.unset(SVGLength::PERCENT, 0.0, 0.0); this->width.unset(SVGLength::PERCENT, 1.0, 1.0); this->height.unset(SVGLength::PERCENT, 1.0, 1.0); - this->viewBox_set = false; - - this->c2p.setIdentity(); - this->defs = NULL; } @@ -129,9 +122,9 @@ void SPRoot::set(unsigned int key, const gchar *value) break; case SP_ATTR_X: - if (!this->x.readAbsolute(value)) { - /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ - this->x.unset(); + /* Valid for non-root SVG elements; ex, em not handled correctly. */ + if (!this->x.read(value)) { + this->x.unset(SVGLength::PERCENT, 0.0, 0.0); } /* fixme: I am almost sure these do not require viewport flag (Lauris) */ @@ -139,9 +132,9 @@ void SPRoot::set(unsigned int key, const gchar *value) break; case SP_ATTR_Y: - if (!this->y.readAbsolute(value)) { - /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ - this->y.unset(); + /* Valid for non-root SVG elements; ex, em not handled correctly. */ + if (!this->y.read(value)) { + this->y.unset(SVGLength::PERCENT, 0.0, 0.0); } /* fixme: I am almost sure these do not require viewport flag (Lauris) */ @@ -149,153 +142,27 @@ void SPRoot::set(unsigned int key, const gchar *value) break; case SP_ATTR_WIDTH: - if (!this->width.readAbsolute(value) || !(this->width.computed > 0.0)) { - /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ + if (!this->width.read(value) || !(this->width.computed > 0.0)) { this->width.unset(SVGLength::PERCENT, 1.0, 1.0); } - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); break; case SP_ATTR_HEIGHT: - if (!this->height.readAbsolute(value) || !(this->height.computed > 0.0)) { - /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ + if (!this->height.read(value) || !(this->height.computed > 0.0)) { this->height.unset(SVGLength::PERCENT, 1.0, 1.0); } - this->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 */ - this->viewBox = Geom::Rect::from_xywh(x, y, width, height); - this->viewBox_set = TRUE; - } else { - this->viewBox_set = FALSE; - } - } else { - this->viewBox_set = FALSE; - } - + set_viewBox( value ); this->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 */ - this->aspect_set = FALSE; - this->aspect_align = SP_ASPECT_XMID_YMID; - this->aspect_clip = SP_ASPECT_MEET; - + set_preserveAspectRatio( value ); this->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; - } - } - - this->aspect_set = TRUE; - this->aspect_align = align; - this->aspect_clip = clip; - } break; case SP_ATTR_ONLOAD: @@ -356,141 +223,75 @@ void SPRoot::update(SPCtx *ctx, guint flags) { 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 (this->x.unit == SVGLength::PERCENT) { - this->x.computed = this->x.value * ictx->viewport.width(); - } - - if (this->y.unit == SVGLength::PERCENT) { - this->y.computed = this->y.value * ictx->viewport.height(); - } - - if (this->width.unit == SVGLength::PERCENT) { - this->width.computed = this->width.value * ictx->viewport.width(); - } - - if (this->height.unit == SVGLength::PERCENT) { - this->height.computed = this->height.value * ictx->viewport.height(); - } - - /* Create copy of item context */ - SPItemCtx rctx = *ictx; - - /* Calculate child to parent transformation */ - this->c2p.setIdentity(); + if( !this->parent ) { - if (this->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. + * This is the root SVG element: + * + * x, y, width, and height apply to positioning the SVG element inside a parent. + * For the root SVG in Inkscape there is no parent, thus special rules apply: + * If width, height not set, width = 100%, height = 100% (as always). + * If width and height are in percent, they are percent of viewBox width/height. + * If width, height, and viewBox are not set... pick "random" width/height. + * x, y are ignored. + * initial viewport = (0 0 width height) */ - this->c2p = Geom::Affine(Geom::Translate(this->x.computed, this->y.computed)); - } - - if (this->viewBox_set) { - double x, y, width, height; - /* Determine actual viewbox in viewport coordinates */ - if (this->aspect_align == SP_ASPECT_NONE) { - x = 0.0; - y = 0.0; - width = this->width.computed; - height = this->height.computed; - } else { - double scalex, scaley, scale; - /* Things are getting interesting */ - scalex = this->width.computed / this->viewBox.width(); - scaley = this->height.computed / this->viewBox.height(); - scale = (this->aspect_clip == SP_ASPECT_MEET) ? MIN(scalex, scaley) : MAX(scalex, scaley); - width = this->viewBox.width() * scale; - height = this->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 (this->aspect_align) { - case SP_ASPECT_XMIN_YMIN: - x = 0.0; - y = 0.0; - break; - - case SP_ASPECT_XMID_YMIN: - x = 0.5 * (this->width.computed - width); - y = 0.0; - break; - - case SP_ASPECT_XMAX_YMIN: - x = 1.0 * (this->width.computed - width); - y = 0.0; - break; - - case SP_ASPECT_XMIN_YMID: - x = 0.0; - y = 0.5 * (this->height.computed - height); - break; - - case SP_ASPECT_XMID_YMID: - x = 0.5 * (this->width.computed - width); - y = 0.5 * (this->height.computed - height); - break; + if( this->viewBox_set ) { - case SP_ASPECT_XMAX_YMID: - x = 1.0 * (this->width.computed - width); - y = 0.5 * (this->height.computed - height); - break; + if( this->width._set ) { + // Check if this is necessary + if (this->width.unit == SVGLength::PERCENT) { + this->width.computed = this->width.value * this->viewBox.width(); + } + } else { + this->width.set( SVGLength::PX, this->viewBox.width(), this->viewBox.width() ); + } - case SP_ASPECT_XMIN_YMAX: - x = 0.0; - y = 1.0 * (this->height.computed - height); - break; + if( this->height._set ) { + if (this->height.unit == SVGLength::PERCENT) { + this->height.computed = this->height.value * this->viewBox.height(); + } + } else { + this->height.set(SVGLength::PX, this->viewBox.height(), this->viewBox.height() ); + } - case SP_ASPECT_XMID_YMAX: - x = 0.5 * (this->width.computed - width); - y = 1.0 * (this->height.computed - height); - break; + } else { - case SP_ASPECT_XMAX_YMAX: - x = 1.0 * (this->width.computed - width); - y = 1.0 * (this->height.computed - height); - break; + if( !this->width._set ) { + this->width.set( SVGLength::PX, 100, 100 ); // Random default + } - default: - x = 0.0; - y = 0.0; - break; + if( !this->height._set ) { + this->height.set( SVGLength::PX, 100, 100 ); // Random default } } - /* Compose additional transformation from scale and position */ - Geom::Scale const viewBox_length(this->viewBox.dimensions()); - Geom::Scale const new_length(width, height); + // Ignore x, y values for root element + this->x.unset(SVGLength::PERCENT, 0.0, 0.0); + this->y.unset(SVGLength::PERCENT, 0.0, 0.0); + } - /* 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. */ - this->c2p = Geom::Translate(-this->viewBox.min()) * (new_length * viewBox_length.inverse()) * Geom::Translate(x, y) * this->c2p; + // Calculate x, y, width, height from parent/initial viewport + if (this->x.unit == SVGLength::PERCENT) { + this->x.computed = this->x.value * ictx->viewport.width(); } - rctx.i2doc = this->c2p * rctx.i2doc; + if (this->y.unit == SVGLength::PERCENT) { + this->y.computed = this->y.value * ictx->viewport.height(); + } - /* Initialize child viewport */ - if (this->viewBox_set) { - rctx.viewport = this->viewBox; - } else { - /* fixme: I wonder whether this logic is correct (Lauris) */ - Geom::Point minp(0, 0); - if (this->parent) { - minp = Geom::Point(this->x.computed, this->y.computed); - } + if (this->width.unit == SVGLength::PERCENT) { + this->width.computed = this->width.value * ictx->viewport.width(); + } - rctx.viewport = Geom::Rect::from_xywh(minp[Geom::X], minp[Geom::Y], this->width.computed, this->height.computed); + if (this->height.unit == SVGLength::PERCENT) { + this->height.computed = this->height.value * ictx->viewport.height(); } - rctx.i2vp = Geom::identity(); + // Calculate new viewport + ictx->viewport = Geom::Rect::from_xywh( this->x.computed, this->y.computed, + this->width.computed, this->height.computed ); + SPItemCtx rctx = get_rctx( ictx ); /* And invoke parent method */ SPGroup::update((SPCtx *) &rctx, flags); -- cgit v1.2.3 From 70d5e94706c772944411e12e13082b531ed2185e Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 27 Feb 2014 14:25:45 +0100 Subject: Don't overwrite SPItemCtx in SPRoot::update. (Maybe should be made const everywhere?) (bzr r13065) --- src/sp-root.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index bc870b116..4f1444e31 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -221,7 +221,7 @@ void SPRoot::remove_child(Inkscape::XML::Node *child) void SPRoot::update(SPCtx *ctx, guint flags) { - SPItemCtx *ictx = (SPItemCtx *) ctx; + SPItemCtx const *ictx = (SPItemCtx const *) ctx; if( !this->parent ) { @@ -288,10 +288,17 @@ void SPRoot::update(SPCtx *ctx, guint flags) this->height.computed = this->height.value * ictx->viewport.height(); } + // std::cout << "SPRoot::update: final:" + // << " x: " << x.computed + // << " y: " << y.computed + // << " width: " << width.computed + // << " height: " << height.computed << std::endl; + // Calculate new viewport - ictx->viewport = Geom::Rect::from_xywh( this->x.computed, this->y.computed, - this->width.computed, this->height.computed ); - SPItemCtx rctx = get_rctx( ictx ); + SPItemCtx rctx = *ictx; + rctx.viewport = Geom::Rect::from_xywh( this->x.computed, this->y.computed, + this->width.computed, this->height.computed ); + rctx = get_rctx( &rctx ); /* And invoke parent method */ SPGroup::update((SPCtx *) &rctx, flags); -- cgit v1.2.3 From fa0d3b889ad80af4b5a0c3f58226978a42e96b37 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 28 Feb 2014 15:01:45 +0100 Subject: Properly identify an embedded SVG. (bzr r13075) --- src/sp-root.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 4f1444e31..12570e03e 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -387,6 +387,9 @@ void SPRoot::print(SPPrintContext *ctx) sp_print_release(ctx); } +const char *SPRoot::displayName() const { + return "SVG"; // Do not translate +} /* Local Variables: -- cgit v1.2.3 From e7a3f5b74d1f5a95390ee95b06371d184c1812f7 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Thu, 13 Mar 2014 05:45:38 +0100 Subject: Provide a toggle in the document properties to optionally turn off antialiasing for display and export. Fixes a nearly 10 year old bug #170356 Fixed bugs: - https://launchpad.net/bugs/170356 (bzr r13144) --- src/sp-root.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 12570e03e..12ac1bad4 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -25,6 +25,7 @@ #include "document.h" #include "inkscape-version.h" #include "sp-defs.h" +#include "sp-namedview.h" #include "sp-root.h" #include "display/drawing-group.h" #include "svg/stringstream.h" @@ -307,6 +308,7 @@ void SPRoot::update(SPCtx *ctx, guint flags) for (SPItemView *v = this->display; v != NULL; v = v->next) { Inkscape::DrawingGroup *g = dynamic_cast(v->arenaitem); g->setChildTransform(this->c2p); + g->setAntialiasing(sp_document_namedview(this->document, NULL)->antialiasing); } } @@ -373,6 +375,7 @@ Inkscape::DrawingItem *SPRoot::show(Inkscape::Drawing &drawing, unsigned int key if (ai) { Inkscape::DrawingGroup *g = dynamic_cast(ai); g->setChildTransform(this->c2p); + g->setAntialiasing(sp_document_namedview(this->document, NULL)->antialiasing); } return ai; @@ -391,6 +394,13 @@ const char *SPRoot::displayName() const { return "SVG"; // Do not translate } +void SPRoot::setAntialiasing(bool s) { + for (SPItemView *v = this->display; v != NULL; v = v->next) { + Inkscape::DrawingGroup *g = dynamic_cast(v->arenaitem); + g->setAntialiasing(s); + } +} + /* Local Variables: mode:c++ -- cgit v1.2.3 From 32ef25632164e5af8766a5364400b579edde4ebf Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Thu, 13 Mar 2014 23:37:07 +0100 Subject: Reimplement global aliasing toggle as a 'shape-rendering' property on the root element. (bzr r13146) --- src/sp-root.cpp | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 12ac1bad4..12570e03e 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -25,7 +25,6 @@ #include "document.h" #include "inkscape-version.h" #include "sp-defs.h" -#include "sp-namedview.h" #include "sp-root.h" #include "display/drawing-group.h" #include "svg/stringstream.h" @@ -308,7 +307,6 @@ void SPRoot::update(SPCtx *ctx, guint flags) for (SPItemView *v = this->display; v != NULL; v = v->next) { Inkscape::DrawingGroup *g = dynamic_cast(v->arenaitem); g->setChildTransform(this->c2p); - g->setAntialiasing(sp_document_namedview(this->document, NULL)->antialiasing); } } @@ -375,7 +373,6 @@ Inkscape::DrawingItem *SPRoot::show(Inkscape::Drawing &drawing, unsigned int key if (ai) { Inkscape::DrawingGroup *g = dynamic_cast(ai); g->setChildTransform(this->c2p); - g->setAntialiasing(sp_document_namedview(this->document, NULL)->antialiasing); } return ai; @@ -394,13 +391,6 @@ const char *SPRoot::displayName() const { return "SVG"; // Do not translate } -void SPRoot::setAntialiasing(bool s) { - for (SPItemView *v = this->display; v != NULL; v = v->next) { - Inkscape::DrawingGroup *g = dynamic_cast(v->arenaitem); - g->setAntialiasing(s); - } -} - /* Local Variables: mode:c++ -- cgit v1.2.3