diff --git a/src/svg/svg-path.cpp b/src/svg/svg-path.cpp
index b37814164eb1c2bca3f2557eabfda04386bc7de9..0239d2ae0cd843d32c916982ff9170fdee0d5007 100644 (file)
--- a/src/svg/svg-path.cpp
+++ b/src/svg/svg-path.cpp
#define __SP_SVG_PARSE_C__
-/*
+/*
svg-path.c: Parse SVG path element data into bezier path.
-
+
Copyright (C) 2000 Eazel, Inc.
Copyright (C) 2000 Lauris Kaplinski
Copyright (C) 2001 Ximian, Inc.
-
+
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
-
+
Authors:
Raph Levien <raph@artofcode.com>
Lauris Kaplinski <lauris@ximian.com>
*/
+#include <cstring>
+#include <string>
#include <cassert>
#include <glib/gmem.h>
#include <glib/gmessages.h>
#include <glib/gstrfuncs.h>
+#include <glib.h> // g_assert()
#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.
double spx, spy; /* beginning of current subpath point */
char cmd; /* current command (lowercase) */
int param; /* parameter number */
- bool rel; /* true if relative coords */
+ bool rel; /* true if relative coords */
double params[7]; /* parameters that have been parsed */
};
switch (ctx->cmd) {
case 'm':
/* moveto */
- if (ctx->param == 2
- || final)
+ if (ctx->param == 2 || final)
{
rsvg_parse_path_default_xy (ctx, 2);
#ifdef VERBOSE
break;
case 'l':
/* lineto */
- if (ctx->param == 2
- || final)
+ if (ctx->param == 2 || final)
{
rsvg_parse_path_default_xy (ctx, 2);
#ifdef VERBOSE
break;
case 'c':
/* curveto */
- if ( ( ctx->param == 6 )
- || final )
+ if (ctx->param == 6 || final )
{
rsvg_parse_path_default_xy (ctx, 6);
x1 = ctx->params[0];
break;
case 's':
/* smooth curveto */
- if ( ( ctx->param == 4 )
- || final )
+ if (ctx->param == 4 || final)
{
rsvg_parse_path_default_xy (ctx, 4);
x1 = 2 * ctx->cpx - ctx->rpx;
int i = 0;
double val = 0;
char c = 0;
- bool in_num = FALSE;
- bool in_frac = FALSE;
- bool in_exp = FALSE;
- bool exp_wait_sign = FALSE;
+ bool in_num = false;
+ bool in_frac = false;
+ bool in_exp = false;
+ bool exp_wait_sign = false;
int sign = 0;
int exp = 0;
int exp_sign = 0;
if (in_exp)
{
exp = (exp * 10) + c - '0';
- exp_wait_sign = FALSE;
+ exp_wait_sign = false;
}
else if (in_frac)
val += (frac *= 0.1) * (c - '0');
}
else
{
- in_num = TRUE;
+ in_num = true;
assert(!in_frac && !in_exp);
exp = 0;
exp_sign = 1;
- exp_wait_sign = FALSE;
+ exp_wait_sign = false;
val = c - '0';
sign = 1;
}
{
if (!in_num)
{
- in_num = TRUE;
+ in_num = true;
assert(!in_exp);
exp = 0;
exp_sign = 1;
- exp_wait_sign = FALSE;
+ exp_wait_sign = false;
val = 0;
sign = 1;
}
- in_frac = TRUE;
+ in_frac = true;
frac = 1;
}
else if ((c == 'E' || c == 'e') && in_num)
{
/* fixme: Should we add `&& !in_exp' to the above condition?
* It looks like the current code will parse `1e3e4' (as 1e4). */
- in_exp = TRUE;
- exp_wait_sign = TRUE;
+ in_exp = true;
+ exp_wait_sign = true;
exp = 0;
exp_sign = 1;
}
}
}
ctx->params[ctx->param++] = val;
- rsvg_parse_path_do_cmd (ctx, FALSE);
+ rsvg_parse_path_do_cmd (ctx, false);
if (c=='.') {
- in_num = TRUE;
+ in_num = true;
val = 0;
- in_frac = TRUE;
- in_exp = FALSE;
+ in_frac = true;
+ in_exp = false;
frac = 1;
}
else {
- in_num = FALSE;
- in_frac = FALSE;
- in_exp = FALSE;
+ in_num = false;
+ in_frac = false;
+ in_exp = false;
}
}
{
sign = c == '+' ? 1 : -1;;
val = 0;
- in_num = TRUE;
- in_frac = FALSE;
- in_exp = FALSE;
+ in_num = true;
+ in_frac = false;
+ in_exp = false;
exp = 0;
exp_sign = 1;
- exp_wait_sign = FALSE;
+ exp_wait_sign = false;
}
else if (c == 'z' || c == 'Z')
{
if (ctx->param)
- rsvg_parse_path_do_cmd (ctx, TRUE);
+ rsvg_parse_path_do_cmd (ctx, true);
rsvg_bpath_def_closepath (ctx->bpath);
ctx->cmd = 'm';
else if (c >= 'A' && c <= 'Z' && c != 'E')
{
if (ctx->param)
- rsvg_parse_path_do_cmd (ctx, TRUE);
+ rsvg_parse_path_do_cmd (ctx, true);
ctx->cmd = c + 'a' - 'A';
- ctx->rel = FALSE;
+ ctx->rel = false;
}
else if (c >= 'a' && c <= 'z' && c != 'e')
{
if (ctx->param)
- rsvg_parse_path_do_cmd (ctx, TRUE);
+ rsvg_parse_path_do_cmd (ctx, true);
ctx->cmd = c;
- ctx->rel = TRUE;
+ ctx->rel = true;
}
/* else c _should_ be whitespace or , */
}
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());
}
/*