Code

Fix ef spam when adjusting pattern on text - patch from Adonis Papaderos
[inkscape.git] / src / sp-polygon.cpp
index 9b9c91c5544828ab5019ee773d9c65cbc689cd06..014c68c9b75652ba8af992a904325b2c0daca8db 100644 (file)
 #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"
@@ -87,27 +90,21 @@ static void sp_polygon_build(SPObject *object, SPDocument *document, Inkscape::X
 
 /*
  * 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");
+            }
         }
     }
 
@@ -126,8 +123,7 @@ static Inkscape::XML::Node *sp_polygon_write(SPObject *object, Inkscape::XML::Do
     }
 
     /* 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);
 
@@ -208,14 +204,9 @@ void sp_polygon_set(SPObject *object, unsigned int key, const gchar *value)
             if (has_error || *cptr != '\0') {
                 /* TODO: Flag the document as in error, as per
                  * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing. */
-            } else if (curve->_posSet) {
-                /* We've done a moveto but no lineto.  I'm not sure how we're supposed to represent
-                 * a single-point polygon in SPCurve: sp_curve_closepath at the time of writing
-                 * doesn't seem to like simply moveto followed by closepath.  The following works,
-                 * but won't round-trip properly: I believe it will write as two points rather than
-                 * one. */
-                curve->lineto(curve->_movePos);
             } else if (hascpt) {
+                /* We might have done a moveto but no lineto.  I'm not sure how we're supposed to represent
+                 * 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);