diff --git a/src/sp-polygon.cpp b/src/sp-polygon.cpp
index 88b155e8e6761060069d3990c3476b983085b23f..1067da72e7613ea1a6cab95d24f5a89afd6866d8 100644 (file)
--- a/src/sp-polygon.cpp
+++ b/src/sp-polygon.cpp
-#define __SP_POLYGON_C__
-
/*
* SVG <polygon> implementation
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
+ * Abhishek Sharma
*
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
#include "sp-polygon.h"
#include "display/curve.h"
#include <glibmm/i18n.h>
-#include "libnr/n-art-bpath.h"
+#include <2geom/pathvector.h>
+#include <2geom/bezier-curve.h>
+#include <2geom/hvlinesegment.h>
+#include "helper/geom-curves.h"
#include "svg/stringstream.h"
#include "xml/repr.h"
#include "document.h"
@@ -81,33 +83,27 @@ static void sp_polygon_build(SPObject *object, SPDocument *document, Inkscape::X
((SPObjectClass *) parent_class)->build(object, document, repr);
}
- sp_object_read_attr(object, "points");
+ object->readAttr( "points" );
}
/*
* sp_svg_write_polygon: Write points attribute for polygon tag.
- * @bpath:
- *
+ * pathv may only contain paths with only straight line segments
* Return value: points attribute string.
*/
-static gchar *sp_svg_write_polygon(const NArtBpath *bpath)
+static gchar *sp_svg_write_polygon(Geom::PathVector const & pathv)
{
- g_return_val_if_fail(bpath != NULL, NULL);
-
Inkscape::SVGOStringStream os;
- for (int i = 0; bpath[i].code != NR_END; i++) {
- switch (bpath [i].code) {
- case NR_LINETO:
- case NR_MOVETO:
- case NR_MOVETO_OPEN:
- os << bpath [i].x3 << "," << bpath [i].y3 << " ";
- break;
-
- case NR_CURVETO:
- default:
- g_assert_not_reached();
+ for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit) {
+ for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_default(); ++cit) {
+ if ( is_straight_curve(*cit) )
+ {
+ os << cit->finalPoint()[0] << "," << cit->finalPoint()[1] << " ";
+ } else {
+ g_error("sp_svg_write_polygon: polygon path contains non-straight line segments");
+ }
}
}
@@ -119,15 +115,14 @@ static Inkscape::XML::Node *sp_polygon_write(SPObject *object, Inkscape::XML::Do
SPShape *shape = SP_SHAPE(object);
// 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
- sp_shape_set_shape(shape);
+ shape->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) */
- NArtBpath const * abp = shape->curve->get_bpath();
- gchar *str = sp_svg_write_polygon(abp);
+ gchar *str = sp_svg_write_polygon(shape->curve->get_pathvector());
repr->setAttribute("points", str);
g_free(str);
* a single-point polygon in SPCurve. TODO: add a testcase with only one coordinate pair */
curve->closepath();
}
- sp_shape_set_curve(SP_SHAPE(polygon), curve, TRUE);
+ (SP_SHAPE(polygon))->setCurve(curve, TRUE);
curve->unref();
break;
}