summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-04-04 22:27:58 +0000
committerMarkus Engel <markus.engel@tum.de>2013-04-04 22:27:58 +0000
commit748ffce08bb6250c87adabb64f45bff02509e9e7 (patch)
tree42c279594149e045b4de61f90f0829bb1d408f22 /src
parentMerged SPSpiral and CSpiral. (diff)
downloadinkscape-748ffce08bb6250c87adabb64f45bff02509e9e7.tar.gz
inkscape-748ffce08bb6250c87adabb64f45bff02509e9e7.zip
Combined some classes.
(bzr r11608.1.75)
Diffstat (limited to 'src')
-rw-r--r--src/box3d-side.cpp120
-rw-r--r--src/box3d-side.h12
-rw-r--r--src/sp-ellipse.cpp198
-rw-r--r--src/sp-ellipse.h54
-rw-r--r--src/sp-line.cpp156
-rw-r--r--src/sp-line.h16
-rw-r--r--src/sp-offset.cpp531
-rw-r--r--src/sp-offset.h16
-rw-r--r--src/sp-path.cpp250
-rw-r--r--src/sp-path.h14
-rw-r--r--src/sp-polygon.cpp49
-rw-r--r--src/sp-polygon.h15
-rw-r--r--src/sp-polyline.cpp74
-rw-r--r--src/sp-polyline.h17
-rw-r--r--src/sp-star.cpp329
-rw-r--r--src/sp-star.h11
16 files changed, 896 insertions, 966 deletions
diff --git a/src/box3d-side.cpp b/src/box3d-side.cpp
index c2940254f..ca80f91df 100644
--- a/src/box3d-side.cpp
+++ b/src/box3d-side.cpp
@@ -36,44 +36,28 @@ namespace {
bool box3DSideRegistered = SPFactory::instance().registerObject("inkscape:box3dside", createBox3DSide);
}
-CBox3DSide::CBox3DSide(Box3DSide* box3dside) : CPolygon(box3dside) {
- this->spbox3dside = box3dside;
-}
-
-CBox3DSide::~CBox3DSide() {
-}
-
Box3DSide::Box3DSide() : SPPolygon() {
- Box3DSide* side = this;
-
- side->cbox3dside = new CBox3DSide(side);
- side->typeHierarchy.insert(typeid(Box3DSide));
-
- delete side->cpolygon;
- side->cpolygon = side->cbox3dside;
- side->cshape = side->cbox3dside;
- side->clpeitem = side->cbox3dside;
- side->citem = side->cbox3dside;
- side->cobject = side->cbox3dside;
-
- side->dir1 = Box3D::NONE;
- side->dir2 = Box3D::NONE;
- side->front_or_rear = Box3D::FRONT;
+ this->cshape = this;
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
+
+ this->dir1 = Box3D::NONE;
+ this->dir2 = Box3D::NONE;
+ this->front_or_rear = Box3D::FRONT;
}
-void CBox3DSide::build(SPDocument * document, Inkscape::XML::Node * repr) {
- Box3DSide* object = this->spbox3dside;
+Box3DSide::~Box3DSide() {
+}
- CPolygon::build(document, repr);
+void Box3DSide::build(SPDocument * document, Inkscape::XML::Node * repr) {
+ SPPolygon::build(document, repr);
- object->readAttr( "inkscape:box3dsidetype" );
+ this->readAttr( "inkscape:box3dsidetype" );
}
-Inkscape::XML::Node* CBox3DSide::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- Box3DSide* object = this->spbox3dside;
- Box3DSide *side = object;
-
+Inkscape::XML::Node* Box3DSide::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
// this is where we end up when saving as plain SVG (also in other circumstances?)
// thus we don' set "sodipodi:type" so that the box is only saved as an ordinary svg:path
@@ -81,30 +65,29 @@ Inkscape::XML::Node* CBox3DSide::write(Inkscape::XML::Document *xml_doc, Inkscap
}
if (flags & SP_OBJECT_WRITE_EXT) {
- sp_repr_set_int(repr, "inkscape:box3dsidetype", side->dir1 ^ side->dir2 ^ side->front_or_rear);
+ sp_repr_set_int(repr, "inkscape:box3dsidetype", this->dir1 ^ this->dir2 ^ this->front_or_rear);
}
- static_cast<SPShape *>(object)->setShape();
+ this->setShape();
/* Duplicate the path */
- SPCurve const *curve = (SP_SHAPE(object))->_curve;
+ SPCurve const *curve = this->_curve;
+
//Nulls might be possible if this called iteratively
if ( !curve ) {
return NULL;
}
+
char *d = sp_svg_write_path ( curve->get_pathvector() );
repr->setAttribute("d", d);
g_free (d);
- CPolygon::write(xml_doc, repr, flags);
+ SPPolygon::write(xml_doc, repr, flags);
return repr;
}
-void CBox3DSide::set(unsigned int key, const gchar* value) {
- Box3DSide* object = this->spbox3dside;
- Box3DSide *side = object;
-
+void Box3DSide::set(unsigned int key, const gchar* value) {
// TODO: In case the box was recreated (by undo, e.g.) we need to recreate the path
// (along with other info?) from the parent box.
@@ -117,25 +100,25 @@ void CBox3DSide::set(unsigned int key, const gchar* value) {
if (!Box3D::is_face_id(desc)) {
g_print ("desc is not a face id: =%s=\n", value);
}
+
g_return_if_fail (Box3D::is_face_id (desc));
+
Box3D::Axis plane = (Box3D::Axis) (desc & 0x7);
plane = (Box3D::is_plane(plane) ? plane : Box3D::orth_plane_or_axis(plane));
- side->dir1 = Box3D::extract_first_axis_direction(plane);
- side->dir2 = Box3D::extract_second_axis_direction(plane);
- side->front_or_rear = (Box3D::FrontOrRear) (desc & 0x8);
+ this->dir1 = Box3D::extract_first_axis_direction(plane);
+ this->dir2 = Box3D::extract_second_axis_direction(plane);
+ this->front_or_rear = (Box3D::FrontOrRear) (desc & 0x8);
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
break;
default:
- CPolygon::set(key, value);
+ SPPolygon::set(key, value);
break;
}
}
-void CBox3DSide::update(SPCtx* ctx, guint flags) {
- Box3DSide* object = this->spbox3dside;
-
+void Box3DSide::update(SPCtx* ctx, guint flags) {
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore
}
@@ -143,11 +126,11 @@ void CBox3DSide::update(SPCtx* ctx, guint flags) {
if (flags & (SP_OBJECT_MODIFIED_FLAG |
SP_OBJECT_STYLE_MODIFIED_FLAG |
SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
- static_cast<SPShape *>(object)->setShape ();
- }
- CPolygon::update(ctx, flags);
+ this->setShape();
+ }
+ SPPolygon::update(ctx, flags);
}
/* Create a new Box3DSide and append it to the parent box */
@@ -172,30 +155,30 @@ int Box3DSide::getFaceId()
void
box3d_side_position_set (Box3DSide *side) {
- side->cbox3dside->set_shape();
+ side->set_shape();
// This call is responsible for live update of the sides during the initial drag
side->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
-void CBox3DSide::set_shape() {
- Box3DSide* shape = this->spbox3dside;
- Box3DSide *side = shape;
-
- if (!side->document->getRoot()) {
+void Box3DSide::set_shape() {
+ if (!this->document->getRoot()) {
// avoid a warning caused by sp_document_height() (which is called from sp_item_i2d_affine() below)
// when reading a file containing 3D boxes
return;
}
- SPObject *parent = side->parent;
+ SPObject *parent = this->parent;
+
if (!SP_IS_BOX3D(parent)) {
- g_warning ("Parent of 3D box side is not a 3D box.\n");
+ g_warning("Parent of 3D box side is not a 3D box.\n");
return;
}
+
SPBox3D *box = SP_BOX3D(parent);
- Persp3D *persp = box3d_side_perspective(side);
+ Persp3D *persp = box3d_side_perspective(this);
+
if (!persp) {
return;
}
@@ -206,7 +189,7 @@ void CBox3DSide::set_shape() {
// resulting path.
unsigned int corners[4];
- box3d_side_compute_corner_ids(side, corners);
+ box3d_side_compute_corner_ids(this, corners);
SPCurve *c = new SPCurve();
@@ -225,17 +208,21 @@ void CBox3DSide::set_shape() {
c->lineto(box3d_get_corner_screen(box, corners[3]));
c->closepath();
- /* Reset the shape'scurve to the "original_curve"
+ /* Reset the this'scurve to the "original_curve"
* This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/
- shape->setCurveInsync( c, TRUE);
- if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(shape)) && sp_lpe_item_path_effects_enabled(SP_LPE_ITEM(shape))) {
+ this->setCurveInsync( c, TRUE);
+
+ if (sp_lpe_item_has_path_effect(this) && sp_lpe_item_path_effects_enabled(this)) {
SPCurve *c_lpe = c->copy();
- bool success = sp_lpe_item_perform_path_effect(SP_LPE_ITEM (shape), c_lpe);
+ bool success = sp_lpe_item_perform_path_effect(this, c_lpe);
+
if (success) {
- shape->setCurveInsync( c_lpe, TRUE);
+ this->setCurveInsync(c_lpe, TRUE);
}
+
c_lpe->unref();
}
+
c->unref();
}
@@ -243,19 +230,24 @@ gchar *box3d_side_axes_string(Box3DSide *side)
{
GString *pstring = g_string_new("");
g_string_printf (pstring, "%s", Box3D::string_from_axes ((Box3D::Axis) (side->dir1 ^ side->dir2)));
+
switch ((Box3D::Axis) (side->dir1 ^ side->dir2)) {
case Box3D::XY:
g_string_append_printf (pstring, (side->front_or_rear == Box3D::FRONT) ? "front" : "rear");
break;
+
case Box3D::XZ:
g_string_append_printf (pstring, (side->front_or_rear == Box3D::FRONT) ? "top" : "bottom");
break;
+
case Box3D::YZ:
g_string_append_printf (pstring, (side->front_or_rear == Box3D::FRONT) ? "right" : "left");
break;
+
default:
break;
}
+
return pstring->str;
}
diff --git a/src/box3d-side.h b/src/box3d-side.h
index 37528f405..106f3770c 100644
--- a/src/box3d-side.h
+++ b/src/box3d-side.h
@@ -22,25 +22,18 @@
class SPBox3D;
struct Persp3D;
-class CBox3DSide;
// FIXME: Would it be better to inherit from SPPath instead?
class Box3DSide : public SPPolygon {
public:
Box3DSide();
- CBox3DSide* cbox3dside;
+ virtual ~Box3DSide();
Box3D::Axis dir1;
Box3D::Axis dir2;
Box3D::FrontOrRear front_or_rear;
int getFaceId();
static Box3DSide * createBox3DSide(SPBox3D *box);
-};
-
-class CBox3DSide : public CPolygon {
-public:
- CBox3DSide(Box3DSide* box3dside);
- virtual ~CBox3DSide();
virtual void build(SPDocument* doc, Inkscape::XML::Node* repr);
virtual void set(unsigned int key, gchar const* value);
@@ -48,9 +41,6 @@ public:
virtual void update(SPCtx *ctx, guint flags);
virtual void set_shape();
-
-protected:
- Box3DSide* spbox3dside;
};
void box3d_side_position_set (Box3DSide *side); // FIXME: Replace this by box3d_side_set_shape??
diff --git a/src/sp-ellipse.cpp b/src/sp-ellipse.cpp
index 0e84a0360..23a7c91b0 100644
--- a/src/sp-ellipse.cpp
+++ b/src/sp-ellipse.cpp
@@ -88,38 +88,28 @@ static double sp_round(double x, double y)
static gboolean sp_arc_set_elliptical_path_attribute(SPArc *arc, Inkscape::XML::Node *repr);
+SPGenericEllipse::SPGenericEllipse() : SPShape(), CShape(this) {
+ delete this->cshape;
+ this->cshape = this;
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
-CGenericEllipse::CGenericEllipse(SPGenericEllipse* genericEllipse) : CShape(genericEllipse) {
- this->spgenericEllipse = genericEllipse;
-}
+ this->cx.unset();
+ this->cy.unset();
+ this->rx.unset();
+ this->ry.unset();
-CGenericEllipse::~CGenericEllipse() {
+ this->start = 0.0;
+ this->end = SP_2PI;
+ this->closed = TRUE;
}
-SPGenericEllipse::SPGenericEllipse() : SPShape() {
- SPGenericEllipse* ellipse = this;
-
- ellipse->cgenericEllipse = new CGenericEllipse(ellipse);
- ellipse->typeHierarchy.insert(typeid(SPGenericEllipse));
-
- delete ellipse->cshape;
- ellipse->cshape = ellipse->cgenericEllipse;
- ellipse->clpeitem = ellipse->cgenericEllipse;
- ellipse->citem = ellipse->cgenericEllipse;
- ellipse->cobject = ellipse->cgenericEllipse;
-
- ellipse->cx.unset();
- ellipse->cy.unset();
- ellipse->rx.unset();
- ellipse->ry.unset();
-
- ellipse->start = 0.0;
- ellipse->end = SP_2PI;
- ellipse->closed = TRUE;
+SPGenericEllipse::~SPGenericEllipse() {
}
-void CGenericEllipse::update(SPCtx *ctx, guint flags) {
- SPGenericEllipse* object = this->spgenericEllipse;
+void SPGenericEllipse::update(SPCtx *ctx, guint flags) {
+ SPGenericEllipse* object = this;
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
SPGenericEllipse *ellipse = (SPGenericEllipse *) object;
@@ -141,8 +131,8 @@ void CGenericEllipse::update(SPCtx *ctx, guint flags) {
CShape::update(ctx, flags);
}
-void CGenericEllipse::update_patheffect(bool write) {
- SPShape *shape = this->spgenericEllipse;
+void SPGenericEllipse::update_patheffect(bool write) {
+ SPShape *shape = this;
this->set_shape();
if (write) {
@@ -161,8 +151,8 @@ void CGenericEllipse::update_patheffect(bool write) {
/* fixme: Think (Lauris) */
/* Can't we use arcto in this method? */
-void CGenericEllipse::set_shape() {
- SPGenericEllipse* shape = this->spgenericEllipse;
+void SPGenericEllipse::set_shape() {
+ SPGenericEllipse* shape = this;
if (sp_lpe_item_has_broken_path_effect(SP_LPE_ITEM(shape))) {
g_warning ("The ellipse shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as ellipse will remove the bad LPE");
@@ -251,8 +241,8 @@ void CGenericEllipse::set_shape() {
curve->unref();
}
-void CGenericEllipse::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) {
- SPGenericEllipse* item = this->spgenericEllipse;
+void SPGenericEllipse::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) {
+ SPGenericEllipse* item = this;
g_assert(item != NULL);
g_assert(SP_IS_GENERICELLIPSE(item));
@@ -334,8 +324,8 @@ sp_genericellipse_normalize(SPGenericEllipse *ellipse)
/* Now we keep: 0 <= start < end <= 2*PI */
}
-Inkscape::XML::Node* CGenericEllipse::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPGenericEllipse *ellipse = this->spgenericEllipse;
+Inkscape::XML::Node* SPGenericEllipse::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
+ SPGenericEllipse *ellipse = this;
SPGenericEllipse* object = ellipse;
if (flags & SP_OBJECT_WRITE_EXT) {
@@ -360,32 +350,20 @@ Inkscape::XML::Node* CGenericEllipse::write(Inkscape::XML::Document *xml_doc, In
}
/* SVG <ellipse> element */
-
-CEllipse::CEllipse(SPEllipse* ellipse) : CGenericEllipse(ellipse) {
- this->spellipse = ellipse;
-}
-
-CEllipse::~CEllipse() {
-}
-
SPEllipse::SPEllipse() : SPGenericEllipse() {
- SPEllipse* ellipse = this;
-
- ellipse->cellipse = new CEllipse(ellipse);
- ellipse->typeHierarchy.insert(typeid(SPEllipse));
+ this->cshape = this;
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
+}
- delete ellipse->cgenericEllipse;
- ellipse->cgenericEllipse = ellipse->cellipse;
- ellipse->cshape = ellipse->cellipse;
- ellipse->clpeitem = ellipse->cellipse;
- ellipse->citem = ellipse->cellipse;
- ellipse->cobject = ellipse->cellipse;
+SPEllipse::~SPEllipse() {
}
-void CEllipse::build(SPDocument *document, Inkscape::XML::Node *repr) {
- CGenericEllipse::build(document, repr);
+void SPEllipse::build(SPDocument *document, Inkscape::XML::Node *repr) {
+ SPGenericEllipse::build(document, repr);
- SPEllipse* object = this->spellipse;
+ SPEllipse* object = this;
object->readAttr( "cx" );
object->readAttr( "cy" );
object->readAttr( "rx" );
@@ -393,8 +371,8 @@ void CEllipse::build(SPDocument *document, Inkscape::XML::Node *repr) {
}
-Inkscape::XML::Node* CEllipse::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPGenericEllipse *ellipse = this->spellipse;
+Inkscape::XML::Node* SPEllipse::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
+ SPGenericEllipse *ellipse = this;
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
repr = xml_doc->createElement("svg:ellipse");
@@ -405,14 +383,14 @@ Inkscape::XML::Node* CEllipse::write(Inkscape::XML::Document *xml_doc, Inkscape:
sp_repr_set_svg_double(repr, "rx", ellipse->rx.computed);
sp_repr_set_svg_double(repr, "ry", ellipse->ry.computed);
- CGenericEllipse::write(xml_doc, repr, flags);
+ SPGenericEllipse::write(xml_doc, repr, flags);
return repr;
}
-void CEllipse::set(unsigned int key, gchar const* value) {
- SPEllipse *ellipse = this->spellipse;
+void SPEllipse::set(unsigned int key, gchar const* value) {
+ SPEllipse *ellipse = this;
SPEllipse* object = (SPEllipse*)ellipse;
switch (key) {
@@ -437,12 +415,12 @@ void CEllipse::set(unsigned int key, gchar const* value) {
object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
default:
- CGenericEllipse::set(key, value);
+ SPGenericEllipse::set(key, value);
break;
}
}
-gchar* CEllipse::description() {
+gchar* SPEllipse::description() {
return g_strdup(_("<b>Ellipse</b>"));
}
@@ -466,32 +444,20 @@ sp_ellipse_position_set(SPEllipse *ellipse, gdouble x, gdouble y, gdouble rx, gd
}
/* SVG <circle> element */
-
-CCircle::CCircle(SPCircle* circle) : CGenericEllipse(circle) {
- this->spcircle = circle;
-}
-
-CCircle::~CCircle() {
-}
-
SPCircle::SPCircle() : SPGenericEllipse() {
- SPCircle* circle = this;
-
- circle->ccircle = new CCircle(circle);
- circle->typeHierarchy.insert(typeid(SPCircle));
+ this->cshape = this;
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
+}
- delete circle->cgenericEllipse;
- circle->cgenericEllipse = circle->ccircle;
- circle->cshape = circle->ccircle;
- circle->clpeitem = circle->ccircle;
- circle->citem = circle->ccircle;
- circle->cobject = circle->ccircle;
+SPCircle::~SPCircle() {
}
-void CCircle::build(SPDocument *document, Inkscape::XML::Node *repr) {
- SPCircle* object = this->spcircle;
+void SPCircle::build(SPDocument *document, Inkscape::XML::Node *repr) {
+ SPCircle* object = this;
- CGenericEllipse::build(document, repr);
+ SPGenericEllipse::build(document, repr);
object->readAttr( "cx" );
object->readAttr( "cy" );
@@ -499,8 +465,8 @@ void CCircle::build(SPDocument *document, Inkscape::XML::Node *repr) {
}
-Inkscape::XML::Node* CCircle::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPGenericEllipse *ellipse = this->spcircle;
+Inkscape::XML::Node* SPCircle::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
+ SPGenericEllipse *ellipse = this;
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
repr = xml_doc->createElement("svg:circle");
@@ -510,13 +476,13 @@ Inkscape::XML::Node* CCircle::write(Inkscape::XML::Document *xml_doc, Inkscape::
sp_repr_set_svg_double(repr, "cy", ellipse->cy.computed);
sp_repr_set_svg_double(repr, "r", ellipse->rx.computed);
- CGenericEllipse::write(xml_doc, repr, flags);
+ SPGenericEllipse::write(xml_doc, repr, flags);
return repr;
}
-void CCircle::set(unsigned int key, gchar const* value) {
- SPGenericEllipse *ge = this->spcircle;
+void SPCircle::set(unsigned int key, gchar const* value) {
+ SPGenericEllipse *ge = this;
SPCircle* object = (SPCircle*)ge;
switch (key) {
@@ -536,42 +502,30 @@ void CCircle::set(unsigned int key, gchar const* value) {
object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
default:
- CGenericEllipse::set(key, value);
+ SPGenericEllipse::set(key, value);
break;
}
}
-gchar* CCircle::description() {
+gchar* SPCircle::description() {
return g_strdup(_("<b>Circle</b>"));
}
/* <path sodipodi:type="arc"> element */
-
-CArc::CArc(SPArc* arc) : CGenericEllipse(arc) {
- this->sparc = arc;
-}
-
-CArc::~CArc() {
-}
-
SPArc::SPArc() : SPGenericEllipse() {
- SPArc* arc = this;
-
- arc->carc = new CArc(arc);
- arc->typeHierarchy.insert(typeid(SPArc));
+ this->cshape = this;
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
+}
- delete arc->cgenericEllipse;
- arc->cgenericEllipse = arc->carc;
- arc->cshape = arc->carc;
- arc->clpeitem = arc->carc;
- arc->citem = arc->carc;
- arc->cobject = arc->carc;
+SPArc::~SPArc() {
}
-void CArc::build(SPDocument *document, Inkscape::XML::Node *repr) {
- SPArc* object = this->sparc;
+void SPArc::build(SPDocument *document, Inkscape::XML::Node *repr) {
+ SPArc* object = this;
- CGenericEllipse::build(document, repr);
+ SPGenericEllipse::build(document, repr);
object->readAttr( "sodipodi:cx" );
object->readAttr( "sodipodi:cy" );
@@ -625,8 +579,8 @@ sp_arc_set_elliptical_path_attribute(SPArc *arc, Inkscape::XML::Node *repr)
return true;
}
-Inkscape::XML::Node* CArc::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPArc* object = this->sparc;
+Inkscape::XML::Node* SPArc::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
+ SPArc* object = this;
SPGenericEllipse *ge = object;
SPArc *arc = object;
@@ -658,13 +612,13 @@ Inkscape::XML::Node* CArc::write(Inkscape::XML::Document *xml_doc, Inkscape::XML
// write d=
sp_arc_set_elliptical_path_attribute(arc, repr);
- CGenericEllipse::write(xml_doc, repr, flags);
+ SPGenericEllipse::write(xml_doc, repr, flags);
return repr;
}
-void CArc::set(unsigned int key, gchar const* value) {
- SPArc* object = this->sparc;
+void SPArc::set(unsigned int key, gchar const* value) {
+ SPArc* object = this;
SPGenericEllipse *ge = object;
switch (key) {
@@ -709,24 +663,24 @@ void CArc::set(unsigned int key, gchar const* value) {
object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
default:
- CGenericEllipse::set(key, value);
+ SPGenericEllipse::set(key, value);
break;
}
}
-void CArc::modified(guint flags) {
- SPArc* object = this->sparc;
+void SPArc::modified(guint flags) {
+ SPArc* object = this;
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
((SPShape *) object)->setShape();
}
- CGenericEllipse::modified(flags);
+ SPGenericEllipse::modified(flags);
}
-gchar* CArc::description() {
- SPArc* item = this->sparc;
+gchar* SPArc::description() {
+ SPArc* item = this;
SPGenericEllipse *ge = item;
gdouble len = fmod(ge->end - ge->start, SP_2PI);
diff --git a/src/sp-ellipse.h b/src/sp-ellipse.h
index 01f1a4a52..e7bc70aa8 100644
--- a/src/sp-ellipse.h
+++ b/src/sp-ellipse.h
@@ -21,12 +21,10 @@
#define SP_GENERICELLIPSE(obj) ((SPGenericEllipse*)obj)
#define SP_IS_GENERICELLIPSE(obj) (dynamic_cast<const SPGenericEllipse*>((SPObject*)obj))
-class CGenericEllipse;
-
-class SPGenericEllipse : public SPShape {
+class SPGenericEllipse : public SPShape, public CShape {
public:
SPGenericEllipse();
- CGenericEllipse* cgenericEllipse;
+ virtual ~SPGenericEllipse();
SVGLength cx;
SVGLength cy;
@@ -35,12 +33,6 @@ public:
unsigned int closed : 1;
double start, end;
-};
-
-class CGenericEllipse : public CShape {
-public:
- CGenericEllipse(SPGenericEllipse* genericEllipse);
- virtual ~CGenericEllipse();
virtual void update(SPCtx* ctx, unsigned int flags);
virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags);
@@ -49,9 +41,6 @@ public:
virtual void set_shape();
virtual void update_patheffect(bool write);
-
-protected:
- SPGenericEllipse* spgenericEllipse;
};
/* This is technically priate by we need this in object edit (Lauris) */
@@ -61,26 +50,15 @@ void sp_genericellipse_normalize (SPGenericEllipse *ellipse);
#define SP_ELLIPSE(obj) ((SPEllipse*)obj)
#define SP_IS_ELLIPSE(obj) (dynamic_cast<const SPEllipse*>((SPObject*)obj))
-class CEllipse;
-
class SPEllipse : public SPGenericEllipse {
public:
SPEllipse();
- CEllipse* cellipse;
-};
-
-class CEllipse : public CGenericEllipse {
-public:
- CEllipse(SPEllipse* ellipse);
- virtual ~CEllipse();
+ virtual ~SPEllipse();
virtual void build(SPDocument *document, Inkscape::XML::Node *repr);
virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags);
virtual void set(unsigned int key, gchar const* value);
virtual gchar* description();
-
-protected:
- SPEllipse* spellipse;
};
void sp_ellipse_position_set (SPEllipse * ellipse, gdouble x, gdouble y, gdouble rx, gdouble ry);
@@ -89,53 +67,31 @@ void sp_ellipse_position_set (SPEllipse * ellipse, gdouble x, gdouble y, gdouble
#define SP_CIRCLE(obj) ((SPCircle*)obj)
#define SP_IS_CIRCLE(obj) (dynamic_cast<const SPCircle*>((SPObject*)obj))
-class CCircle;
-
class SPCircle : public SPGenericEllipse {
public:
SPCircle();
- CCircle* ccircle;
-};
-
-class CCircle : public CGenericEllipse {
-public:
- CCircle(SPCircle* circle);
- virtual ~CCircle();
+ virtual ~SPCircle();
virtual void build(SPDocument *document, Inkscape::XML::Node *repr);
virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags);
virtual void set(unsigned int key, gchar const* value);
virtual gchar* description();
-
-protected:
- SPCircle* spcircle;
};
/* <path sodipodi:type="arc"> element */
#define SP_ARC(obj) ((SPArc*)obj)
#define SP_IS_ARC(obj) (dynamic_cast<const SPArc*>((SPObject*)obj))
-class CArc;
-
class SPArc : public SPGenericEllipse {
public:
SPArc();
- CArc* carc;
-};
-
-class CArc : public CGenericEllipse {
-public:
- CArc(SPArc* arc);
- virtual ~CArc();
+ virtual ~SPArc();
virtual void build(SPDocument *document, Inkscape::XML::Node *repr);
virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags);
virtual void set(unsigned int key, gchar const* value);
virtual gchar* description();
virtual void modified(unsigned int flags);
-
-protected:
- SPArc* sparc;
};
void sp_arc_position_set (SPArc * arc, gdouble x, gdouble y, gdouble rx, gdouble ry);
diff --git a/src/sp-line.cpp b/src/sp-line.cpp
index 4a14b883c..d60969baa 100644
--- a/src/sp-line.cpp
+++ b/src/sp-line.cpp
@@ -34,170 +34,144 @@ namespace {
bool lineRegistered = SPFactory::instance().registerObject("svg:line", createLine);
}
-CLine::CLine(SPLine* line) : CShape(line) {
- this->spline = line;
+SPLine::SPLine() : SPShape(), CShape(this) {
+ delete this->cshape;
+ this->cshape = this;
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
+
+ this->x1.unset();
+ this->y1.unset();
+ this->x2.unset();
+ this->y2.unset();
}
-CLine::~CLine() {
+SPLine::~SPLine() {
}
-SPLine::SPLine() : SPShape() {
- SPLine* line = this;
-
- line->cline = new CLine(line);
- line->typeHierarchy.insert(typeid(SPLine));
-
- delete line->cshape;
- line->cshape = line->cline;
- line->clpeitem = line->cline;
- line->citem = line->cline;
- line->cobject = line->cline;
-
- line->x1.unset();
- line->y1.unset();
- line->x2.unset();
- line->y2.unset();
-}
-
-void CLine::build(SPDocument * document, Inkscape::XML::Node * repr) {
- SPLine* object = this->spline;
-
+void SPLine::build(SPDocument * document, Inkscape::XML::Node * repr) {
CShape::build(document, repr);
- object->readAttr( "x1" );
- object->readAttr( "y1" );
- object->readAttr( "x2" );
- object->readAttr( "y2" );
+ this->readAttr( "x1" );
+ this->readAttr( "y1" );
+ this->readAttr( "x2" );
+ this->readAttr( "y2" );
}
-void CLine::set(unsigned int key, const gchar* value) {
- SPLine* object = this->spline;
- SPLine * line = object;
-
+void SPLine::set(unsigned int key, const gchar* value) {
/* fixme: we should really collect updates */
switch (key) {
case SP_ATTR_X1:
- line->x1.readOrUnset(value);
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->x1.readOrUnset(value);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_Y1:
- line->y1.readOrUnset(value);
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->y1.readOrUnset(value);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_X2:
- line->x2.readOrUnset(value);
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->x2.readOrUnset(value);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_Y2:
- line->y2.readOrUnset(value);
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->y2.readOrUnset(value);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
default:
CShape::set(key, value);
break;
}
}
-void CLine::update(SPCtx *ctx, guint flags) {
- SPLine* object = this->spline;
-
+void SPLine::update(SPCtx *ctx, guint flags) {
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
- SPLine *line = SP_LINE(object);
-
- SPStyle const *style = object->style;
+ SPStyle const *style = this->style;
SPItemCtx const *ictx = (SPItemCtx const *) ctx;
double const w = ictx->viewport.width();
double const h = ictx->viewport.height();
double const em = style->font_size.computed;
double const ex = em * 0.5; // fixme: get from pango or libnrtype.
- line->x1.update(em, ex, w);
- line->x2.update(em, ex, w);
- line->y1.update(em, ex, h);
- line->y2.update(em, ex, h);
- ((SPShape *) object)->setShape();
+ this->x1.update(em, ex, w);
+ this->x2.update(em, ex, w);
+ this->y1.update(em, ex, h);
+ this->y2.update(em, ex, h);
+
+ this->setShape();
}
CShape::update(ctx, flags);
}
-Inkscape::XML::Node* CLine::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPLine* object = this->spline;
- SPLine *line = object;
-
+Inkscape::XML::Node* SPLine::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
repr = xml_doc->createElement("svg:line");
}
- if (repr != object->getRepr()) {
- repr->mergeFrom(object->getRepr(), "id");
+ if (repr != this->getRepr()) {
+ repr->mergeFrom(this->getRepr(), "id");
}
- sp_repr_set_svg_double(repr, "x1", line->x1.computed);
- sp_repr_set_svg_double(repr, "y1", line->y1.computed);
- sp_repr_set_svg_double(repr, "x2", line->x2.computed);
- sp_repr_set_svg_double(repr, "y2", line->y2.computed);
+ sp_repr_set_svg_double(repr, "x1", this->x1.computed);
+ sp_repr_set_svg_double(repr, "y1", this->y1.computed);
+ sp_repr_set_svg_double(repr, "x2", this->x2.computed);
+ sp_repr_set_svg_double(repr, "y2", this->y2.computed);
CShape::write(xml_doc, repr, flags);
return repr;
}
-gchar* CLine::description() {
+gchar* SPLine::description() {
return g_strdup(_("<b>Line</b>"));
}
-void CLine::convert_to_guides() {
- SPLine* item = this->spline;
- SPLine *line = item;
-
+void SPLine::convert_to_guides() {
Geom::Point points[2];
+ Geom::Affine const i2dt(this->i2dt_affine());
- Geom::Affine const i2dt(item->i2dt_affine());
-
- points[0] = Geom::Point(line->x1.computed, line->y1.computed)*i2dt;
- points[1] = Geom::Point(line->x2.computed, line->y2.computed)*i2dt;
+ points[0] = Geom::Point(this->x1.computed, this->y1.computed)*i2dt;
+ points[1] = Geom::Point(this->x2.computed, this->y2.computed)*i2dt;
- SPGuide::createSPGuide(item->document, points[0], points[1]);
+ SPGuide::createSPGuide(this->document, points[0], points[1]);
}
-Geom::Affine CLine::set_transform(Geom::Affine const &transform) {
- SPLine* item = this->spline;
- SPLine *line = item;
-
+Geom::Affine SPLine::set_transform(Geom::Affine const &transform) {
Geom::Point points[2];
- points[0] = Geom::Point(line->x1.computed, line->y1.computed);
- points[1] = Geom::Point(line->x2.computed, line->y2.computed);
+ points[0] = Geom::Point(this->x1.computed, this->y1.computed);
+ points[1] = Geom::Point(this->x2.computed, this->y2.computed);
points[0] *= transform;
points[1] *= transform;
- line->x1.computed = points[0][Geom::X];
- line->y1.computed = points[0][Geom::Y];
- line->x2.computed = points[1][Geom::X];
- line->y2.computed = points[1][Geom::Y];
+ this->x1.computed = points[0][Geom::X];
+ this->y1.computed = points[0][Geom::Y];
+ this->x2.computed = points[1][Geom::X];
+ this->y2.computed = points[1][Geom::Y];
- item->adjust_stroke(transform.descrim());
+ this->adjust_stroke(transform.descrim());
- SP_OBJECT(item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
return Geom::identity();
}
-void CLine::set_shape() {
- SPLine* shape = this->spline;
- SPLine *line = shape;
-
+void SPLine::set_shape() {
SPCurve *c = new SPCurve();
- c->moveto(line->x1.computed, line->y1.computed);
- c->lineto(line->x2.computed, line->y2.computed);
+ c->moveto(this->x1.computed, this->y1.computed);
+ c->lineto(this->x2.computed, this->y2.computed);
- shape->setCurveInsync(c, TRUE); // *_insync does not call update, avoiding infinite recursion when set_shape is called by update
- shape->setCurveBeforeLPE(c);
+ this->setCurveInsync(c, TRUE); // *_insync does not call update, avoiding infinite recursion when set_shape is called by update
+ this->setCurveBeforeLPE(c);
// LPE's cannot be applied to lines. (the result can (generally) not be represented as SPLine)
diff --git a/src/sp-line.h b/src/sp-line.h
index 9b8bf149d..72c749f43 100644
--- a/src/sp-line.h
+++ b/src/sp-line.h
@@ -20,24 +20,15 @@
#define SP_LINE(obj) ((SPLine*)obj)
#define SP_IS_LINE(obj) (dynamic_cast<const SPLine*>((SPObject*)obj))
-class SPLine;
-class CLine;
-
-class SPLine : public SPShape {
+class SPLine : public SPShape, CShape {
public:
SPLine();
- CLine* cline;
+ virtual ~SPLine();
SVGLength x1;
SVGLength y1;
SVGLength x2;
SVGLength y2;
-};
-
-class CLine : public CShape {
-public:
- CLine(SPLine* line);
- virtual ~CLine();
virtual void build(SPDocument *document, Inkscape::XML::Node *repr);
virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags);
@@ -49,9 +40,6 @@ public:
virtual void update(SPCtx* ctx, guint flags);
virtual void set_shape();
-
-protected:
- SPLine* spline;
};
#endif // SEEN_SP_LINE_H
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<Path *>(this->originalPath)->LoadPathVector(pv);
- Geom::PathVector pv = sp_svg_read_pathv(offset->original);
- offset->originalPath = new Path;
- reinterpret_cast<Path *>(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(_("<b>Linked offset</b>, %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(_("<b>Dynamic offset</b>, %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;i<nbPart;i++) {
double partSurf=parts[i]->Surface();
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;j<onePart->nbPt;j++) theShape->AddPoint(onePart->pts[j].x);
for (int j=0;j<onePart->nbAr;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;j<onePart->nbAr;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;i<nbPart;i++) {
if ( parts[i] ) {
parts[i]->ConvertWithBackData(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;i<nbPart;i++) if ( parts[i] ) delete parts[i];
+
+ for (int i=0;i<nbPart;i++) {
+ if ( parts[i] ) {
+ delete parts[i];
+ }
+ }
} else if ( nbPart == 1 ) {
orig->Copy(parts[0]);
- for (int i=0;i<nbPart;i++) if ( parts[i] ) delete parts[i];
+
+ for (int i=0;i<nbPart;i++) {
+ if ( parts[i] ) {
+ delete parts[i];
+ }
+ }
} else {
orig->Reset();
}
@@ -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<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) {
+void SPOffset::snappoints(std::vector<Inkscape::SnapCandidatePoint> &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<SPOffset*>(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;
}
diff --git a/src/sp-offset.h b/src/sp-offset.h
index 20f5164b4..cc0be839a 100644
--- a/src/sp-offset.h
+++ b/src/sp-offset.h
@@ -16,12 +16,9 @@
#include <stddef.h>
#include <sigc++/sigc++.h>
-#define SP_TYPE_OFFSET (sp_offset_get_type ())
#define SP_OFFSET(obj) ((SPOffset*)obj)
-//#define SP_IS_OFFSET(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPOffset)))
#define SP_IS_OFFSET(obj) (dynamic_cast<const SPOffset*>((SPObject*)obj))
-class COffset;
class SPUseReference;
/**
@@ -52,13 +49,11 @@ class SPUseReference;
* points, or more precisely one control point, that's enough to define the
* radius (look in object-edit).
*/
-class SPOffset : public SPShape {
+class SPOffset : public SPShape, CShape {
public:
SPOffset();
virtual ~SPOffset();
- COffset* coffset;
-
void *originalPath; ///< will be a livarot Path, just don't declare it here to please the gcc linker
char *original; ///< SVG description of the source path
float rad; ///< offset radius
@@ -79,12 +74,6 @@ public:
sigc::connection _delete_connection;
sigc::connection _changed_connection;
sigc::connection _transformed_connection;
-};
-
-class COffset : public CShape {
-public:
- COffset(SPOffset* offset);
- ~COffset();
virtual void build(SPDocument *document, Inkscape::XML::Node *repr);
virtual void set(unsigned int key, gchar const* value);
@@ -96,9 +85,6 @@ public:
virtual gchar* description();
virtual void set_shape();
-
-protected:
- SPOffset* spoffset;
};
double sp_offset_distance_to_original (SPOffset * offset, Geom::Point px);
diff --git a/src/sp-path.cpp b/src/sp-path.cpp
index 394b815fb..06167e6dd 100644
--- a/src/sp-path.cpp
+++ b/src/sp-path.cpp
@@ -66,24 +66,26 @@ gint SPPath::nodesInPath() const
return _curve ? _curve->nodes_in_path() : 0;
}
-gchar* CPath::description() {
- SPPath* item = this->sppath;
-
- int count = SP_PATH(item)->nodesInPath();
- if (SP_IS_LPE_ITEM(item) && sp_lpe_item_has_path_effect(SP_LPE_ITEM(item))) {
-
+gchar* SPPath::description() {
+ int count = this->nodesInPath();
+
+ if (sp_lpe_item_has_path_effect(this)) {
Glib::ustring s;
-
- PathEffectList effect_list = sp_lpe_item_get_effect_list(SP_LPE_ITEM(item));
+ PathEffectList effect_list = sp_lpe_item_get_effect_list(this);
+
for (PathEffectList::iterator it = effect_list.begin(); it != effect_list.end(); ++it)
{
LivePathEffectObject *lpeobj = (*it)->lpeobject;
- if (!lpeobj || !lpeobj->get_lpe())
+
+ if (!lpeobj || !lpeobj->get_lpe()) {
break;
- if (s.empty())
+ }
+
+ if (s.empty()) {
s = lpeobj->get_lpe()->getName();
- else
+ } else {
s = s + ", " + lpeobj->get_lpe()->getName();
+ }
}
return g_strdup_printf(ngettext("<b>Path</b> (%i node, path effect: %s)",
@@ -94,19 +96,16 @@ gchar* CPath::description() {
}
}
-void CPath::convert_to_guides() {
- SPPath* item = this->sppath;
- SPPath *path = item;
-
- if (!path->_curve) {
+void SPPath::convert_to_guides() {
+ if (!this->_curve) {
return;
}
std::list<std::pair<Geom::Point, Geom::Point> > pts;
- Geom::Affine const i2dt(path->i2dt_affine());
-
- Geom::PathVector const & pv = path->_curve->get_pathvector();
+ Geom::Affine const i2dt(this->i2dt_affine());
+ Geom::PathVector const & pv = this->_curve->get_pathvector();
+
for(Geom::PathVector::const_iterator pit = pv.begin(); pit != pv.end(); ++pit) {
for(Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_default(); ++cit) {
// only add curves for straight line segments
@@ -117,121 +116,106 @@ void CPath::convert_to_guides() {
}
}
- sp_guide_pt_pairs_to_guides(item->document, pts);
+ sp_guide_pt_pairs_to_guides(this->document, pts);
}
-CPath::CPath(SPPath* path) : CShape(path) {
- this->sppath = path;
-}
-
-CPath::~CPath() {
-}
-
-SPPath::SPPath() : SPShape(), connEndPair(this) {
- SPPath* path = this;
-
- path->cpath = new CPath(path);
- path->typeHierarchy.insert(typeid(SPPath));
-
- delete path->cshape;
- path->cshape = path->cpath;
- path->clpeitem = path->cpath;
- path->citem = path->cpath;
- path->cobject = path->cpath;
+SPPath::SPPath() : SPShape(), CShape(this), connEndPair(this) {
+ delete this->cshape;
+ this->cshape = this;
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
}
SPPath::~SPPath() {
}
-void CPath::build(SPDocument *document, Inkscape::XML::Node *repr) {
- SPPath* object = this->sppath;
-
+void SPPath::build(SPDocument *document, Inkscape::XML::Node *repr) {
/* Are these calls actually necessary? */
- object->readAttr( "marker" );
- object->readAttr( "marker-start" );
- object->readAttr( "marker-mid" );
- object->readAttr( "marker-end" );
+ this->readAttr( "marker" );
+ this->readAttr( "marker-start" );
+ this->readAttr( "marker-mid" );
+ this->readAttr( "marker-end" );
- sp_conn_end_pair_build(object);
+ sp_conn_end_pair_build(this);
CShape::build(document, repr);
- object->readAttr( "inkscape:original-d" );
- object->readAttr( "d" );
+ this->readAttr( "inkscape:original-d" );
+ this->readAttr( "d" );
/* d is a required attribute */
- gchar const *d = object->getAttribute("d", NULL);
+ gchar const *d = this->getAttribute("d", NULL);
+
if (d == NULL) {
- object->setKeyValue( sp_attribute_lookup("d"), "");
+ this->setKeyValue( sp_attribute_lookup("d"), "");
}
}
-void CPath::release() {
- SPPath* object = this->sppath;
- SPPath *path = object;
-
- path->connEndPair.release();
+void SPPath::release() {
+ this->connEndPair.release();
CShape::release();
}
-
-void CPath::set(unsigned int key, const gchar* value) {
- SPPath* object = this->sppath;
- SPPath *path = (SPPath *) object;
-
+void SPPath::set(unsigned int key, const gchar* value) {
switch (key) {
case SP_ATTR_INKSCAPE_ORIGINAL_D:
- if (value) {
- Geom::PathVector pv = sp_svg_read_pathv(value);
- SPCurve *curve = new SPCurve(pv);
- if (curve) {
- path->set_original_curve(curve, TRUE, true);
- curve->unref();
- }
- } else {
- path->set_original_curve(NULL, TRUE, true);
- }
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ if (value) {
+ Geom::PathVector pv = sp_svg_read_pathv(value);
+ SPCurve *curve = new SPCurve(pv);
+
+ if (curve) {
+ this->set_original_curve(curve, TRUE, true);
+ curve->unref();
+ }
+ } else {
+ this->set_original_curve(NULL, TRUE, true);
+ }
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_D:
- if (value) {
- Geom::PathVector pv = sp_svg_read_pathv(value);
- SPCurve *curve = new SPCurve(pv);
- if (curve) {
- ((SPShape *) path)->setCurve(curve, TRUE);
- curve->unref();
- }
- } else {
- ((SPShape *) path)->setCurve(NULL, TRUE);
- }
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ if (value) {
+ Geom::PathVector pv = sp_svg_read_pathv(value);
+ SPCurve *curve = new SPCurve(pv);
+
+ if (curve) {
+ this->setCurve(curve, TRUE);
+ curve->unref();
+ }
+ } else {
+ this->setCurve(NULL, TRUE);
+ }
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_PROP_MARKER:
case SP_PROP_MARKER_START:
case SP_PROP_MARKER_MID:
case SP_PROP_MARKER_END:
- sp_shape_set_marker(object, key, value);
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ sp_shape_set_marker(this, key, value);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_CONNECTOR_TYPE:
case SP_ATTR_CONNECTOR_CURVATURE:
case SP_ATTR_CONNECTION_START:
case SP_ATTR_CONNECTION_END:
case SP_ATTR_CONNECTION_START_POINT:
case SP_ATTR_CONNECTION_END_POINT:
- path->connEndPair.setAttr(key, value);
+ this->connEndPair.setAttr(key, value);
break;
+
default:
CShape::set(key, value);
break;
}
}
-Inkscape::XML::Node* CPath::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPPath* object = this->sppath;
- SPShape *shape = (SPShape *) object;
-
+Inkscape::XML::Node* SPPath::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");
}
@@ -239,8 +223,9 @@ Inkscape::XML::Node* CPath::write(Inkscape::XML::Document *xml_doc, Inkscape::XM
#ifdef PATH_VERBOSE
g_message("sp_path_write writes 'd' attribute");
#endif
- if ( shape->_curve != NULL ) {
- gchar *str = sp_svg_write_path(shape->_curve->get_pathvector());
+
+ if ( this->_curve != NULL ) {
+ gchar *str = sp_svg_write_path(this->_curve->get_pathvector());
repr->setAttribute("d", str);
g_free(str);
} else {
@@ -248,8 +233,8 @@ g_message("sp_path_write writes 'd' attribute");
}
if (flags & SP_OBJECT_WRITE_EXT) {
- if ( shape->_curve_before_lpe != NULL ) {
- gchar *str = sp_svg_write_path(shape->_curve_before_lpe->get_pathvector());
+ if ( this->_curve_before_lpe != NULL ) {
+ gchar *str = sp_svg_write_path(this->_curve_before_lpe->get_pathvector());
repr->setAttribute("inkscape:original-d", str);
g_free(str);
} else {
@@ -257,94 +242,82 @@ g_message("sp_path_write writes 'd' attribute");
}
}
- SP_PATH(shape)->connEndPair.writeRepr(repr);
+ this->connEndPair.writeRepr(repr);
CShape::write(xml_doc, repr, flags);
return repr;
}
-void CPath::update(SPCtx *ctx, guint flags) {
- SPPath* object = this->sppath;
-
+void SPPath::update(SPCtx *ctx, guint flags) {
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
- flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore
- }
+ flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore
+ }
- CShape::update(ctx, flags);
+ CShape::update(ctx, flags);
- SPPath *path = SP_PATH(object);
- path->connEndPair.update();
+ this->connEndPair.update();
}
-
-Geom::Affine CPath::set_transform(Geom::Affine const &transform) {
- SPPath* item = this->sppath;
-
- if (!SP_IS_PATH(item)) {
+Geom::Affine SPPath::set_transform(Geom::Affine const &transform) {
+ if (!this->_curve) { // 0 nodes, nothing to transform
return Geom::identity();
}
- SPPath *path = SP_PATH(item);
- if (!path->_curve) { // 0 nodes, nothing to transform
- return Geom::identity();
- }
-
- // Transform the original-d path if this is a valid LPE item, other else the (ordinary) path
- if (path->_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(item))) {
- if (sp_lpe_item_has_path_effect_of_type(SP_LPE_ITEM(item), Inkscape::LivePathEffect::CLONE_ORIGINAL)) {
+ // Transform the original-d path if this is a valid LPE this, other else the (ordinary) path
+ if (this->_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(this)) {
+ if (sp_lpe_item_has_path_effect_of_type(this, Inkscape::LivePathEffect::CLONE_ORIGINAL)) {
// if path has the CLONE_ORIGINAL LPE applied, don't write the transform to the pathdata, but write it 'unoptimized'
return transform;
} else {
- path->_curve_before_lpe->transform(transform);
+ this->_curve_before_lpe->transform(transform);
}
} else {
- path->_curve->transform(transform);
+ this->_curve->transform(transform);
}
// Adjust stroke
- item->adjust_stroke(transform.descrim());
+ this->adjust_stroke(transform.descrim());
// Adjust pattern fill
- item->adjust_pattern(transform);
+ this->adjust_pattern(transform);
// Adjust gradient fill
- item->adjust_gradient(transform);
+ this->adjust_gradient(transform);
// Adjust LPE
- item->adjust_livepatheffect(transform);
+ this->adjust_livepatheffect(transform);
- item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
// nothing remains - we've written all of the transform, so return identity
return Geom::identity();
}
-void CPath::update_patheffect(bool write) {
- SPPath* lpeitem = this->sppath;
- SPShape * const shape = (SPShape *) lpeitem;
-
- Inkscape::XML::Node *repr = shape->getRepr();
+void SPPath::update_patheffect(bool write) {
+ Inkscape::XML::Node *repr = this->getRepr();
#ifdef PATH_VERBOSE
g_message("sp_path_update_patheffect");
#endif
- if (shape->_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(lpeitem)) {
- SPCurve *curve = shape->_curve_before_lpe->copy();
+ if (this->_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(this)) {
+ SPCurve *curve = this->_curve_before_lpe->copy();
/* if a path has an lpeitem applied, then reset the curve to the _curve_before_lpe.
* This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/
- shape->setCurveInsync(curve, TRUE);
+ this->setCurveInsync(curve, TRUE);
+
+ bool success = sp_lpe_item_perform_path_effect(this, curve);
- bool success = sp_lpe_item_perform_path_effect(SP_LPE_ITEM(shape), curve);
if (success && write) {
- // could also do shape->getRepr()->updateRepr(); but only the d attribute needs updating.
+ // could also do this->getRepr()->updateRepr(); but only the d attribute needs updating.
#ifdef PATH_VERBOSE
g_message("sp_path_update_patheffect writes 'd' attribute");
#endif
- if ( shape->_curve != NULL ) {
- gchar *str = sp_svg_write_path(shape->_curve->get_pathvector());
+
+ if ( this->_curve != NULL ) {
+ gchar *str = sp_svg_write_path(this->_curve->get_pathvector());
repr->setAttribute("d", str);
g_free(str);
} else {
@@ -355,13 +328,15 @@ g_message("sp_path_update_patheffect writes 'd' attribute");
if (gchar const * value = repr->attribute("d")) {
Geom::PathVector pv = sp_svg_read_pathv(value);
SPCurve *oldcurve = new SPCurve(pv);
+
if (oldcurve) {
- shape->setCurve(oldcurve, TRUE);
+ this->setCurve(oldcurve, TRUE);
oldcurve->unref();
}
}
}
- shape->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
curve->unref();
}
}
@@ -380,6 +355,7 @@ void SPPath::set_original_curve (SPCurve *new_curve, unsigned int owner, bool wr
if (_curve_before_lpe) {
_curve_before_lpe = _curve_before_lpe->unref();
}
+
if (new_curve) {
if (owner) {
_curve_before_lpe = new_curve->ref();
@@ -387,6 +363,7 @@ void SPPath::set_original_curve (SPCurve *new_curve, unsigned int owner, bool wr
_curve_before_lpe = new_curve->copy();
}
}
+
sp_lpe_item_update_patheffect(this, true, write);
requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
@@ -399,6 +376,7 @@ SPCurve * SPPath::get_original_curve () const
if (_curve_before_lpe) {
return _curve_before_lpe->copy();
}
+
return NULL;
}
diff --git a/src/sp-path.h b/src/sp-path.h
index a9b9e7f68..e475a3f09 100644
--- a/src/sp-path.h
+++ b/src/sp-path.h
@@ -20,7 +20,6 @@
#include "sp-conn-end-pair.h"
class SPCurve;
-class CPath;
#define SP_PATH(obj) ((SPPath*)obj)
#define SP_IS_PATH(obj) (dynamic_cast<const SPPath*>((SPObject*)obj))
@@ -28,13 +27,11 @@ class CPath;
/**
* SVG <path> implementation
*/
-class SPPath : public SPShape {
+class SPPath : public SPShape, public CShape {
public:
SPPath();
virtual ~SPPath();
- CPath* cpath;
-
gint nodesInPath() const;
// still in lowercase because the names should be clearer on whether curve, curve->copy or curve-ref is returned.
@@ -49,12 +46,6 @@ public: // should be made protected
public:
SPConnEndPair connEndPair;
-};
-
-class CPath : public CShape {
-public:
- CPath(SPPath* path);
- ~CPath();
virtual void build(SPDocument *document, Inkscape::XML::Node *repr);
virtual void release();
@@ -68,9 +59,6 @@ public:
virtual void convert_to_guides();
virtual void update_patheffect(bool write);
-
-protected:
- SPPath* sppath;
};
#endif // SEEN_SP_PATH_H
diff --git a/src/sp-polygon.cpp b/src/sp-polygon.cpp
index 8155c0767..09726703e 100644
--- a/src/sp-polygon.cpp
+++ b/src/sp-polygon.cpp
@@ -35,28 +35,19 @@ namespace {
bool polygonRegistered = SPFactory::instance().registerObject("svg:polygon", createPolygon);
}
-CPolygon::CPolygon(SPPolygon* polygon) : CShape(polygon) {
- this->sppolygon = polygon;
+SPPolygon::SPPolygon() : SPShape(), CShape(this) {
+ delete this->cshape;
+ this->cshape = this;
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
}
-CPolygon::~CPolygon() {
+SPPolygon::~SPPolygon() {
}
-SPPolygon::SPPolygon() : SPShape() {
- SPPolygon* polygon = this;
-
- polygon->cpolygon = new CPolygon(polygon);
- polygon->typeHierarchy.insert(typeid(SPPolygon));
-
- delete polygon->cshape;
- polygon->cshape = polygon->cpolygon;
- polygon->clpeitem = polygon->cpolygon;
- polygon->citem = polygon->cpolygon;
- polygon->cobject = polygon->cpolygon;
-}
-
-void CPolygon::build(SPDocument *document, Inkscape::XML::Node *repr) {
- SPPolygon* object = this->sppolygon;
+void SPPolygon::build(SPDocument *document, Inkscape::XML::Node *repr) {
+ SPPolygon* object = this;
CShape::build(document, repr);
@@ -86,19 +77,17 @@ static gchar *sp_svg_write_polygon(Geom::PathVector const & pathv)
return g_strdup(os.str().c_str());
}
-Inkscape::XML::Node* CPolygon::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPShape *shape = this->sppolygon;
-
+Inkscape::XML::Node* SPPolygon::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
// Tolerable workaround: we need to update the object's curve before we set points=
// because it's out of sync when e.g. some extension attrs of the polygon or star are changed in XML editor
- shape->setShape();
+ this->setShape();
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
repr = xml_doc->createElement("svg:polygon");
}
/* We can safely write points here, because all subclasses require it too (Lauris) */
- gchar *str = sp_svg_write_polygon(shape->_curve->get_pathvector());
+ gchar *str = sp_svg_write_polygon(this->_curve->get_pathvector());
repr->setAttribute("points", str);
g_free(str);
@@ -120,17 +109,17 @@ static gboolean polygon_get_value(gchar const **p, gdouble *v)
gchar *e = NULL;
*v = g_ascii_strtod(*p, &e);
+
if (e == *p) {
return false;
}
*p = e;
+
return true;
}
-void CPolygon::set(unsigned int key, const gchar* value) {
- SPPolygon *polygon = this->sppolygon;
-
+void SPPolygon::set(unsigned int key, const gchar* value) {
switch (key) {
case SP_ATTR_POINTS: {
if (!value) {
@@ -138,6 +127,7 @@ void CPolygon::set(unsigned int key, const gchar* value) {
* http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing. */
break;
}
+
SPCurve *curve = new SPCurve();
gboolean hascpt = FALSE;
@@ -146,11 +136,13 @@ void CPolygon::set(unsigned int key, const gchar* value) {
while (TRUE) {
gdouble x;
+
if (!polygon_get_value(&cptr, &x)) {
break;
}
gdouble y;
+
if (!polygon_get_value(&cptr, &y)) {
/* fixme: It is an error for an odd number of points to be specified. We
* should display the points up to now (as we currently do, though perhaps
@@ -180,7 +172,8 @@ void CPolygon::set(unsigned int key, const gchar* value) {
* a single-point polygon in SPCurve. TODO: add a testcase with only one coordinate pair */
curve->closepath();
}
- (SP_SHAPE(polygon))->setCurve(curve, TRUE);
+
+ this->setCurve(curve, TRUE);
curve->unref();
break;
}
@@ -190,7 +183,7 @@ void CPolygon::set(unsigned int key, const gchar* value) {
}
}
-gchar* CPolygon::description() {
+gchar* SPPolygon::description() {
return g_strdup(_("<b>Polygon</b>"));
}
diff --git a/src/sp-polygon.h b/src/sp-polygon.h
index 7a95f5364..df414eda8 100644
--- a/src/sp-polygon.h
+++ b/src/sp-polygon.h
@@ -19,26 +19,15 @@
#define SP_POLYGON(obj) ((SPPolygon*)obj)
#define SP_IS_POLYGON(obj) (dynamic_cast<const SPPolygon*>((SPObject*)obj))
-class CPolygon;
-
-class SPPolygon : public SPShape {
+class SPPolygon : public SPShape, public CShape {
public:
SPPolygon();
- CPolygon* cpolygon;
-};
-
-class CPolygon : public CShape {
-public:
- CPolygon(SPPolygon* polygon);
- virtual ~CPolygon();
+ virtual ~SPPolygon();
virtual void build(SPDocument *document, Inkscape::XML::Node *repr);
virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags);
virtual void set(unsigned int key, gchar const* value);
virtual gchar* description();
-
-protected:
- SPPolygon* sppolygon;
};
// made 'public' so that SPCurve can set it as friend:
diff --git a/src/sp-polyline.cpp b/src/sp-polyline.cpp
index 310fd9db8..c97b96b73 100644
--- a/src/sp-polyline.cpp
+++ b/src/sp-polyline.cpp
@@ -30,38 +30,24 @@ namespace {
bool polyLineRegistered = SPFactory::instance().registerObject("svg:polyline", createPolyLine);
}
-CPolyLine::CPolyLine(SPPolyLine* polyline) : CShape(polyline) {
- this->sppolyline = polyline;
+SPPolyLine::SPPolyLine() : SPShape(), CShape(this) {
+ delete this->cshape;
+ this->cshape = this;
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
}
-CPolyLine::~CPolyLine() {
+SPPolyLine::~SPPolyLine() {
}
-SPPolyLine::SPPolyLine() : SPShape() {
- SPPolyLine* polyline = this;
-
- polyline->cpolyline = new CPolyLine(polyline);
- polyline->typeHierarchy.insert(typeid(SPPolyLine));
-
- delete polyline->cshape;
- polyline->cshape = polyline->cpolyline;
- polyline->clpeitem = polyline->cpolyline;
- polyline->citem = polyline->cpolyline;
- polyline->cobject = polyline->cpolyline;
-}
-
-void CPolyLine::build(SPDocument * document, Inkscape::XML::Node * repr) {
- SPPolyLine* object = this->sppolyline;
-
+void SPPolyLine::build(SPDocument * document, Inkscape::XML::Node * repr) {
CShape::build(document, repr);
- object->readAttr( "points" );
+ this->readAttr("points");
}
-void CPolyLine::set(unsigned int key, const gchar* value) {
- SPPolyLine* object = this->sppolyline;
- SPPolyLine *polyline = object;
-
+void SPPolyLine::set(unsigned int key, const gchar* value) {
switch (key) {
case SP_ATTR_POINTS: {
SPCurve * curve;
@@ -69,7 +55,10 @@ void CPolyLine::set(unsigned int key, const gchar* value) {
char * eptr;
gboolean hascpt;
- if (!value) break;
+ if (!value) {
+ break;
+ }
+
curve = new SPCurve ();
hascpt = FALSE;
@@ -82,20 +71,35 @@ void CPolyLine::set(unsigned int key, const gchar* value) {
while (*cptr != '\0' && (*cptr == ',' || *cptr == '\x20' || *cptr == '\x9' || *cptr == '\xD' || *cptr == '\xA')) {
cptr++;
}
- if (!*cptr) break;
+
+ if (!*cptr) {
+ break;
+ }
x = g_ascii_strtod (cptr, &eptr);
- if (eptr == cptr) break;
+
+ if (eptr == cptr) {
+ break;
+ }
+
cptr = eptr;
while (*cptr != '\0' && (*cptr == ',' || *cptr == '\x20' || *cptr == '\x9' || *cptr == '\xD' || *cptr == '\xA')) {
cptr++;
}
- if (!*cptr) break;
+
+ if (!*cptr) {
+ break;
+ }
y = g_ascii_strtod (cptr, &eptr);
- if (eptr == cptr) break;
+
+ if (eptr == cptr) {
+ break;
+ }
+
cptr = eptr;
+
if (hascpt) {
curve->lineto(x, y);
} else {
@@ -104,7 +108,7 @@ void CPolyLine::set(unsigned int key, const gchar* value) {
}
}
- (SP_SHAPE (polyline))->setCurve (curve, TRUE);
+ this->setCurve(curve, TRUE);
curve->unref();
break;
}
@@ -114,15 +118,13 @@ void CPolyLine::set(unsigned int key, const gchar* value) {
}
}
-Inkscape::XML::Node* CPolyLine::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPPolyLine* object = this->sppolyline;
-
+Inkscape::XML::Node* SPPolyLine::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
repr = xml_doc->createElement("svg:polyline");
}
- if (repr != object->getRepr()) {
- repr->mergeFrom(object->getRepr(), "id");
+ if (repr != this->getRepr()) {
+ repr->mergeFrom(this->getRepr(), "id");
}
CShape::write(xml_doc, repr, flags);
@@ -130,7 +132,7 @@ Inkscape::XML::Node* CPolyLine::write(Inkscape::XML::Document *xml_doc, Inkscape
return repr;
}
-gchar* CPolyLine::description() {
+gchar* SPPolyLine::description() {
return g_strdup(_("<b>Polyline</b>"));
}
diff --git a/src/sp-polyline.h b/src/sp-polyline.h
index 994ee18b1..66570d881 100644
--- a/src/sp-polyline.h
+++ b/src/sp-polyline.h
@@ -6,29 +6,16 @@
#define SP_POLYLINE(obj) ((SPPolyLine*)obj)
#define SP_IS_POLYLINE(obj) (dynamic_cast<const SPPolyLine*>((SPObject*)obj))
-class SPPolyLine;
-class CPolyLine;
-
-class SPPolyLine : public SPShape {
+class SPPolyLine : public SPShape, public CShape {
public:
SPPolyLine();
-
- CPolyLine* cpolyline;
-};
-
-class CPolyLine : public CShape {
-public:
- CPolyLine(SPPolyLine* polyline);
- virtual ~CPolyLine();
+ virtual ~SPPolyLine();
virtual void build(SPDocument* doc, Inkscape::XML::Node* repr);
virtual void set(unsigned int key, gchar const* value);
virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags);
virtual gchar* description();
-
-protected:
- SPPolyLine* sppolyline;
};
#endif // SEEN_SP_POLYLINE_H
diff --git a/src/sp-star.cpp b/src/sp-star.cpp
index b6a6132a4..8414c6d9a 100644
--- a/src/sp-star.cpp
+++ b/src/sp-star.cpp
@@ -42,80 +42,65 @@ namespace {
bool starRegistered = SPFactory::instance().registerObject("star", createStar);
}
-CStar::CStar(SPStar* star) : CPolygon(star) {
- this->spstar = star;
-}
-
-CStar::~CStar() {
-}
-
SPStar::SPStar() : SPPolygon() {
- SPStar* star = this;
-
- star->cstar = new CStar(star);
- star->typeHierarchy.insert(typeid(SPStar));
-
- delete star->cpolygon;
- star->cpolygon = star->cstar;
- star->cshape = star->cstar;
- star->clpeitem = star->cstar;
- star->citem = star->cstar;
- star->cobject = star->cstar;
-
- star->sides = 5;
- star->center = Geom::Point(0, 0);
- star->r[0] = 1.0;
- star->r[1] = 0.001;
- star->arg[0] = star->arg[1] = 0.0;
- star->flatsided = 0;
- star->rounded = 0.0;
- star->randomized = 0.0;
+ this->cshape = this;
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
+
+ this->sides = 5;
+ this->center = Geom::Point(0, 0);
+ this->r[0] = 1.0;
+ this->r[1] = 0.001;
+ this->arg[0] = this->arg[1] = 0.0;
+ this->flatsided = 0;
+ this->rounded = 0.0;
+ this->randomized = 0.0;
}
-void CStar::build(SPDocument * document, Inkscape::XML::Node * repr) {
- SPStar* object = this->spstar;
+SPStar::~SPStar() {
+}
+void SPStar::build(SPDocument * document, Inkscape::XML::Node * repr) {
// CPPIFY: see header file
CShape::build(document, repr);
- object->readAttr( "sodipodi:cx" );
- object->readAttr( "sodipodi:cy" );
- object->readAttr( "sodipodi:sides" );
- object->readAttr( "sodipodi:r1" );
- object->readAttr( "sodipodi:r2" );
- object->readAttr( "sodipodi:arg1" );
- object->readAttr( "sodipodi:arg2" );
- object->readAttr( "inkscape:flatsided" );
- object->readAttr( "inkscape:rounded" );
- object->readAttr( "inkscape:randomized" );
+ this->readAttr( "sodipodi:cx" );
+ this->readAttr( "sodipodi:cy" );
+ this->readAttr( "sodipodi:sides" );
+ this->readAttr( "sodipodi:r1" );
+ this->readAttr( "sodipodi:r2" );
+ this->readAttr( "sodipodi:arg1" );
+ this->readAttr( "sodipodi:arg2" );
+ this->readAttr( "inkscape:flatsided" );
+ this->readAttr( "inkscape:rounded" );
+ this->readAttr( "inkscape:randomized" );
}
-Inkscape::XML::Node* CStar::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPStar* object = this->spstar;
- SPStar *star = object;
-
+Inkscape::XML::Node* SPStar::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");
}
if (flags & SP_OBJECT_WRITE_EXT) {
repr->setAttribute("sodipodi:type", "star");
- sp_repr_set_int (repr, "sodipodi:sides", star->sides);
- sp_repr_set_svg_double(repr, "sodipodi:cx", star->center[Geom::X]);
- sp_repr_set_svg_double(repr, "sodipodi:cy", star->center[Geom::Y]);
- sp_repr_set_svg_double(repr, "sodipodi:r1", star->r[0]);
- sp_repr_set_svg_double(repr, "sodipodi:r2", star->r[1]);
- sp_repr_set_svg_double(repr, "sodipodi:arg1", star->arg[0]);
- sp_repr_set_svg_double(repr, "sodipodi:arg2", star->arg[1]);
- sp_repr_set_boolean (repr, "inkscape:flatsided", star->flatsided);
- sp_repr_set_svg_double(repr, "inkscape:rounded", star->rounded);
- sp_repr_set_svg_double(repr, "inkscape:randomized", star->randomized);
+ sp_repr_set_int (repr, "sodipodi:sides", this->sides);
+ sp_repr_set_svg_double(repr, "sodipodi:cx", this->center[Geom::X]);
+ sp_repr_set_svg_double(repr, "sodipodi:cy", this->center[Geom::Y]);
+ sp_repr_set_svg_double(repr, "sodipodi:r1", this->r[0]);
+ sp_repr_set_svg_double(repr, "sodipodi:r2", this->r[1]);
+ sp_repr_set_svg_double(repr, "sodipodi:arg1", this->arg[0]);
+ sp_repr_set_svg_double(repr, "sodipodi:arg2", this->arg[1]);
+ sp_repr_set_boolean (repr, "inkscape:flatsided", this->flatsided);
+ sp_repr_set_svg_double(repr, "inkscape:rounded", this->rounded);
+ sp_repr_set_svg_double(repr, "inkscape:randomized", this->randomized);
}
this->set_shape();
- char *d = sp_svg_write_path (star->_curve->get_pathvector());
+
+ char *d = sp_svg_write_path (this->_curve->get_pathvector());
repr->setAttribute("d", d);
- g_free (d);
+ g_free(d);
// CPPIFY: see header file
CShape::write(xml_doc, repr, flags);
@@ -123,98 +108,117 @@ Inkscape::XML::Node* CStar::write(Inkscape::XML::Document *xml_doc, Inkscape::XM
return repr;
}
-void CStar::set(unsigned int key, const gchar* value) {
- SPStar* object = this->spstar;
- SPStar *star = object;
-
+void SPStar::set(unsigned int key, const gchar* value) {
SVGLength::Unit unit;
/* fixme: we should really collect updates */
switch (key) {
case SP_ATTR_SODIPODI_SIDES:
if (value) {
- star->sides = atoi (value);
- star->sides = CLAMP(star->sides, 3, 1024);
+ this->sides = atoi (value);
+ this->sides = CLAMP(this->sides, 3, 1024);
} else {
- star->sides = 5;
+ this->sides = 5;
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_SODIPODI_CX:
- if (!sp_svg_length_read_ldd (value, &unit, NULL, &star->center[Geom::X]) ||
+ if (!sp_svg_length_read_ldd (value, &unit, NULL, &this->center[Geom::X]) ||
(unit == SVGLength::EM) ||
(unit == SVGLength::EX) ||
(unit == SVGLength::PERCENT)) {
- star->center[Geom::X] = 0.0;
+ this->center[Geom::X] = 0.0;
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_SODIPODI_CY:
- if (!sp_svg_length_read_ldd (value, &unit, NULL, &star->center[Geom::Y]) ||
+ if (!sp_svg_length_read_ldd (value, &unit, NULL, &this->center[Geom::Y]) ||
(unit == SVGLength::EM) ||
(unit == SVGLength::EX) ||
(unit == SVGLength::PERCENT)) {
- star->center[Geom::Y] = 0.0;
+ this->center[Geom::Y] = 0.0;
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_SODIPODI_R1:
- if (!sp_svg_length_read_ldd (value, &unit, NULL, &star->r[0]) ||
+ if (!sp_svg_length_read_ldd (value, &unit, NULL, &this->r[0]) ||
(unit == SVGLength::EM) ||
(unit == SVGLength::EX) ||
(unit == SVGLength::PERCENT)) {
- star->r[0] = 1.0;
+ this->r[0] = 1.0;
}
+
/* fixme: Need CLAMP (Lauris) */
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_SODIPODI_R2:
- if (!sp_svg_length_read_ldd (value, &unit, NULL, &star->r[1]) ||
+ if (!sp_svg_length_read_ldd (value, &unit, NULL, &this->r[1]) ||
(unit == SVGLength::EM) ||
(unit == SVGLength::EX) ||
(unit == SVGLength::PERCENT)) {
- star->r[1] = 0.0;
+ this->r[1] = 0.0;
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
return;
+
case SP_ATTR_SODIPODI_ARG1:
if (value) {
- star->arg[0] = g_ascii_strtod (value, NULL);
+ this->arg[0] = g_ascii_strtod (value, NULL);
} else {
- star->arg[0] = 0.0;
+ this->arg[0] = 0.0;
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_SODIPODI_ARG2:
if (value) {
- star->arg[1] = g_ascii_strtod (value, NULL);
+ this->arg[1] = g_ascii_strtod (value, NULL);
} else {
- star->arg[1] = 0.0;
+ this->arg[1] = 0.0;
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_INKSCAPE_FLATSIDED:
- if (value && !strcmp (value, "true"))
- star->flatsided = true;
- else star->flatsided = false;
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ if (value && !strcmp(value, "true")) {
+ this->flatsided = true;
+ } else {
+ this->flatsided = false;
+ }
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_INKSCAPE_ROUNDED:
if (value) {
- star->rounded = g_ascii_strtod (value, NULL);
+ this->rounded = g_ascii_strtod (value, NULL);
} else {
- star->rounded = 0.0;
+ this->rounded = 0.0;
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_INKSCAPE_RANDOMIZED:
if (value) {
- star->randomized = g_ascii_strtod (value, NULL);
+ this->randomized = g_ascii_strtod (value, NULL);
} else {
- star->randomized = 0.0;
+ this->randomized = 0.0;
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
default:
// CPPIFY: see header file
CShape::set(key, value);
@@ -222,29 +226,26 @@ void CStar::set(unsigned int key, const gchar* value) {
}
}
-void CStar::update(SPCtx *ctx, guint flags) {
- SPStar* object = this->spstar;
-
+void SPStar::update(SPCtx *ctx, guint flags) {
if (flags & (SP_OBJECT_MODIFIED_FLAG |
SP_OBJECT_STYLE_MODIFIED_FLAG |
SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
- ((SPShape *) object)->setShape ();
+
+ this->setShape();
}
// CPPIFY: see header file
CShape::update(ctx, flags);
}
-void CStar::update_patheffect(bool write) {
- SPStar* lpeitem = this->spstar;
- SPShape *shape = (SPShape *) lpeitem;
-
+void SPStar::update_patheffect(bool write) {
this->set_shape();
if (write) {
- Inkscape::XML::Node *repr = shape->getRepr();
- if ( shape->_curve != NULL ) {
- gchar *str = sp_svg_write_path(shape->_curve->get_pathvector());
+ Inkscape::XML::Node *repr = this->getRepr();
+
+ if ( this->_curve != NULL ) {
+ gchar *str = sp_svg_write_path(this->_curve->get_pathvector());
repr->setAttribute("d", str);
g_free(str);
} else {
@@ -252,23 +253,22 @@ void CStar::update_patheffect(bool write) {
}
}
- ((SPObject *)shape)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
-gchar* CStar::description() {
- SPStar *star = this->spstar;
-
+gchar* SPStar::description() {
// while there will never be less than 3 vertices, we still need to
// make calls to ngettext because the pluralization may be different
// for various numbers >=3. The singular form is used as the index.
- if (star->flatsided == false )
- return g_strdup_printf (ngettext("<b>Star</b> with %d vertex",
+ if (this->flatsided == false) {
+ return g_strdup_printf (ngettext("<b>Star</b> with %d vertex",
"<b>Star</b> with %d vertices",
- star->sides), star->sides);
- else
+ this->sides), this->sides);
+ } else {
return g_strdup_printf (ngettext("<b>Polygon</b> with %d vertex",
"<b>Polygon</b> with %d vertices",
- star->sides), star->sides);
+ this->sides), this->sides);
+ }
}
/**
@@ -380,100 +380,104 @@ sp_star_get_curvepoint (SPStar *star, SPStarPoint point, gint index, bool previ)
#define NEXT false
#define PREV true
-void CStar::set_shape() {
- SPStar* shape = this->spstar;
- SPStar *star = shape;
-
+void SPStar::set_shape() {
// perhaps we should convert all our shapes into LPEs without source path
// and with knotholders for parameters, then this situation will be handled automatically
// by disabling the entire stack (including the shape LPE)
- if (sp_lpe_item_has_broken_path_effect(SP_LPE_ITEM(shape))) {
+ if (sp_lpe_item_has_broken_path_effect(SP_LPE_ITEM(this))) {
g_warning ("The star shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as star will remove the bad LPE");
- if (shape->getRepr()->attribute("d")) {
+
+ if (this->getRepr()->attribute("d")) {
// unconditionally read the curve from d, if any, to preserve appearance
- Geom::PathVector pv = sp_svg_read_pathv(shape->getRepr()->attribute("d"));
+ Geom::PathVector pv = sp_svg_read_pathv(this->getRepr()->attribute("d"));
SPCurve *cold = new SPCurve(pv);
- shape->setCurveInsync( cold, TRUE);
- shape->setCurveBeforeLPE(cold);
+ this->setCurveInsync( cold, TRUE);
+ this->setCurveBeforeLPE(cold);
cold->unref();
}
+
return;
}
SPCurve *c = new SPCurve ();
- gint sides = star->sides;
- bool not_rounded = (fabs (star->rounded) < 1e-4);
+ gint sides = this->sides;
+ bool not_rounded = (fabs (this->rounded) < 1e-4);
// note that we pass randomized=true to sp_star_get_xy, because the curve must be randomized;
// other places that call that function (e.g. the knotholder) need the exact point
// draw 1st segment
- c->moveto(sp_star_get_xy (star, SP_STAR_POINT_KNOT1, 0, true));
- if (star->flatsided == false) {
+ c->moveto(sp_star_get_xy (this, SP_STAR_POINT_KNOT1, 0, true));
+
+ if (this->flatsided == false) {
if (not_rounded) {
- c->lineto(sp_star_get_xy (star, SP_STAR_POINT_KNOT2, 0, true));
+ c->lineto(sp_star_get_xy (this, SP_STAR_POINT_KNOT2, 0, true));
} else {
- c->curveto(sp_star_get_curvepoint (star, SP_STAR_POINT_KNOT1, 0, NEXT),
- sp_star_get_curvepoint (star, SP_STAR_POINT_KNOT2, 0, PREV),
- sp_star_get_xy (star, SP_STAR_POINT_KNOT2, 0, true));
+ c->curveto(sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, 0, NEXT),
+ sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT2, 0, PREV),
+ sp_star_get_xy (this, SP_STAR_POINT_KNOT2, 0, true));
}
}
// draw all middle segments
for (gint i = 1; i < sides; i++) {
if (not_rounded) {
- c->lineto(sp_star_get_xy (star, SP_STAR_POINT_KNOT1, i, true));
+ c->lineto(sp_star_get_xy (this, SP_STAR_POINT_KNOT1, i, true));
} else {
- if (star->flatsided == false) {
- c->curveto(sp_star_get_curvepoint (star, SP_STAR_POINT_KNOT2, i - 1, NEXT),
- sp_star_get_curvepoint (star, SP_STAR_POINT_KNOT1, i, PREV),
- sp_star_get_xy (star, SP_STAR_POINT_KNOT1, i, true));
+ if (this->flatsided == false) {
+ c->curveto(sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT2, i - 1, NEXT),
+ sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, i, PREV),
+ sp_star_get_xy (this, SP_STAR_POINT_KNOT1, i, true));
} else {
- c->curveto(sp_star_get_curvepoint (star, SP_STAR_POINT_KNOT1, i - 1, NEXT),
- sp_star_get_curvepoint (star, SP_STAR_POINT_KNOT1, i, PREV),
- sp_star_get_xy (star, SP_STAR_POINT_KNOT1, i, true));
+ c->curveto(sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, i - 1, NEXT),
+ sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, i, PREV),
+ sp_star_get_xy (this, SP_STAR_POINT_KNOT1, i, true));
}
}
- if (star->flatsided == false) {
+ if (this->flatsided == false) {
if (not_rounded) {
- c->lineto(sp_star_get_xy (star, SP_STAR_POINT_KNOT2, i, true));
+ c->lineto(sp_star_get_xy (this, SP_STAR_POINT_KNOT2, i, true));
} else {
- c->curveto(sp_star_get_curvepoint (star, SP_STAR_POINT_KNOT1, i, NEXT),
- sp_star_get_curvepoint (star, SP_STAR_POINT_KNOT2, i, PREV),
- sp_star_get_xy (star, SP_STAR_POINT_KNOT2, i, true));
+ c->curveto(sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, i, NEXT),
+ sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT2, i, PREV),
+ sp_star_get_xy (this, SP_STAR_POINT_KNOT2, i, true));
}
}
}
// draw last segment
- if (!not_rounded) {
- if (star->flatsided == false) {
- c->curveto(sp_star_get_curvepoint (star, SP_STAR_POINT_KNOT2, sides - 1, NEXT),
- sp_star_get_curvepoint (star, SP_STAR_POINT_KNOT1, 0, PREV),
- sp_star_get_xy (star, SP_STAR_POINT_KNOT1, 0, true));
- } else {
- c->curveto(sp_star_get_curvepoint (star, SP_STAR_POINT_KNOT1, sides - 1, NEXT),
- sp_star_get_curvepoint (star, SP_STAR_POINT_KNOT1, 0, PREV),
- sp_star_get_xy (star, SP_STAR_POINT_KNOT1, 0, true));
- }
- }
+ if (!not_rounded) {
+ if (this->flatsided == false) {
+ c->curveto(sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT2, sides - 1, NEXT),
+ sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, 0, PREV),
+ sp_star_get_xy (this, SP_STAR_POINT_KNOT1, 0, true));
+ } else {
+ c->curveto(sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, sides - 1, NEXT),
+ sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, 0, PREV),
+ sp_star_get_xy (this, SP_STAR_POINT_KNOT1, 0, true));
+ }
+ }
c->closepath();
/* Reset the shape'scurve to the "original_curve"
* This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/
- shape->setCurveInsync( c, TRUE);
- shape->setCurveBeforeLPE( c );
- if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(shape)) && sp_lpe_item_path_effects_enabled(SP_LPE_ITEM(shape))) {
+ this->setCurveInsync( c, TRUE);
+ this->setCurveBeforeLPE( c );
+
+ if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(this)) && sp_lpe_item_path_effects_enabled(SP_LPE_ITEM(this))) {
SPCurve *c_lpe = c->copy();
- bool success = sp_lpe_item_perform_path_effect(SP_LPE_ITEM (shape), c_lpe);
+ bool success = sp_lpe_item_perform_path_effect(SP_LPE_ITEM (this), c_lpe);
+
if (success) {
- shape->setCurveInsync( c_lpe, TRUE);
+ this->setCurveInsync( c_lpe, TRUE);
}
+
c_lpe->unref();
}
+
c->unref();
}
@@ -486,11 +490,13 @@ sp_star_position_set (SPStar *star, gint sides, Geom::Point center, gdouble r1,
star->sides = CLAMP(sides, 3, 1024);
star->center = center;
star->r[0] = MAX (r1, 0.001);
+
if (isflat == false) {
star->r[1] = CLAMP(r2, 0.0, star->r[0]);
} else {
star->r[1] = CLAMP( r1*cos(M_PI/sides) ,0.0, star->r[0] );
}
+
star->arg[0] = arg1;
star->arg[1] = arg2;
star->flatsided = isflat;
@@ -499,9 +505,7 @@ sp_star_position_set (SPStar *star, gint sides, Geom::Point center, gdouble r1,
star->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
-void CStar::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) {
- SPStar* item = this->spstar;
-
+void SPStar::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) {
// We will determine the star's midpoint ourselves, instead of trusting on the base class
// Therefore snapping to object midpoints is temporarily disabled
Inkscape::SnapPreferences local_snapprefs = *snapprefs;
@@ -511,8 +515,8 @@ void CStar::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::S
CShape::snappoints(p, &local_snapprefs);
if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) {
- Geom::Affine const i2dt (item->i2dt_affine ());
- p.push_back(Inkscape::SnapCandidatePoint(SP_STAR(item)->center * i2dt,Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT));
+ Geom::Affine const i2dt (this->i2dt_affine ());
+ p.push_back(Inkscape::SnapCandidatePoint(this->center * i2dt,Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT));
}
}
@@ -526,7 +530,6 @@ void CStar::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::S
*
* Initial item coordinate system is same as document coordinate system.
*/
-
Geom::Point
sp_star_get_xy (SPStar const *star, SPStarPoint point, gint index, bool randomized)
{
diff --git a/src/sp-star.h b/src/sp-star.h
index 3e787beb3..48f17f161 100644
--- a/src/sp-star.h
+++ b/src/sp-star.h
@@ -20,7 +20,6 @@
#define SP_STAR(obj) ((SPStar*)obj)
#define SP_IS_STAR(obj) (dynamic_cast<const SPStar*>((SPObject*)obj))
-class CStar;
typedef enum {
SP_STAR_POINT_KNOT1,
SP_STAR_POINT_KNOT2
@@ -29,7 +28,7 @@ typedef enum {
class SPStar : public SPPolygon {
public:
SPStar();
- CStar* cstar;
+ virtual ~SPStar();
gint sides;
@@ -40,16 +39,11 @@ public:
double rounded;
double randomized;
-};
// CPPIFY: This derivation is a bit weird.
// parent_class = reinterpret_cast<SPShapeClass *>(g_type_class_ref(SP_TYPE_SHAPE));
// So shouldn't star be derived from shape instead of polygon?
// What does polygon have that shape doesn't?
-class CStar : public CPolygon {
-public:
- CStar(SPStar* star);
- virtual ~CStar();
virtual void build(SPDocument *document, Inkscape::XML::Node *repr);
virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags);
@@ -61,9 +55,6 @@ public:
virtual void update_patheffect(bool write);
virtual void set_shape();
-
-protected:
- SPStar* spstar;
};
void sp_star_position_set (SPStar *star, gint sides, Geom::Point center, gdouble r1, gdouble r2, gdouble arg1, gdouble arg2, bool isflat, double rounded, double randomized);