From 1cca85d01800742484b2901ea0f2d6bcf6cae1a5 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 18:36:31 +0200 Subject: Added "virtual pad" to SPOffset. (bzr r11608.1.7) --- src/sp-offset.cpp | 140 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 96 insertions(+), 44 deletions(-) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index 817db92e8..f2f707882 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -162,12 +162,25 @@ sp_offset_class_init(SPOffsetClass *klass) shape_class->set_shape = sp_offset_set_shape; } +COffset::COffset(SPOffset* offset) : CShape(offset) { + this->spoffset = offset; +} + +COffset::~COffset() { +} + /** * Callback for SPOffset object initialization. */ static void sp_offset_init(SPOffset *offset) { + offset->coffset = new COffset(offset); + offset->cshape = offset->coffset; + offset->clpeitem = offset->coffset; + offset->citem = offset->coffset; + offset->cobject = offset->coffset; + offset->rad = 1.0; offset->original = NULL; offset->originalPath = NULL; @@ -207,14 +220,10 @@ sp_offset_finalize(GObject *obj) offset->_transformed_connection.~connection(); } -/** - * Virtual build: set offset attributes from corresponding repr. - */ -static void -sp_offset_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ - if (((SPObjectClass *) parent_class)->build) - ((SPObjectClass *) parent_class)->build (object, document, repr); +void COffset::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPOffset* object = this->spoffset; + + CShape::onBuild(document, repr); //XML Tree being used directly here while it shouldn't be. if (object->getRepr()->attribute("inkscape:radius")) { @@ -255,13 +264,19 @@ sp_offset_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *rep } } +// CPPIFY: remove /** - * Virtual write: write offset attributes to corresponding repr. + * Virtual build: set offset attributes from corresponding repr. */ -static Inkscape::XML::Node * -sp_offset_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void +sp_offset_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - SPOffset *offset = SP_OFFSET (object); + ((SPOffset*)object)->coffset->onBuild(document, repr); +} + +Inkscape::XML::Node* COffset::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPOffset* object = this->spoffset; + SPOffset *offset = object; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:path"); @@ -290,19 +305,23 @@ sp_offset_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XM repr->setAttribute("d", d); g_free (d); - if (((SPObjectClass *) (parent_class))->write) - ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, - flags | SP_SHAPE_WRITE_PATH); + CShape::onWrite(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); return repr; } +// CPPIFY: remove /** - * Virtual release callback. + * Virtual write: write offset attributes to corresponding repr. */ -static void -sp_offset_release(SPObject *object) +static Inkscape::XML::Node * +sp_offset_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + return ((SPOffset*)object)->coffset->onWrite(xml_doc, repr, flags); +} + +void COffset::onRelease() { + SPOffset* object = this->spoffset; SPOffset *offset = (SPOffset *) object; if (offset->original) free (offset->original); @@ -317,20 +336,22 @@ sp_offset_release(SPObject *object) offset->sourceHref = NULL; offset->sourceRef->detach(); - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release (object); - } - + CShape::onRelease(); } +// CPPIFY: remove /** - * Set callback: the function that is called whenever a change is made to - * the description of the object. + * Virtual release callback. */ static void -sp_offset_set(SPObject *object, unsigned key, gchar const *value) +sp_offset_release(SPObject *object) { - SPOffset *offset = SP_OFFSET (object); + ((SPOffset*)object)->coffset->onRelease(); +} + +void COffset::onSet(unsigned int key, const gchar* value) { + SPOffset* object = this->spoffset; + SPOffset *offset = object; if ( offset->sourceDirty ) refresh_offset_source(offset); @@ -389,19 +410,26 @@ sp_offset_set(SPObject *object, unsigned key, gchar const *value) } break; default: - if (((SPObjectClass *) parent_class)->set) - ((SPObjectClass *) parent_class)->set (object, key, value); + CShape::onSet(key, value); break; } } +// CPPIFY: remove /** - * Update callback: the object has changed, recompute its shape. + * Set callback: the function that is called whenever a change is made to + * the description of the object. */ static void -sp_offset_update(SPObject *object, SPCtx *ctx, guint flags) +sp_offset_set(SPObject *object, unsigned key, gchar const *value) { - SPOffset* offset = SP_OFFSET(object); + ((SPOffset*)object)->coffset->onSet(key, value); +} + +void COffset::onUpdate(SPCtx *ctx, guint flags) { + SPOffset* object = this->spoffset; + SPOffset* offset = object; + offset->isUpdating=true; // prevent sp_offset_set from requesting updates if ( offset->sourceDirty ) refresh_offset_source(offset); if (flags & @@ -411,17 +439,22 @@ sp_offset_update(SPObject *object, SPCtx *ctx, guint flags) } offset->isUpdating=false; - if (((SPObjectClass *) parent_class)->update) - ((SPObjectClass *) parent_class)->update (object, ctx, flags); + CShape::onUpdate(ctx, flags); } +// CPPIFY: remove /** - * Returns a textual description of object. + * Update callback: the object has changed, recompute its shape. */ -static gchar * -sp_offset_description(SPItem *item) +static void +sp_offset_update(SPObject *object, SPCtx *ctx, guint flags) { - SPOffset *offset = SP_OFFSET (item); + ((SPOffset*)object)->coffset->onUpdate(ctx, flags); +} + +gchar* COffset::onDescription() { + SPOffset* item = this->spoffset; + SPOffset *offset = item; if ( offset->sourceHref ) { // TRANSLATORS COMMENT: %s is either "outset" or "inset" depending on sign @@ -434,13 +467,19 @@ sp_offset_description(SPItem *item) } } +// CPPIFY: remove /** - * Compute and set shape's offset. + * Returns a textual description of object. */ -static void -sp_offset_set_shape(SPShape *shape) +static gchar * +sp_offset_description(SPItem *item) { - SPOffset *offset = SP_OFFSET (shape); + return ((SPOffset*)item)->coffset->onDescription(); +} + +void COffset::onSetShape() { + SPOffset* shape = this->spoffset; + SPOffset *offset = shape; if ( offset->originalPath == NULL ) { // oops : no path?! (the offset object should do harakiri) @@ -720,14 +759,27 @@ sp_offset_set_shape(SPShape *shape) } } +// CPPIFY: remove +/** + * Compute and set shape's offset. + */ +static void +sp_offset_set_shape(SPShape *shape) +{ + ((SPOffset*)shape)->coffset->onSetShape(); +} + +void COffset::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + CShape::onSnappoints(p, snapprefs); +} + +// CPPIFY: remove /** * Virtual snappoints function. */ static void sp_offset_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) { - if (((SPItemClass *) parent_class)->snappoints) { - ((SPItemClass *) parent_class)->snappoints (item, p, snapprefs); - } + ((SPOffset*)item)->coffset->onSnappoints(p, snapprefs); } -- cgit v1.2.3 From 260c7156ca920232cca2e829782373a805d59cae Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 29 Sep 2012 17:43:15 +0200 Subject: Removed old calls to set_shape and update_patheffect. (bzr r11608.1.45) --- src/sp-offset.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index f2f707882..08a57234b 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -159,7 +159,7 @@ sp_offset_class_init(SPOffsetClass *klass) item_class->description = sp_offset_description; item_class->snappoints = sp_offset_snappoints; - shape_class->set_shape = sp_offset_set_shape; + //shape_class->set_shape = sp_offset_set_shape; } COffset::COffset(SPOffset* offset) : CShape(offset) { -- 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-offset.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index 08a57234b..652f4fdb7 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -156,8 +156,8 @@ sp_offset_class_init(SPOffsetClass *klass) sp_object_class->update = sp_offset_update; sp_object_class->release = sp_offset_release; - item_class->description = sp_offset_description; - item_class->snappoints = sp_offset_snappoints; +// item_class->description = sp_offset_description; +// item_class->snappoints = sp_offset_snappoints; //shape_class->set_shape = sp_offset_set_shape; } -- 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-offset.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index 652f4fdb7..d1efb97f3 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -150,7 +150,7 @@ sp_offset_class_init(SPOffsetClass *klass) gobject_class->finalize = sp_offset_finalize; - sp_object_class->build = sp_offset_build; + //sp_object_class->build = sp_offset_build; sp_object_class->write = sp_offset_write; sp_object_class->set = sp_offset_set; sp_object_class->update = sp_offset_update; -- 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-offset.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index d1efb97f3..ae7538fe1 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -151,10 +151,10 @@ sp_offset_class_init(SPOffsetClass *klass) gobject_class->finalize = sp_offset_finalize; //sp_object_class->build = sp_offset_build; - sp_object_class->write = sp_offset_write; - sp_object_class->set = sp_offset_set; - sp_object_class->update = sp_offset_update; - sp_object_class->release = sp_offset_release; +// sp_object_class->write = sp_offset_write; +// sp_object_class->set = sp_offset_set; +// sp_object_class->update = sp_offset_update; +// sp_object_class->release = sp_offset_release; // item_class->description = sp_offset_description; // item_class->snappoints = sp_offset_snappoints; -- 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-offset.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index 5a15f9dbe..d6ad5e426 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -159,10 +159,10 @@ sp_offset_finalize(GObject *obj) offset->_transformed_connection.~connection(); } -void COffset::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { +void COffset::build(SPDocument *document, Inkscape::XML::Node *repr) { SPOffset* object = this->spoffset; - CShape::onBuild(document, repr); + CShape::build(document, repr); //XML Tree being used directly here while it shouldn't be. if (object->getRepr()->attribute("inkscape:radius")) { @@ -203,7 +203,7 @@ void COffset::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { } } -Inkscape::XML::Node* COffset::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { +Inkscape::XML::Node* COffset::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPOffset* object = this->spoffset; SPOffset *offset = object; @@ -226,7 +226,7 @@ Inkscape::XML::Node* COffset::onWrite(Inkscape::XML::Document *xml_doc, Inkscape // Make sure the object has curve SPCurve *curve = SP_SHAPE (offset)->getCurve(); if (curve == NULL) { - this->onSetShape(); + this->set_shape(); } // write that curve to "d" @@ -234,12 +234,12 @@ Inkscape::XML::Node* COffset::onWrite(Inkscape::XML::Document *xml_doc, Inkscape repr->setAttribute("d", d); g_free (d); - CShape::onWrite(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); + CShape::write(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); return repr; } -void COffset::onRelease() { +void COffset::release() { SPOffset* object = this->spoffset; SPOffset *offset = (SPOffset *) object; @@ -255,10 +255,10 @@ void COffset::onRelease() { offset->sourceHref = NULL; offset->sourceRef->detach(); - CShape::onRelease(); + CShape::release(); } -void COffset::onSet(unsigned int key, const gchar* value) { +void COffset::set(unsigned int key, const gchar* value) { SPOffset* object = this->spoffset; SPOffset *offset = object; @@ -319,12 +319,12 @@ void COffset::onSet(unsigned int key, const gchar* value) { } break; default: - CShape::onSet(key, value); + CShape::set(key, value); break; } } -void COffset::onUpdate(SPCtx *ctx, guint flags) { +void COffset::update(SPCtx *ctx, guint flags) { SPOffset* object = this->spoffset; SPOffset* offset = object; @@ -337,10 +337,10 @@ void COffset::onUpdate(SPCtx *ctx, guint flags) { } offset->isUpdating=false; - CShape::onUpdate(ctx, flags); + CShape::update(ctx, flags); } -gchar* COffset::onDescription() { +gchar* COffset::description() { SPOffset* item = this->spoffset; SPOffset *offset = item; @@ -355,7 +355,7 @@ gchar* COffset::onDescription() { } } -void COffset::onSetShape() { +void COffset::set_shape() { SPOffset* shape = this->spoffset; SPOffset *offset = shape; @@ -637,8 +637,8 @@ void COffset::onSetShape() { } } -void COffset::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { - CShape::onSnappoints(p, snapprefs); +void COffset::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + CShape::snappoints(p, snapprefs); } @@ -867,7 +867,7 @@ sp_offset_top_point (SPOffset const * offset, Geom::Point *px) SPCurve *curve = SP_SHAPE (offset)->getCurve(); if (curve == NULL) { - offset->coffset->onSetShape(); + offset->coffset->set_shape(); curve = SP_SHAPE (offset)->getCurve(); if (curve == NULL) return; -- 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-offset.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index d6ad5e426..511a0c4b1 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -113,6 +113,7 @@ static void sp_offset_init(SPOffset *offset) { offset->coffset = new COffset(offset); + offset->typeHierarchy.insert(typeid(SPOffset)); delete offset->cshape; offset->cshape = offset->coffset; -- 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-offset.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index 511a0c4b1..3a8bf5a10 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -87,7 +87,7 @@ static void sp_offset_source_modified (SPObject *iSource, guint flags, SPItem *i // reappearing in offset when the radius becomes too large static bool use_slow_but_correct_offset_method=false; -G_DEFINE_TYPE(SPOffset, sp_offset, SP_TYPE_SHAPE); +G_DEFINE_TYPE(SPOffset, sp_offset, G_TYPE_OBJECT); /** * SPOffset vtable initialization. @@ -106,12 +106,9 @@ COffset::COffset(SPOffset* offset) : CShape(offset) { COffset::~COffset() { } -/** - * Callback for SPOffset object initialization. - */ -static void -sp_offset_init(SPOffset *offset) -{ +SPOffset::SPOffset() : SPShape() { + SPOffset* offset = this; + offset->coffset = new COffset(offset); offset->typeHierarchy.insert(typeid(SPOffset)); @@ -140,6 +137,15 @@ sp_offset_init(SPOffset *offset) offset->_changed_connection = offset->sourceRef->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_offset_href_changed), offset)); } +/** + * Callback for SPOffset object initialization. + */ +static void +sp_offset_init(SPOffset *offset) +{ + new (offset) SPOffset(); +} + /** * Callback for SPOffset finalization. */ -- 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-offset.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index 3a8bf5a10..5a9b3933c 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -43,6 +43,16 @@ class SPDocument; +#include "sp-factory.h" + +namespace { + SPObject* createOffset() { + return new SPOffset(); + } + + bool offsetRegistered = SPFactory::instance().registerObject("inkscape:offset", createOffset); +} + #define noOFFSET_VERBOSE /** \note -- cgit v1.2.3 From 8443720ce6429b9beec839e60b8a808595f4ba72 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 23:01:45 +0200 Subject: Cleaned up a bit. Uses some C++11 features. (bzr r11608.1.72) --- src/sp-offset.cpp | 46 ++++++---------------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index 5a9b3933c..f812ad931 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -78,8 +78,6 @@ namespace { * radius (look in object-edit). */ -static void sp_offset_finalize(GObject *obj); - static void refresh_offset_source(SPOffset* offset); static void sp_offset_start_listening(SPOffset *offset,SPObject* to); @@ -97,18 +95,6 @@ static void sp_offset_source_modified (SPObject *iSource, guint flags, SPItem *i // reappearing in offset when the radius becomes too large static bool use_slow_but_correct_offset_method=false; -G_DEFINE_TYPE(SPOffset, sp_offset, G_TYPE_OBJECT); - -/** - * SPOffset vtable initialization. - */ -static void -sp_offset_class_init(SPOffsetClass *klass) -{ - GObjectClass *gobject_class = (GObjectClass *) klass; - gobject_class->finalize = sp_offset_finalize; -} - COffset::COffset(SPOffset* offset) : CShape(offset) { this->spoffset = offset; } @@ -147,33 +133,13 @@ SPOffset::SPOffset() : SPShape() { offset->_changed_connection = offset->sourceRef->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_offset_href_changed), offset)); } -/** - * Callback for SPOffset object initialization. - */ -static void -sp_offset_init(SPOffset *offset) -{ - new (offset) SPOffset(); -} - -/** - * Callback for SPOffset finalization. - */ -static void -sp_offset_finalize(GObject *obj) -{ - SPOffset *offset = (SPOffset *) obj; +SPOffset::~SPOffset() { + delete this->sourceRef; - delete offset->sourceRef; - - offset->_modified_connection.disconnect(); - offset->_modified_connection.~connection(); - offset->_delete_connection.disconnect(); - offset->_delete_connection.~connection(); - offset->_changed_connection.disconnect(); - offset->_changed_connection.~connection(); - offset->_transformed_connection.disconnect(); - offset->_transformed_connection.~connection(); + this->_modified_connection.disconnect(); + this->_delete_connection.disconnect(); + this->_changed_connection.disconnect(); + this->_transformed_connection.disconnect(); } void COffset::build(SPDocument *document, Inkscape::XML::Node *repr) { -- cgit v1.2.3 From 748ffce08bb6250c87adabb64f45bff02509e9e7 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 00:27:58 +0200 Subject: Combined some classes. (bzr r11608.1.75) --- src/sp-offset.cpp | 531 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 345 insertions(+), 186 deletions(-) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index f812ad931..ede1ab39b 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -95,42 +95,32 @@ static void sp_offset_source_modified (SPObject *iSource, guint flags, SPItem *i // reappearing in offset when the radius becomes too large static bool use_slow_but_correct_offset_method=false; -COffset::COffset(SPOffset* offset) : CShape(offset) { - this->spoffset = offset; -} - -COffset::~COffset() { -} - -SPOffset::SPOffset() : SPShape() { - SPOffset* offset = this; - - offset->coffset = new COffset(offset); - offset->typeHierarchy.insert(typeid(SPOffset)); +SPOffset::SPOffset() : SPShape(), CShape(this) { + delete this->cshape; + this->cshape = this; + this->clpeitem = this; + this->citem = this; + this->cobject = this; + + this->rad = 1.0; + this->original = NULL; + this->originalPath = NULL; + this->knotSet = false; + this->sourceDirty=false; + this->isUpdating=false; + // init various connections + this->sourceHref = NULL; + this->sourceRepr = NULL; + this->sourceObject = NULL; - delete offset->cshape; - offset->cshape = offset->coffset; - offset->clpeitem = offset->coffset; - offset->citem = offset->coffset; - offset->cobject = offset->coffset; + new (&this->_modified_connection) sigc::connection(); + new (&this->_delete_connection) sigc::connection(); + new (&this->_changed_connection) sigc::connection(); + new (&this->_transformed_connection) sigc::connection(); - offset->rad = 1.0; - offset->original = NULL; - offset->originalPath = NULL; - offset->knotSet = false; - offset->sourceDirty=false; - offset->isUpdating=false; - // init various connections - offset->sourceHref = NULL; - offset->sourceRepr = NULL; - offset->sourceObject = NULL; - new (&offset->_modified_connection) sigc::connection(); - new (&offset->_delete_connection) sigc::connection(); - new (&offset->_changed_connection) sigc::connection(); - new (&offset->_transformed_connection) sigc::connection(); // set up the uri reference - offset->sourceRef = new SPUseReference(offset); - offset->_changed_connection = offset->sourceRef->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_offset_href_changed), offset)); + this->sourceRef = new SPUseReference(this); + this->_changed_connection = this->sourceRef->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_offset_href_changed), this)); } SPOffset::~SPOffset() { @@ -142,54 +132,58 @@ SPOffset::~SPOffset() { this->_transformed_connection.disconnect(); } -void COffset::build(SPDocument *document, Inkscape::XML::Node *repr) { - SPOffset* object = this->spoffset; - +void SPOffset::build(SPDocument *document, Inkscape::XML::Node *repr) { CShape::build(document, repr); //XML Tree being used directly here while it shouldn't be. - if (object->getRepr()->attribute("inkscape:radius")) { - object->readAttr( "inkscape:radius" ); + if (this->getRepr()->attribute("inkscape:radius")) { + this->readAttr( "inkscape:radius" ); } else { //XML Tree being used directly here (as object->getRepr) //in all the below lines in the block while it shouldn't be. - gchar const *oldA = object->getRepr()->attribute("sodipodi:radius"); - object->getRepr()->setAttribute("inkscape:radius",oldA); - object->getRepr()->setAttribute("sodipodi:radius",NULL); + gchar const *oldA = this->getRepr()->attribute("sodipodi:radius"); + this->getRepr()->setAttribute("inkscape:radius",oldA); + this->getRepr()->setAttribute("sodipodi:radius",NULL); - object->readAttr( "inkscape:radius" ); + this->readAttr( "inkscape:radius" ); } - if (object->getRepr()->attribute("inkscape:original")) { - object->readAttr( "inkscape:original" ); + + if (this->getRepr()->attribute("inkscape:original")) { + this->readAttr( "inkscape:original" ); } else { - gchar const *oldA = object->getRepr()->attribute("sodipodi:original"); - object->getRepr()->setAttribute("inkscape:original",oldA); - object->getRepr()->setAttribute("sodipodi:original",NULL); + gchar const *oldA = this->getRepr()->attribute("sodipodi:original"); + this->getRepr()->setAttribute("inkscape:original",oldA); + this->getRepr()->setAttribute("sodipodi:original",NULL); - object->readAttr( "inkscape:original" ); + this->readAttr( "inkscape:original" ); } - if (object->getRepr()->attribute("xlink:href")) { - object->readAttr( "xlink:href" ); + + if (this->getRepr()->attribute("xlink:href")) { + this->readAttr( "xlink:href" ); } else { - gchar const *oldA = object->getRepr()->attribute("inkscape:href"); + gchar const *oldA = this->getRepr()->attribute("inkscape:href"); + if (oldA) { size_t lA = strlen(oldA); char *nA=(char*)malloc((1+lA+1)*sizeof(char)); + memcpy(nA+1,oldA,lA*sizeof(char)); + nA[0]='#'; nA[lA+1]=0; - object->getRepr()->setAttribute("xlink:href",nA); + + this->getRepr()->setAttribute("xlink:href",nA); + free(nA); - object->getRepr()->setAttribute("inkscape:href",NULL); + + this->getRepr()->setAttribute("inkscape:href",NULL); } - object->readAttr( "xlink:href" ); + + this->readAttr( "xlink:href" ); } } -Inkscape::XML::Node* COffset::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPOffset* object = this->spoffset; - SPOffset *offset = object; - +Inkscape::XML::Node* SPOffset::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:path"); } @@ -200,20 +194,21 @@ Inkscape::XML::Node* COffset::write(Inkscape::XML::Document *xml_doc, Inkscape:: * inkscape:offset="cx cy exp revo rad arg t0" */ repr->setAttribute("sodipodi:type", "inkscape:offset"); - sp_repr_set_svg_double(repr, "inkscape:radius", offset->rad); - repr->setAttribute("inkscape:original", offset->original); - repr->setAttribute("inkscape:href", offset->sourceHref); + sp_repr_set_svg_double(repr, "inkscape:radius", this->rad); + repr->setAttribute("inkscape:original", this->original); + repr->setAttribute("inkscape:href", this->sourceHref); } - // Make sure the object has curve - SPCurve *curve = SP_SHAPE (offset)->getCurve(); + // Make sure the offset has curve + SPCurve *curve = SP_SHAPE (this)->getCurve(); + if (curve == NULL) { this->set_shape(); } // write that curve to "d" - char *d = sp_svg_write_path (offset->_curve->get_pathvector()); + char *d = sp_svg_write_path (this->_curve->get_pathvector()); repr->setAttribute("d", d); g_free (d); @@ -222,30 +217,34 @@ Inkscape::XML::Node* COffset::write(Inkscape::XML::Document *xml_doc, Inkscape:: return repr; } -void COffset::release() { - SPOffset* object = this->spoffset; - SPOffset *offset = (SPOffset *) object; +void SPOffset::release() { + if (this->original) { + free (this->original); + } - if (offset->original) free (offset->original); - if (offset->originalPath) delete ((Path *) offset->originalPath); - offset->original = NULL; - offset->originalPath = NULL; + if (this->originalPath) { + delete ((Path *) this->originalPath); + } - sp_offset_quit_listening(offset); + this->original = NULL; + this->originalPath = NULL; + + sp_offset_quit_listening(this); + + this->_changed_connection.disconnect(); - offset->_changed_connection.disconnect(); - g_free(offset->sourceHref); - offset->sourceHref = NULL; - offset->sourceRef->detach(); + g_free(this->sourceHref); + + this->sourceHref = NULL; + this->sourceRef->detach(); CShape::release(); } -void COffset::set(unsigned int key, const gchar* value) { - SPOffset* object = this->spoffset; - SPOffset *offset = object; - - if ( offset->sourceDirty ) refresh_offset_source(offset); +void SPOffset::set(unsigned int key, const gchar* value) { + if ( this->sourceDirty ) { + refresh_offset_source(this); + } /* fixme: we should really collect updates */ switch (key) @@ -254,95 +253,112 @@ void COffset::set(unsigned int key, const gchar* value) { case SP_ATTR_SODIPODI_ORIGINAL: if (value == NULL) { } else { - if (offset->original) { - free (offset->original); - delete ((Path *) offset->originalPath); - offset->original = NULL; - offset->originalPath = NULL; + if (this->original) { + free (this->original); + delete ((Path *) this->originalPath); + + this->original = NULL; + this->originalPath = NULL; } - offset->original = strdup (value); + this->original = strdup (value); + + Geom::PathVector pv = sp_svg_read_pathv(this->original); + + this->originalPath = new Path; + reinterpret_cast(this->originalPath)->LoadPathVector(pv); - Geom::PathVector pv = sp_svg_read_pathv(offset->original); - offset->originalPath = new Path; - reinterpret_cast(offset->originalPath)->LoadPathVector(pv); + this->knotSet = false; - offset->knotSet = false; - if ( offset->isUpdating == false ) object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + if ( this->isUpdating == false ) { + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + } } break; + case SP_ATTR_INKSCAPE_RADIUS: case SP_ATTR_SODIPODI_RADIUS: - if (!sp_svg_length_read_computed_absolute (value, &offset->rad)) { - if (fabs (offset->rad) < 0.01) - offset->rad = (offset->rad < 0) ? -0.01 : 0.01; - offset->knotSet = false; // knotset=false because it's not set from the context + if (!sp_svg_length_read_computed_absolute (value, &this->rad)) { + if (fabs (this->rad) < 0.01) { + this->rad = (this->rad < 0) ? -0.01 : 0.01; + } + + this->knotSet = false; // knotset=false because it's not set from the context + } + + if ( this->isUpdating == false ) { + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } - if ( offset->isUpdating == false ) object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_INKSCAPE_HREF: case SP_ATTR_XLINK_HREF: if ( value == NULL ) { - sp_offset_quit_listening(offset); - if ( offset->sourceHref ) g_free(offset->sourceHref); - offset->sourceHref = NULL; - offset->sourceRef->detach(); + sp_offset_quit_listening(this); + if ( this->sourceHref ) { + g_free(this->sourceHref); + } + + this->sourceHref = NULL; + this->sourceRef->detach(); } else { - if ( offset->sourceHref && ( strcmp(value, offset->sourceHref) == 0 ) ) { + if ( this->sourceHref && ( strcmp(value, this->sourceHref) == 0 ) ) { } else { - if ( offset->sourceHref ) g_free(offset->sourceHref); - offset->sourceHref = g_strdup(value); + if ( this->sourceHref ) { + g_free(this->sourceHref); + } + + this->sourceHref = g_strdup(value); + try { - offset->sourceRef->attach(Inkscape::URI(value)); + this->sourceRef->attach(Inkscape::URI(value)); } catch (Inkscape::BadURIException &e) { g_warning("%s", e.what()); - offset->sourceRef->detach(); + this->sourceRef->detach(); } } } break; + default: CShape::set(key, value); break; } } -void COffset::update(SPCtx *ctx, guint flags) { - SPOffset* object = this->spoffset; - SPOffset* offset = object; - - offset->isUpdating=true; // prevent sp_offset_set from requesting updates - if ( offset->sourceDirty ) refresh_offset_source(offset); +void SPOffset::update(SPCtx *ctx, guint flags) { + this->isUpdating=true; // prevent sp_offset_set from requesting updates + + if ( this->sourceDirty ) { + refresh_offset_source(this); + } + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - ((SPShape *) object)->setShape (); + + this->setShape (); } - offset->isUpdating=false; + + this->isUpdating=false; CShape::update(ctx, flags); } -gchar* COffset::description() { - SPOffset* item = this->spoffset; - SPOffset *offset = item; - - if ( offset->sourceHref ) { +gchar* SPOffset::description() { + if ( this->sourceHref ) { // TRANSLATORS COMMENT: %s is either "outset" or "inset" depending on sign return g_strdup_printf(_("Linked offset, %s by %f pt"), - (offset->rad >= 0)? _("outset") : _("inset"), fabs (offset->rad)); + (this->rad >= 0)? _("outset") : _("inset"), fabs (this->rad)); } else { // TRANSLATORS COMMENT: %s is either "outset" or "inset" depending on sign return g_strdup_printf(_("Dynamic offset, %s by %f pt"), - (offset->rad >= 0)? _("outset") : _("inset"), fabs (offset->rad)); + (this->rad >= 0)? _("outset") : _("inset"), fabs (this->rad)); } } -void COffset::set_shape() { - SPOffset* shape = this->spoffset; - SPOffset *offset = shape; - - if ( offset->originalPath == NULL ) { +void SPOffset::set_shape() { + if ( this->originalPath == NULL ) { // oops : no path?! (the offset object should do harakiri) return; } @@ -351,30 +367,35 @@ void COffset::set_shape() { #endif // au boulot - if ( fabs(offset->rad) < 0.01 ) { + if ( fabs(this->rad) < 0.01 ) { // grosso modo: 0 - // just put the source shape as the offseted one, no one will notice + // just put the source this as the offseted one, no one will notice // it's also useless to compute the offset with a 0 radius //XML Tree being used directly here while it shouldn't be. - const char *res_d = shape->getRepr()->attribute("inkscape:original"); + const char *res_d = this->getRepr()->attribute("inkscape:original"); + if ( res_d ) { Geom::PathVector pv = sp_svg_read_pathv(res_d); SPCurve *c = new SPCurve(pv); g_assert(c != NULL); - ((SPShape *) offset)->setCurveInsync (c, TRUE); - ((SPShape *) offset)->setCurveBeforeLPE(c); + + this->setCurveInsync (c, TRUE); + this->setCurveBeforeLPE(c); + c->unref(); } + return; } // extra paraniac careful check. the preceding if () should take care of this case - if (fabs (offset->rad) < 0.01) - offset->rad = (offset->rad < 0) ? -0.01 : 0.01; + if (fabs (this->rad) < 0.01) { + this->rad = (this->rad < 0) ? -0.01 : 0.01; + } Path *orig = new Path; - orig->Copy ((Path *) offset->originalPath); + orig->Copy ((Path *)this->originalPath); if ( use_slow_but_correct_offset_method == false ) { // version par outline @@ -386,14 +407,14 @@ void COffset::set_shape() { // and now: offset float o_width; - if (offset->rad >= 0) + if (this->rad >= 0) { - o_width = offset->rad; + o_width = this->rad; orig->OutsideOutline (res, o_width, join_round, butt_straight, 20.0); } else { - o_width = -offset->rad; + o_width = -this->rad; orig->OutsideOutline (res, -o_width, join_round, butt_straight, 20.0); } @@ -413,13 +434,16 @@ void COffset::set_shape() { theRes->ConvertToForme (orig, 1, originaux); - SPItem *item = shape; - Geom::OptRect bbox = item->desktopVisualBounds(); + Geom::OptRect bbox = this->desktopVisualBounds(); + if ( bbox ) { gdouble size = L2(bbox->dimensions()); - gdouble const exp = item->transform.descrim(); - if (exp != 0) + gdouble const exp = this->transform.descrim(); + + if (exp != 0) { size /= exp; + } + orig->Coalesce (size * 0.001); //g_print ("coa %g exp %g item %p\n", size * 0.001, exp, item); } @@ -450,13 +474,13 @@ void COffset::set_shape() { // and now: offset float o_width; - if (offset->rad >= 0) + if (this->rad >= 0) { - o_width = offset->rad; + o_width = this->rad; } else { - o_width = -offset->rad; + o_width = -this->rad; } // one has to have a measure of the details @@ -468,24 +492,32 @@ void COffset::set_shape() { { orig->ConvertWithBackData (0.5*o_width); } + orig->Fill (theShape, 0); theRes->ConvertToShape (theShape, fill_positive); + Path *originaux[1]; originaux[0]=orig; + Path *res = new Path; theRes->ConvertToForme (res, 1, originaux); + int nbPart=0; Path** parts=res->SubPaths(nbPart,true); char *holes=(char*)malloc(nbPart*sizeof(char)); + // we offset contours separately, because we can. // this way, we avoid doing a unique big ConvertToShape when dealing with big shapes with lots of holes { Shape* onePart=new Shape; Shape* oneCleanPart=new Shape; + theShape->Reset(); + for (int i=0;iSurface(); parts[i]->Convert(1.0); + { // raffiner si besoin double bL,bT,bR,bB; @@ -495,29 +527,41 @@ void COffset::set_shape() { parts[i]->Convert(0.02*mesure); } } + if ( partSurf < 0 ) { // inverse par rapport a la realite // plein holes[i]=0; parts[i]->Fill(oneCleanPart,0); onePart->ConvertToShape(oneCleanPart,fill_positive); // there aren't intersections in that one, but maybe duplicate points and null edges - oneCleanPart->MakeOffset(onePart,offset->rad,join_round,20.0); + oneCleanPart->MakeOffset(onePart,this->rad,join_round,20.0); onePart->ConvertToShape(oneCleanPart,fill_positive); onePart->CalcBBox(); double typicalSize=0.5*((onePart->rightX-onePart->leftX)+(onePart->bottomY-onePart->topY)); - if ( typicalSize < 0.05 ) typicalSize=0.05; + + if ( typicalSize < 0.05 ) { + typicalSize=0.05; + } + typicalSize*=0.01; - if ( typicalSize > 1.0 ) typicalSize=1.0; + + if ( typicalSize > 1.0 ) { + typicalSize=1.0; + } + onePart->ConvertToForme (parts[i]); parts[i]->ConvertEvenLines (typicalSize); parts[i]->Simplify (typicalSize); + double nPartSurf=parts[i]->Surface(); + if ( nPartSurf >= 0 ) { // inversion de la surface -> disparait delete parts[i]; parts[i]=NULL; } else { } + /* int firstP=theShape->nbPt; for (int j=0;jnbPt;j++) theShape->AddPoint(onePart->pts[j].x); for (int j=0;jnbAr;j++) theShape->AddEdge(firstP+onePart->aretes[j].st,firstP+onePart->aretes[j].en);*/ @@ -526,19 +570,28 @@ void COffset::set_shape() { holes[i]=1; parts[i]->Fill(oneCleanPart,0,false,true,true); onePart->ConvertToShape(oneCleanPart,fill_positive); - oneCleanPart->MakeOffset(onePart,-offset->rad,join_round,20.0); + oneCleanPart->MakeOffset(onePart,-this->rad,join_round,20.0); onePart->ConvertToShape(oneCleanPart,fill_positive); // for (int j=0;jnbAr;j++) onePart->Inverse(j); // pas oublier de reinverser onePart->CalcBBox(); double typicalSize=0.5*((onePart->rightX-onePart->leftX)+(onePart->bottomY-onePart->topY)); - if ( typicalSize < 0.05 ) typicalSize=0.05; + + if ( typicalSize < 0.05 ) { + typicalSize=0.05; + } + typicalSize*=0.01; - if ( typicalSize > 1.0 ) typicalSize=1.0; + + if ( typicalSize > 1.0 ) { + typicalSize=1.0; + } + onePart->ConvertToForme (parts[i]); parts[i]->ConvertEvenLines (typicalSize); parts[i]->Simplify (typicalSize); double nPartSurf=parts[i]->Surface(); + if ( nPartSurf >= 0 ) { // inversion de la surface -> disparait delete parts[i]; @@ -556,11 +609,14 @@ void COffset::set_shape() { delete onePart; delete oneCleanPart; } + if ( nbPart > 1 ) { theShape->Reset(); + for (int i=0;iConvertWithBackData(1.0); + if ( holes[i] ) { parts[i]->Fill(theShape,i,true,true,true); } else { @@ -568,12 +624,23 @@ void COffset::set_shape() { } } } + theRes->ConvertToShape (theShape, fill_positive); theRes->ConvertToForme (orig,nbPart,parts); - for (int i=0;iCopy(parts[0]); - for (int i=0;iReset(); } @@ -588,14 +655,21 @@ void COffset::set_shape() { orig->Simplify (1.0 * o_width); }*/ - if ( parts ) free(parts); - if ( holes ) free(holes); + if ( parts ) { + free(parts); + } + + if ( holes ) { + free(holes); + } + delete res; delete theShape; delete theRes; } { char *res_d = NULL; + if (orig->descr_cmd.size() <= 1) { // Aie.... nothing left. @@ -607,20 +681,22 @@ void COffset::set_shape() { res_d = orig->svg_dump_path (); } + delete orig; Geom::PathVector pv = sp_svg_read_pathv(res_d); SPCurve *c = new SPCurve(pv); g_assert(c != NULL); - ((SPShape *) offset)->setCurveInsync (c, TRUE); - ((SPShape *) offset)->setCurveBeforeLPE(c); + + this->setCurveInsync (c, TRUE); + this->setCurveBeforeLPE(c); c->unref(); free (res_d); } } -void COffset::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { +void SPOffset::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { CShape::snappoints(p, snapprefs); } @@ -656,31 +732,53 @@ vectors_are_clockwise (Geom::Point A, Geom::Point B, Geom::Point C) double ca_c = dot(C, A); double ab_a = acos (ab_c); - if (ab_c <= -1.0) + + if (ab_c <= -1.0) { ab_a = M_PI; - if (ab_c >= 1.0) + } + + if (ab_c >= 1.0) { ab_a = 0; - if (ab_s < 0) + } + + if (ab_s < 0) { ab_a = 2 * M_PI - ab_a; + } + double bc_a = acos (bc_c); - if (bc_c <= -1.0) + + if (bc_c <= -1.0) { bc_a = M_PI; - if (bc_c >= 1.0) + } + + if (bc_c >= 1.0) { bc_a = 0; - if (bc_s < 0) + } + + if (bc_s < 0) { bc_a = 2 * M_PI - bc_a; + } + double ca_a = acos (ca_c); - if (ca_c <= -1.0) + + if (ca_c <= -1.0) { ca_a = M_PI; - if (ca_c >= 1.0) + } + + if (ca_c >= 1.0) { ca_a = 0; - if (ca_s < 0) + } + + if (ca_s < 0) { ca_a = 2 * M_PI - ca_a; + } double lim = 2 * M_PI - ca_a; - if (ab_a < lim) + if (ab_a < lim) { return true; + } + return false; } @@ -695,9 +793,10 @@ vectors_are_clockwise (Geom::Point A, Geom::Point B, Geom::Point C) double sp_offset_distance_to_original (SPOffset * offset, Geom::Point px) { - if (offset == NULL || offset->originalPath == NULL - || ((Path *) offset->originalPath)->descr_cmd.size() <= 1) + if (offset == NULL || offset->originalPath == NULL || ((Path *) offset->originalPath)->descr_cmd.size() <= 1) { return 1.0; + } + double dist = 1.0; Shape *theShape = new Shape; Shape *theRes = new Shape; @@ -726,14 +825,16 @@ sp_offset_distance_to_original (SPOffset * offset, Geom::Point px) bool ptSet = false; double arDist = -1.0; bool arSet = false; + // first get the minimum distance to the points for (int i = 0; i < theRes->numberOfPoints(); i++) { if (theRes->getPoint(i).totalDegree() > 0) - { + { Geom::Point nx = theRes->getPoint(i).x; Geom::Point nxpx = px-nx; double ndist = sqrt (dot(nxpx,nxpx)); + if (ptSet == false || fabs (ndist) < fabs (ptDist)) { // we have a new minimum distance @@ -745,6 +846,7 @@ sp_offset_distance_to_original (SPOffset * offset, Geom::Point px) fb = theRes->getPoint(i).incidentEdge[LAST]; pb = theRes->getPoint(i).incidentEdge[LAST]; cb = theRes->getPoint(i).incidentEdge[FIRST]; + do { // one angle @@ -755,10 +857,12 @@ sp_offset_distance_to_original (SPOffset * offset, Geom::Point px) nex = theRes->getEdge(cb).dx; nlen = sqrt (dot(nex , nex)); nex /= nlen; + if (theRes->getEdge(pb).en == i) { prx = -prx; } + if (theRes->getEdge(cb).en == i) { nex = -nex; @@ -779,13 +883,16 @@ sp_offset_distance_to_original (SPOffset * offset, Geom::Point px) } break; } + pb = cb; cb = theRes->NextAt (i, cb); } + while (cb >= 0 && pb >= 0 && pb != fb); } } } + // loop over the edges to try to improve the distance for (int i = 0; i < theRes->numberOfEdges(); i++) { @@ -793,14 +900,17 @@ sp_offset_distance_to_original (SPOffset * offset, Geom::Point px) Geom::Point ex = theRes->getPoint(theRes->getEdge(i).en).x; Geom::Point nx = ex - sx; double len = sqrt (dot(nx,nx)); + if (len > 0.0001) { Geom::Point pxsx=px-sx; double ab = dot(nx,pxsx); + if (ab > 0 && ab < len * len) { // we're in the zone of influence of the segment double ndist = (cross(pxsx,nx)) / len; + if (arSet == false || fabs (ndist) < fabs (arDist)) { arDist = ndist; @@ -809,16 +919,22 @@ sp_offset_distance_to_original (SPOffset * offset, Geom::Point px) } } } + if (arSet || ptSet) { - if (arSet == false) + if (arSet == false) { arDist = ptDist; - if (ptSet == false) + } + + if (ptSet == false) { ptDist = arDist; - if (fabs (ptDist) < fabs (arDist)) + } + + if (fabs (ptDist) < fabs (arDist)) { dist = ptDist; - else + } else { dist = arDist; + } } } @@ -838,8 +954,10 @@ void sp_offset_top_point (SPOffset const * offset, Geom::Point *px) { (*px) = Geom::Point(0, 0); - if (offset == NULL) + + if (offset == NULL) { return; + } if (offset->knotSet) { @@ -848,13 +966,19 @@ sp_offset_top_point (SPOffset const * offset, Geom::Point *px) } SPCurve *curve = SP_SHAPE (offset)->getCurve(); + if (curve == NULL) { - offset->coffset->set_shape(); + // CPPIFY + //offset->set_shape(); + const_cast(offset)->set_shape(); + curve = SP_SHAPE (offset)->getCurve(); + if (curve == NULL) return; } + if (curve->is_empty()) { curve->unref(); @@ -897,8 +1021,9 @@ static void sp_offset_start_listening(SPOffset *offset,SPObject* to) static void sp_offset_quit_listening(SPOffset *offset) { - if ( offset->sourceObject == NULL ) + if ( offset->sourceObject == NULL ) { return; + } offset->_modified_connection.disconnect(); offset->_delete_connection.disconnect(); @@ -912,9 +1037,14 @@ static void sp_offset_href_changed(SPObject */*old_ref*/, SPObject */*ref*/, SPOffset *offset) { sp_offset_quit_listening(offset); + if (offset->sourceRef) { SPItem *refobj = offset->sourceRef->getObject(); - if (refobj) sp_offset_start_listening(offset,refobj); + + if (refobj) { + sp_offset_start_listening(offset,refobj); + } + offset->sourceDirty=true; offset->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } @@ -926,6 +1056,7 @@ static void sp_offset_move_compensate(Geom::Affine const *mp, SPItem */*original guint mode = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_PARALLEL); Geom::Affine m(*mp); + if (!(m.isTranslation()) || mode == SP_CLONE_COMPENSATION_NONE) { self->sourceDirty=true; self->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); @@ -966,7 +1097,11 @@ sp_offset_delete_self(SPObject */*deleted*/, SPOffset *offset) if (mode == SP_CLONE_ORPHANS_UNLINK) { // leave it be. just forget about the source sp_offset_quit_listening(offset); - if ( offset->sourceHref ) g_free(offset->sourceHref); + + if ( offset->sourceHref ) { + g_free(offset->sourceHref); + } + offset->sourceHref = NULL; offset->sourceRef->detach(); } else if (mode == SP_CLONE_ORPHANS_DELETE) { @@ -979,6 +1114,7 @@ sp_offset_source_modified (SPObject */*iSource*/, guint flags, SPItem *item) { SPOffset *offset = SP_OFFSET(item); offset->sourceDirty=true; + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG)) { offset->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } @@ -987,35 +1123,54 @@ sp_offset_source_modified (SPObject */*iSource*/, guint flags, SPItem *item) static void refresh_offset_source(SPOffset* offset) { - if ( offset == NULL ) return; + if ( offset == NULL ) { + return; + } + offset->sourceDirty=false; // le mauvais cas: pas d'attribut d => il faut verifier que c'est une SPShape puis prendre le contour // The bad case: no d attribute. Must check that it's an SPShape and then take the outline. SPObject *refobj=offset->sourceObject; - if ( refobj == NULL ) return; + + if ( refobj == NULL ) { + return; + } + SPItem *item = SP_ITEM (refobj); SPCurve *curve=NULL; - if (!SP_IS_SHAPE (item) && !SP_IS_TEXT (item)) return; + + if (!SP_IS_SHAPE (item) && !SP_IS_TEXT (item)) { + return; + } + if (SP_IS_SHAPE (item)) { curve = SP_SHAPE (item)->getCurve (); - if (curve == NULL) + + if (curve == NULL) { return; + } } + if (SP_IS_TEXT (item)) { curve = SP_TEXT (item)->getNormalizedBpath (); - if (curve == NULL) - return; + + if (curve == NULL) { + return; + } } + Path *orig = new Path; orig->LoadPathVector(curve->get_pathvector()); curve->unref(); if (!item->transform.isIdentity()) { gchar const *t_attr = item->getRepr()->attribute("transform"); + if (t_attr) { Geom::Affine t; + if (sp_svg_transform_read(t_attr, &t)) { orig->Transform(t); } @@ -1034,6 +1189,7 @@ refresh_offset_source(SPOffset* offset) css = sp_repr_css_attr (offset->sourceRepr , "style"); val = sp_repr_css_property (css, "fill-rule", NULL); + if (val && strcmp (val, "nonzero") == 0) { theRes->ConvertToShape (theShape, fill_nonZero); @@ -1072,9 +1228,12 @@ sp_offset_get_source (SPOffset *offset) { if (offset && offset->sourceRef) { SPItem *refobj = offset->sourceRef->getObject(); - if (SP_IS_ITEM (refobj)) + + if (SP_IS_ITEM (refobj)) { return (SPItem *) refobj; + } } + return NULL; } -- cgit v1.2.3 From cfe48de7f071e2e07a1f2f2ace3456f7b410e93b Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 15:37:33 +0200 Subject: Merged Shape and subclasses. Cleaned up a bit. (bzr r11608.1.76) --- src/sp-offset.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index ede1ab39b..5a8d3e1d0 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -95,9 +95,7 @@ static void sp_offset_source_modified (SPObject *iSource, guint flags, SPItem *i // reappearing in offset when the radius becomes too large static bool use_slow_but_correct_offset_method=false; -SPOffset::SPOffset() : SPShape(), CShape(this) { - delete this->cshape; - this->cshape = this; +SPOffset::SPOffset() : SPShape() { this->clpeitem = this; this->citem = this; this->cobject = this; @@ -133,7 +131,7 @@ SPOffset::~SPOffset() { } void SPOffset::build(SPDocument *document, Inkscape::XML::Node *repr) { - CShape::build(document, repr); + SPShape::build(document, repr); //XML Tree being used directly here while it shouldn't be. if (this->getRepr()->attribute("inkscape:radius")) { @@ -212,7 +210,7 @@ Inkscape::XML::Node* SPOffset::write(Inkscape::XML::Document *xml_doc, Inkscape: repr->setAttribute("d", d); g_free (d); - CShape::write(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); + SPShape::write(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); return repr; } @@ -238,7 +236,7 @@ void SPOffset::release() { this->sourceHref = NULL; this->sourceRef->detach(); - CShape::release(); + SPShape::release(); } void SPOffset::set(unsigned int key, const gchar* value) { @@ -321,7 +319,7 @@ void SPOffset::set(unsigned int key, const gchar* value) { break; default: - CShape::set(key, value); + SPShape::set(key, value); break; } } @@ -337,12 +335,12 @@ void SPOffset::update(SPCtx *ctx, guint flags) { (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - this->setShape (); + this->set_shape(); } this->isUpdating=false; - CShape::update(ctx, flags); + SPShape::update(ctx, flags); } gchar* SPOffset::description() { @@ -697,7 +695,7 @@ void SPOffset::set_shape() { } void SPOffset::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { - CShape::snappoints(p, snapprefs); + SPShape::snappoints(p, snapprefs); } -- 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-offset.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index 5a8d3e1d0..3743ad88d 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -96,7 +96,6 @@ static void sp_offset_source_modified (SPObject *iSource, guint flags, SPItem *i static bool use_slow_but_correct_offset_method=false; SPOffset::SPOffset() : SPShape() { - 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-offset.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index 3743ad88d..89f6e20d4 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -96,7 +96,6 @@ static void sp_offset_source_modified (SPObject *iSource, guint flags, SPItem *i static bool use_slow_but_correct_offset_method=false; SPOffset::SPOffset() : SPShape() { - this->citem = this; this->cobject = this; this->rad = 1.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-offset.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index 89f6e20d4..ef18acc8e 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -96,8 +96,6 @@ static void sp_offset_source_modified (SPObject *iSource, guint flags, SPItem *i static bool use_slow_but_correct_offset_method=false; SPOffset::SPOffset() : SPShape() { - this->cobject = this; - this->rad = 1.0; this->original = NULL; this->originalPath = NULL; -- cgit v1.2.3 From eb3598e7e27619c759ef33bb9ec4ffb8898523de Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Fri, 20 Sep 2013 00:45:16 -0400 Subject: Refactor status-bar text for multiple items, was very broken Fixed bugs: - https://launchpad.net/bugs/1199192 (bzr r12550) --- src/sp-offset.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/sp-offset.cpp') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index ef18acc8e..f9759cac1 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -339,18 +339,20 @@ void SPOffset::update(SPCtx *ctx, guint flags) { SPShape::update(ctx, flags); } -gchar* SPOffset::description() { +const char* SPOffset::display_name() { if ( this->sourceHref ) { - // TRANSLATORS COMMENT: %s is either "outset" or "inset" depending on sign - return g_strdup_printf(_("Linked offset, %s by %f pt"), - (this->rad >= 0)? _("outset") : _("inset"), fabs (this->rad)); + return _("Linked Offset"); } else { - // TRANSLATORS COMMENT: %s is either "outset" or "inset" depending on sign - return g_strdup_printf(_("Dynamic offset, %s by %f pt"), - (this->rad >= 0)? _("outset") : _("inset"), fabs (this->rad)); + return _("Dynamic Offset"); } } +gchar* SPOffset::description() { + // TRANSLATORS COMMENT: %s is either "outset" or "inset" depending on sign + return g_strdup_printf(_("%s by %f pt"), (this->rad >= 0) ? + _("outset") : _("inset"), fabs (this->rad)); +} + void SPOffset::set_shape() { if ( this->originalPath == NULL ) { // oops : no path?! (the offset object should do harakiri) -- cgit v1.2.3