summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6021d43)
raw | patch | inline | side by side (parent: 6021d43)
| author | mental <mental@users.sourceforge.net> | |
| Wed, 24 Jan 2007 03:24:42 +0000 (03:24 +0000) | ||
| committer | mental <mental@users.sourceforge.net> | |
| Wed, 24 Jan 2007 03:24:42 +0000 (03:24 +0000) |
index cf5c7529db0e06bdb0740a7f747d18a8a9c73c4d..87e0c14ac09b6562b804d2e4aabe73d61099c434 100644 (file)
#include "sp-object.h"
#include "util/glib-list-iterators.h"
+#include "svg/path-string.h"
+
#include "extension/effect.h"
#include "extension/system.h"
namespace {
-Glib::ustring build_op(char op, NR::Point p) {
- gchar *floatstring;
- // FIXME: locale formatting issues?
- floatstring = g_strdup_printf("%c%f,%f ", op, p[NR::X], p[NR::Y]);
- Glib::ustring result(floatstring);
- g_free(floatstring);
- return result;
-}
-
Glib::ustring build_lines(int axis, NR::Rect bounding_area,
float offset, float spacing)
{
NR::Point point_offset(0.0, 0.0);
point_offset[axis] = offset;
- Glib::ustring path_data("");
+ 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 += build_op('M', start_point + point_offset)
- + build_op('L', end_point + point_offset);
+ path_data.moveTo(start_point + point_offset)
+ .lineTo(end_point + point_offset);
}
return path_data;
diff --git a/src/sp-ellipse.cpp b/src/sp-ellipse.cpp
index 819aed99766dc6f070387eb1bc7c50adcf91f228..38cc924c875f7b41cd3fb48564aee8e1de503aa0 100644 (file)
--- a/src/sp-ellipse.cpp
+++ b/src/sp-ellipse.cpp
#include "libnr/nr-path.h"
#include "libnr/nr-matrix-fns.h"
#include "svg/svg.h"
-#include "svg/stringstream.h"
+#include "svg/path-string.h"
#include "xml/repr.h"
#include "attributes.h"
#include "style.h"
@@ -662,42 +662,34 @@ sp_arc_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
static gboolean
sp_arc_set_elliptical_path_attribute(SPArc *arc, Inkscape::XML::Node *repr)
{
- gint fa, fs;
- gdouble dt;
- Inkscape::SVGOStringStream os;
-
SPGenericEllipse *ge = SP_GENERICELLIPSE(arc);
+ Inkscape::SVG::PathString str;
+
NR::Point p1 = sp_arc_get_xy(arc, ge->start);
NR::Point p2 = sp_arc_get_xy(arc, ge->end);
+ double rx = ge->rx.computed;
+ double ry = ge->ry.computed;
- dt = fmod(ge->end - ge->start, SP_2PI);
+ str.moveTo(p1);
+
+ double dt = fmod(ge->end - ge->start, SP_2PI);
if (fabs(dt) < 1e-6) {
NR::Point ph = sp_arc_get_xy(arc, (ge->start + ge->end) / 2.0);
- os << "M " << p1[NR::X] << " " << p1[NR::Y]
- << " A " << ge->rx.computed << " " << ge->ry.computed
- << " 0 1 1 " << " " << ph[NR::X] << "," << ph[NR::Y]
- << " A " << ge->rx.computed << " " << ge->ry.computed
- << " 0 1 1 " << " " << p2[NR::X] << " " << p2[NR::Y] << " z";
+ str.arcTo(rx, ry, 0, true, true, ph)
+ .arcTo(rx, ry, 0, true, true, p2)
+ .closePath();
} else {
- fa = (fabs(dt) > M_PI) ? 1 : 0;
- fs = (dt > 0) ? 1 : 0;
-#ifdef ARC_VERBOSE
- g_print("start:%g end:%g fa=%d fs=%d\n", ge->start, ge->end, fa, fs);
-#endif
+ bool fa = (fabs(dt) > M_PI) ? 1 : 0;
+ bool fs = (dt > 0) ? 1 : 0;
+ str.arcTo(rx, ry, 0, fa, fs, p2);
if (ge->closed) {
- os << "M " << p1[NR::X] << "," << p1[NR::Y]
- << " A " << ge->rx.computed << "," << ge->ry.computed
- << " 0 " << fa << " " << fs << " " << p2[NR::X] << "," << p2[NR::Y]
- << " L " << ge->cx.computed << "," << ge->cy.computed << " z";
- } else {
- os << "M " << p1[NR::X] << "," << p1[NR::Y]
- << " A " << ge->rx.computed << "," << ge->ry.computed
- << " 0 " << fa << " " << fs << " " << p2[NR::X] << "," << p2[NR::Y];
-
+ NR::Point center = NR::Point(ge->cx.computed, ge->cy.computed);
+ str.lineTo(center).closePath();
}
}
- repr->setAttribute("d", os.str().c_str());
+
+ repr->setAttribute("d", str.c_str());
return true;
}
diff --git a/src/svg/svg-path.cpp b/src/svg/svg-path.cpp
index e6899a3b2a3660adf9c6083d9469ee7f3f87e319..c5689869746bedb8ed6ee281bdfcb4698c4015eb 100644 (file)
--- a/src/svg/svg-path.cpp
+++ b/src/svg/svg-path.cpp
#include "libnr/n-art-bpath.h"
#include "gnome-canvas-bpath-util.h"
-#include "stringstream.h"
+#include "svg/path-string.h"
/* This module parses an SVG path element into an RsvgBpathDef.
g_return_val_if_fail (bpath != NULL, NULL);
+ Inkscape::SVG::PathString str;
+
for (int i = 0; bpath[i].code != NR_END; i++){
- if (i) {
- os << " ";
- }
switch (bpath [i].code){
case NR_LINETO:
- os << "L " << bpath[i].x3 << "," << bpath[i].y3;
+ str.lineTo(bpath[i].x3, bpath[i].y3);
break;
case NR_CURVETO:
- os << "C " << bpath[i].x1 << "," << bpath[i].y1
- << " " << bpath[i].x2 << "," << bpath[i].y2
- << " " << bpath[i].x3 << "," << bpath[i].y3;
+ str.curveTo(bpath[i].x1, bpath[i].y1,
+ bpath[i].x2, bpath[i].y2,
+ bpath[i].x3, bpath[i].y3);
break;
case NR_MOVETO_OPEN:
case NR_MOVETO:
if (closed) {
- os << "z ";
+ str.closePath();
}
closed = ( bpath[i].code == NR_MOVETO );
- os << "M " << bpath[i].x3 << "," << bpath[i].y3;
+ str.moveTo(bpath[i].x3, bpath[i].y3);
break;
+
default:
g_assert_not_reached ();
}
}
if (closed) {
- os << " z ";
+ str.closePath();
}
-// std::string s = os.str();
-// gchar *ret = g_strdup(s.c_str());
-// delete (s);
-// return ret;
- return g_strdup (os.str().c_str());
+ return g_strdup(str.c_str());
}
/*
index c27309eb9109ab6f73c7bff64d4a062c4ca4f34d..3f4cbc36c2803921e79aa0a61ff643205d6a515c 100644 (file)
#include <desktop-handles.h>
#include "message-stack.h"
#include <sp-path.h>
-#include <svg/stringstream.h>
+#include <svg/path-string.h>
#include "curve.h"
#include "bitmap.h"
*/
static long
writePaths(PotraceTracingEngine *engine, potrace_path_t *plist,
- Inkscape::SVGOStringStream& data, std::vector<Point> &points)
+ Inkscape::SVG::PathString& data, std::vector<Point> &points)
{
long nodeCount = 0L;
p.x = x2; p.y = y2;
points.push_back(p);
}
- data << "M " << x2 << " " << y2 << " ";
+ data.moveTo(x2, y2);
nodeCount++;
for (int i=0 ; i<curve->n ; i++)
switch (curve->tag[i])
{
case POTRACE_CORNER:
- data << "L " << x1 << " " << y1 << " " ;
- data << "L " << x2 << " " << y2 << " " ;
+ data.lineTo(x1, y1).lineTo(x2, y2);
break;
case POTRACE_CURVETO:
- data << "C " << x0 << " " << y0 << " "
- << x1 << " " << y1 << " "
- << x2 << " " << y2 << " ";
-
+ data.curveTo(x0, y0, x1, y1, x2, y2);
break;
default:
break;
}
nodeCount++;
}
- data << "z";
+ data.closePath();
for (path_t *child=node->childlist; child ; child=child->sibling)
{
return "";
}
- Inkscape::SVGOStringStream data;
-
- data << "";
+ Inkscape::SVG::PathString data;
//## copy the path information into our d="" attribute string
std::vector<Point> points;
if (!keepGoing)
return "";
- std::string d = data.str();
if ( nodeCount)
*nodeCount = thisNodeCount;
- return d;
-
+ return data.ustring();
}