Code

Extensions. Localized float values in SVG due to internal extensions, %f in printf...
[inkscape.git] / src / extension / internal / grid.cpp
index 534d4bcda632f96d7dbdd618bb29620c39454b95..1593ffe795f394881f4cd04719324a1f29344417 100644 (file)
@@ -46,25 +46,29 @@ Grid::load (Inkscape::Extension::Extension */*module*/)
 
 namespace {
 
-Glib::ustring build_lines(int axis, NR::Rect bounding_area,
-                          float offset, float spacing)
+Glib::ustring build_lines(Geom::Rect bounding_area,
+                          float offset[], float spacing[])
 {
-    NR::Point point_offset(0.0, 0.0);
-    point_offset[axis] = offset;
+    Geom::Point point_offset(0.0, 0.0);
 
     SVG::PathString path_data;
-    for (NR::Point start_point = bounding_area.min();
-            start_point[axis] + offset <= (bounding_area.max())[axis];
-            start_point[axis] += spacing) {
-        NR::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;
+    }
 
 }
 
@@ -78,22 +82,21 @@ Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc
 {
     Inkscape::Selection * selection     = ((SPDesktop *)document)->selection;
 
-    NR::Rect bounding_area = NR::Rect(NR::Point(0,0), NR::Point(100,100));
+    Geom::Rect bounding_area = Geom::Rect(Geom::Point(0,0), Geom::Point(100,100));
     if (selection->isEmpty()) {
         /* get page size */
         SPDocument * doc = document->doc();
-        bounding_area = NR::Rect(NR::Point(0,0),
-                                 NR::Point(sp_document_width(doc),
-                                           sp_document_height(doc)));
+        bounding_area = Geom::Rect(  Geom::Point(0,0),
+                                     Geom::Point(sp_document_width(doc), sp_document_height(doc))  );
     } else {
-        NR::Maybe<NR::Rect> bounds = selection->bounds();
+        Geom::OptRect bounds = selection->bounds();
         if (bounds) {
             bounding_area = *bounds;
         }
 
         gdouble doc_height  =  sp_document_height(document->doc());
-        NR::Rect temprec = NR::Rect(NR::Point(bounding_area.min()[NR::X], doc_height - bounding_area.min()[NR::Y]),
-                                    NR::Point(bounding_area.max()[NR::X], doc_height - bounding_area.max()[NR::Y]));
+        Geom::Rect temprec = Geom::Rect(Geom::Point(bounding_area.min()[Geom::X], doc_height - bounding_area.min()[Geom::Y]),
+                                    Geom::Point(bounding_area.max()[Geom::X], doc_height - bounding_area.max()[Geom::Y]));
 
         bounding_area = temprec;
     }
@@ -105,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");
@@ -119,12 +120,15 @@ 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());
 
     current_layer->appendChild(path);
+               Inkscape::GC::release(path);
 
     return;
 }