summaryrefslogtreecommitdiffstats
path: root/src/sp-polygon.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2013-09-19 22:33:11 +0000
committerJabiertxof <jtx@jtx.marker.es>2013-09-19 22:33:11 +0000
commit4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7 (patch)
treecaeb924426bcc861badc6fa81318b67460b26d47 /src/sp-polygon.cpp
parentUpdate to trunk (diff)
parentupdates for cmake (diff)
downloadinkscape-4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7.tar.gz
inkscape-4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7.zip
Update to trunk
(bzr r11950.1.141)
Diffstat (limited to 'src/sp-polygon.cpp')
-rw-r--r--src/sp-polygon.cpp71
1 files changed, 28 insertions, 43 deletions
diff --git a/src/sp-polygon.cpp b/src/sp-polygon.cpp
index 94000cc9d..983a738ce 100644
--- a/src/sp-polygon.cpp
+++ b/src/sp-polygon.cpp
@@ -25,40 +25,30 @@
#include "xml/repr.h"
#include "document.h"
-static void sp_polygon_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
-static Inkscape::XML::Node *sp_polygon_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
+#include "sp-factory.h"
-static gchar *sp_polygon_description(SPItem *item);
+namespace {
+ SPObject* createPolygon() {
+ return new SPPolygon();
+ }
-G_DEFINE_TYPE(SPPolygon, sp_polygon, SP_TYPE_SHAPE);
-
-static void sp_polygon_class_init(SPPolygonClass *pc)
-{
- SPObjectClass *sp_object_class = (SPObjectClass *) pc;
- SPItemClass *item_class = (SPItemClass *) pc;
-
- sp_object_class->build = sp_polygon_build;
- sp_object_class->write = sp_polygon_write;
- sp_object_class->set = sp_polygon_set;
+ bool polygonRegistered = SPFactory::instance().registerObject("svg:polygon", createPolygon);
+}
- item_class->description = sp_polygon_description;
+SPPolygon::SPPolygon() : SPShape() {
}
-static void sp_polygon_init(SPPolygon */*polygon*/)
-{
- /* Nothing here */
+SPPolygon::~SPPolygon() {
}
-static void sp_polygon_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
-{
- if (((SPObjectClass *) sp_polygon_parent_class)->build) {
- ((SPObjectClass *) sp_polygon_parent_class)->build(object, document, repr);
- }
+void SPPolygon::build(SPDocument *document, Inkscape::XML::Node *repr) {
+ SPPolygon* object = this;
+
+ SPShape::build(document, repr);
object->readAttr( "points" );
}
-
/*
* sp_svg_write_polygon: Write points attribute for polygon tag.
* pathv may only contain paths with only straight line segments
@@ -82,25 +72,21 @@ static gchar *sp_svg_write_polygon(Geom::PathVector const & pathv)
return g_strdup(os.str().c_str());
}
-static Inkscape::XML::Node *sp_polygon_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
-{
- SPShape *shape = SP_SHAPE(object);
+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->set_shape();
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);
- if (((SPObjectClass *) (sp_polygon_parent_class))->write) {
- ((SPObjectClass *) (sp_polygon_parent_class))->write(object, xml_doc, repr, flags);
- }
+ SPShape::write(xml_doc, repr, flags);
return repr;
}
@@ -118,19 +104,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 sp_polygon_set(SPObject *object, unsigned int key, const gchar *value)
-{
- SPPolygon *polygon = SP_POLYGON(object);
-
+void SPPolygon::set(unsigned int key, const gchar* value) {
switch (key) {
case SP_ATTR_POINTS: {
if (!value) {
@@ -138,6 +122,7 @@ void sp_polygon_set(SPObject *object, 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 +131,13 @@ void sp_polygon_set(SPObject *object, 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,21 +167,19 @@ void sp_polygon_set(SPObject *object, 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;
}
default:
- if (((SPObjectClass *) sp_polygon_parent_class)->set) {
- ((SPObjectClass *) sp_polygon_parent_class)->set(object, key, value);
- }
+ SPShape::set(key, value);
break;
}
}
-static gchar *sp_polygon_description(SPItem */*item*/)
-{
- return g_strdup(_("<b>Polygon</b>"));
+gchar* SPPolygon::description() {
+ return g_strdup(_("<b>Polygon</b>"));
}
/*