Code

This is the first c++ification commit from me. It handles sp-line, sp-polyline, sp...
[inkscape.git] / src / extension / internal / grid.cpp
index 366bab0006fec8dcf59c3157eccf884a11ebd0ff..1593ffe795f394881f4cd04719324a1f29344417 100644 (file)
@@ -46,25 +46,29 @@ Grid::load (Inkscape::Extension::Extension */*module*/)
 
 namespace {
 
-Glib::ustring build_lines(int axis, Geom::Rect bounding_area,
-                          float offset, float spacing)
+Glib::ustring build_lines(Geom::Rect bounding_area,
+                          float offset[], float spacing[])
 {
     Geom::Point point_offset(0.0, 0.0);
-    point_offset[axis] = offset;
 
     SVG::PathString path_data;
-    for (Geom::Point start_point = bounding_area.min();
-            start_point[axis] + offset <= (bounding_area.max())[axis];
-            start_point[axis] += spacing) {
-        Geom::Point end_point = start_point;
-        end_point[1-axis] = (bounding_area.max())[1-axis];
-
-        path_data.moveTo(start_point + point_offset)
-                 .lineTo(end_point + point_offset);
-    }
 
-    return path_data;
-}
+    for ( int axis = 0 ; axis < 2 ; ++axis ) {
+        point_offset[axis] = offset[axis];
+
+        for (Geom::Point start_point = bounding_area.min();
+                start_point[axis] + offset[axis] <= (bounding_area.max())[axis];
+                start_point[axis] += spacing[axis]) {
+            Geom::Point end_point = start_point;
+            end_point[1-axis] = (bounding_area.max())[1-axis];
+
+            path_data.moveTo(start_point + point_offset)
+                     .lineTo(end_point + point_offset);
+        }
+    }
+        // std::cout << "Path data:" << path_data.c_str() << std::endl;
+        return path_data;
+    }
 
 }
 
@@ -85,7 +89,7 @@ Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc
         bounding_area = Geom::Rect(  Geom::Point(0,0),
                                      Geom::Point(sp_document_width(doc), sp_document_height(doc))  );
     } else {
-        boost::optional<Geom::Rect> bounds = selection->bounds();
+        Geom::OptRect bounds = selection->bounds();
         if (bounds) {
             bounding_area = *bounds;
         }
@@ -104,11 +108,9 @@ Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc
                          module->get_param_float("yoffset") };
 
     Glib::ustring path_data("");
-    for ( int axis = 0 ; axis < 2 ; ++axis ) {
-        path_data += build_lines(axis, bounding_area,
-                                 offsets[axis], spacings[axis]);
-    }
 
+    path_data = build_lines(bounding_area,
+                                 offsets, spacings);
     Inkscape::XML::Document * xml_doc = sp_document_repr_doc(document->doc());
     Inkscape::XML::Node * current_layer = static_cast<SPDesktop *>(document)->currentLayer()->repr;
     Inkscape::XML::Node * path = xml_doc->createElement("svg:path");
@@ -118,7 +120,9 @@ Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc
     Glib::ustring style("fill:none;fill-opacity:0.75000000;fill-rule:evenodd;stroke:#000000;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000");
     style += ";stroke-width:";
     gchar floatstring[64];
-    sprintf(floatstring, "%f", line_width);
+    std::ostringstream stringstream;
+    stringstream << line_width;
+    sprintf(floatstring, "%s", stringstream.str().c_str());
     style += floatstring;
     style += "pt";
     path->setAttribute("style", style.c_str());