From ac33151cfb8293b8b7f7d3882f75dd779e4346d9 Mon Sep 17 00:00:00 2001 From: mental Date: Wed, 24 Jan 2007 03:24:42 +0000 Subject: [PATCH] switch to using SVG::PathString for building paths --- src/extension/internal/grid.cpp | 17 +++------- src/sp-ellipse.cpp | 44 +++++++++++--------------- src/svg/svg-path.cpp | 28 +++++++--------- src/trace/potrace/inkscape-potrace.cpp | 24 +++++--------- 4 files changed, 43 insertions(+), 70 deletions(-) diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp index cf5c7529d..87e0c14ac 100644 --- a/src/extension/internal/grid.cpp +++ b/src/extension/internal/grid.cpp @@ -20,6 +20,8 @@ #include "sp-object.h" #include "util/glib-list-iterators.h" +#include "svg/path-string.h" + #include "extension/effect.h" #include "extension/system.h" @@ -44,30 +46,21 @@ Grid::load (Inkscape::Extension::Extension *module) 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 819aed997..38cc924c8 100644 --- a/src/sp-ellipse.cpp +++ b/src/sp-ellipse.cpp @@ -23,7 +23,7 @@ #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 e6899a3b2..c56898697 100644 --- a/src/svg/svg-path.cpp +++ b/src/svg/svg-path.cpp @@ -33,7 +33,7 @@ #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. @@ -656,42 +656,38 @@ gchar *sp_svg_write_path(NArtBpath const *bpath) 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()); } /* diff --git a/src/trace/potrace/inkscape-potrace.cpp b/src/trace/potrace/inkscape-potrace.cpp index c27309eb9..3f4cbc36c 100644 --- a/src/trace/potrace/inkscape-potrace.cpp +++ b/src/trace/potrace/inkscape-potrace.cpp @@ -27,7 +27,7 @@ #include #include "message-stack.h" #include -#include +#include #include "curve.h" #include "bitmap.h" @@ -125,7 +125,7 @@ hasPoint(std::vector &points, double x, double y) */ static long writePaths(PotraceTracingEngine *engine, potrace_path_t *plist, - Inkscape::SVGOStringStream& data, std::vector &points) + Inkscape::SVG::PathString& data, std::vector &points) { long nodeCount = 0L; @@ -155,7 +155,7 @@ writePaths(PotraceTracingEngine *engine, potrace_path_t *plist, p.x = x2; p.y = y2; points.push_back(p); } - data << "M " << x2 << " " << y2 << " "; + data.moveTo(x2, y2); nodeCount++; for (int i=0 ; in ; i++) @@ -172,21 +172,17 @@ writePaths(PotraceTracingEngine *engine, potrace_path_t *plist, 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) { @@ -395,9 +391,7 @@ PotraceTracingEngine::grayMapToPath(GrayMap *grayMap, long *nodeCount) return ""; } - Inkscape::SVGOStringStream data; - - data << ""; + Inkscape::SVG::PathString data; //## copy the path information into our d="" attribute string std::vector points; @@ -409,12 +403,10 @@ PotraceTracingEngine::grayMapToPath(GrayMap *grayMap, long *nodeCount) if (!keepGoing) return ""; - std::string d = data.str(); if ( nodeCount) *nodeCount = thisNodeCount; - return d; - + return data.ustring(); } -- 2.39.5