Code

* 2geomify polygon svg writing
authorjohanengelen <johanengelen@users.sourceforge.net>
Tue, 8 Jul 2008 17:55:15 +0000 (17:55 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Tue, 8 Jul 2008 17:55:15 +0000 (17:55 +0000)
* 2geomify caligraphy and erasertool svg writing

src/dyna-draw-context.cpp
src/eraser-context.cpp
src/sp-polygon.cpp

index 68bb2f163efdab8bfa4cc110a183861b2a3b5210..8db9cb2e174e3103f89051192bfddd002d021d43 100644 (file)
@@ -52,6 +52,7 @@
 #include "libnr/nr-path.h"
 #include "libnr/nr-matrix-ops.h"
 #include "libnr/nr-scale-translate-ops.h"
+#include "libnr/nr-convert2geom.h"
 #include "xml/repr.h"
 #include "context-fns.h"
 #include "sp-item.h"
@@ -65,7 +66,8 @@
 #include "display/canvas-bpath.h"
 #include "display/canvas-arena.h"
 #include "livarot/Shape.h"
-#include "2geom/isnan.h"
+#include <2geom/isnan.h>
+#include <2geom/pathvector.h>
 
 #include "dyna-draw-context.h"
 
@@ -971,9 +973,6 @@ set_to_accumulated(SPDynaDrawContext *dc, bool unionize)
     SPDesktop *desktop = SP_EVENT_CONTEXT(dc)->desktop;
 
     if (!dc->accumulated->is_empty()) {
-        NArtBpath *abp;
-        gchar *str;
-
         if (!dc->repr) {
             /* Create object */
             Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
@@ -989,10 +988,9 @@ set_to_accumulated(SPDynaDrawContext *dc, bool unionize)
             item->transform = SP_ITEM(desktop->currentRoot())->getRelativeTransform(desktop->currentLayer());
             item->updateRepr();
         }
-        abp = nr_artpath_affine(dc->accumulated->get_bpath(), sp_desktop_dt2root_affine(desktop));
-        str = sp_svg_write_path(abp);
+        Geom::PathVector pathv = dc->accumulated->get_pathvector() * to_2geom(sp_desktop_dt2root_affine(desktop));
+        gchar *str = sp_svg_write_path(pathv);
         g_assert( str != NULL );
-        g_free(abp);
         dc->repr->setAttribute("d", str);
         g_free(str);
 
index 605c6971d4e0f42ea85ac7296037c9f4315f99a6..6cfd915ef2ccac2f7716f260478e8f8ac7dcdae7 100644 (file)
 #include "message-context.h"
 #include "prefs-utils.h"
 #include "pixmaps/cursor-eraser.xpm"
-#include "libnr/n-art-bpath.h"
-#include "libnr/nr-path.h"
-#include "libnr/nr-matrix-ops.h"
-#include "libnr/nr-scale-translate-ops.h"
 #include "xml/repr.h"
 #include "context-fns.h"
 #include "sp-item.h"
@@ -66,7 +62,8 @@
 #include "display/canvas-bpath.h"
 #include "display/canvas-arena.h"
 #include "livarot/Shape.h"
-#include "2geom/isnan.h"
+#include <2geom/isnan.h>
+#include <2geom/pathvector.h>
 
 #include "eraser-context.h"
 
@@ -718,9 +715,6 @@ set_to_accumulated(SPEraserContext *dc)
     bool workDone = false;
 
     if (!dc->accumulated->is_empty()) {
-        NArtBpath *abp;
-        gchar *str;
-
         if (!dc->repr) {
             /* Create object */
             Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
@@ -736,10 +730,9 @@ set_to_accumulated(SPEraserContext *dc)
             item->transform = SP_ITEM(desktop->currentRoot())->getRelativeTransform(desktop->currentLayer());
             item->updateRepr();
         }
-        abp = nr_artpath_affine(dc->accumulated->get_bpath(), sp_desktop_dt2root_affine(desktop));
-        str = sp_svg_write_path(abp);
+        Geom::PathVector pathv = dc->accumulated->get_pathvector() * to_2geom(sp_desktop_dt2root_affine(desktop));
+        gchar *str = sp_svg_write_path(pathv);
         g_assert( str != NULL );
-        g_free(abp);
         dc->repr->setAttribute("d", str);
         g_free(str);
 
index 88b155e8e6761060069d3990c3476b983085b23f..04046a47d81982a3ad07b26d5a616f110d0a6a85 100644 (file)
@@ -18,7 +18,7 @@
 #include "sp-polygon.h"
 #include "display/curve.h"
 #include <glibmm/i18n.h>
-#include "libnr/n-art-bpath.h"
+#include <2geom/pathvector.h>
 #include "svg/stringstream.h"
 #include "xml/repr.h"
 #include "document.h"
@@ -87,27 +87,23 @@ 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 ( dynamic_cast<Geom::LineSegment const *>(&*cit) ||
+                 dynamic_cast<Geom::HLineSegment const *>(&*cit) ||
+                 dynamic_cast<Geom::VLineSegment const *>(&*cit) )
+            {
+                os << cit->finalPoint()[0] << "," << cit->finalPoint()[1] << " ";
+            } else {
+                g_error("sp_svg_write_polygon: polygon path contains non-straight line segments");
+            }
         }
     }
 
@@ -126,8 +122,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);