svg-path.cpp revision 6b15695578f07a3f72c4c9475c1a261a3021472a
#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.
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 <cassert>
#include <glib/gmessages.h>
#include <glib/gstrfuncs.h>
#include "libnr/n-art-bpath.h"
#include "gnome-canvas-bpath-util.h"
#include "stringstream.h"
/* This module parses an SVG path element into an RsvgBpathDef.
At present, there is no support for <marker> or any other contextual
information from the SVG file. The API will need to change rather
significantly to support these.
Reference: SVG working draft 3 March 2000, section 8.
*/
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif /* M_PI */
/* We are lazy ;-) (Lauris) */
struct RSVGParsePathCtx {
char cmd; /* current command (lowercase) */
int param; /* parameter number */
};
{
double t;
double th_half;
/* inverse transform compared with rsvg_path_arc */
}
/**
* rsvg_path_arc: Add an RSVG arc to the path context.
* @ctx: Path context.
* @rx: Radius in x direction (before rotation).
* @ry: Radius in y direction (before rotation).
* @x_axis_rotation: Rotation angle for axes.
* @large_arc_flag: 0 for arc length <= 180, 1 for arc >= 180.
* @sweep: 0 for "negative angle", 1 for "positive angle".
* @x: New x coordinate.
* @y: New y coordinate.
*
**/
int large_arc_flag, int sweep_flag,
double x, double y)
{
double d, sfactor, sfactor_sq;
int i, n_segs;
/*
Correction of out-of-range radii as described in Appendix F.6.6:
1. Ensure radii are non-zero (Done?).
2. Ensure that radii are positive.
3. Ensure that radii are large enough.
*/
if(pl > 1.0)
{
}
/* Proceed with computations as described in Appendix F.6.5 */
/* (x0, y0) is current point in transformed coordinate space.
(x1, y1) is new point in transformed coordinate space.
The arc fits a unit-radius circle in this space.
*/
if (sfactor_sq < 0) sfactor_sq = 0;
/* (xc, yc) is center of the circle. */
if (th_arc < 0 && sweep_flag)
else if (th_arc > 0 && !sweep_flag)
for (i = 0; i < n_segs; i++) {
}
}
/* supply defaults for missing parameters, assuming relative coordinates
are to be interpreted as x,y */
{
int i;
if (i > 2)
else if (i == 1)
else if (i == 0)
/* we shouldn't get here (usually ctx->param > 0 as
precondition) */
}
} else {
}
}
}
{
#ifdef VERBOSE
int i;
}
#endif
case 'm':
/* moveto */
|| final)
{
#ifdef VERBOSE
g_print ("'m' moveto %g,%g\n",
#endif
}
break;
case 'l':
/* lineto */
|| final)
{
#ifdef VERBOSE
g_print ("'l' lineto %g,%g\n",
#endif
}
break;
case 'c':
/* curveto */
|| final )
{
#ifdef VERBOSE
g_print ("'c' curveto %g,%g %g,%g, %g,%g\n",
#endif
}
break;
case 's':
/* smooth curveto */
|| final )
{
#ifdef VERBOSE
g_print ("'s' curveto %g,%g %g,%g, %g,%g\n",
#endif
}
break;
case 'h':
/* horizontal lineto */
#ifdef VERBOSE
g_print ("'h' lineto %g,%g\n",
#endif
}
break;
case 'v':
/* vertical lineto */
#ifdef VERBOSE
g_print ("'v' lineto %g,%g\n",
#endif
}
break;
case 'q':
/* quadratic bezier curveto */
/* non-normative reference:
*/
{
/* raise quadratic bezier to cubic */
#ifdef VERBOSE
g_print("'q' curveto %g,%g %g,%g, %g,%g\n",
#endif
}
break;
case 't':
/* Truetype quadratic bezier curveto */
/* generate a quadratic bezier with control point = xc, yc */
#ifdef VERBOSE
g_print ("'t' curveto %g,%g %g,%g, %g,%g\n",
#endif
} else if (final) {
/* raise quadratic bezier to cubic */
#ifdef VERBOSE
g_print ("'t' curveto %g,%g %g,%g, %g,%g\n",
#endif
} else {
#ifdef VERBOSE
g_print ("'t' lineto %g,%g\n",
#endif
}
}
break;
case 'a':
{
}
break;
default:
}
}
{
int i = 0;
double val = 0;
char c = 0;
int sign = 0;
int exp = 0;
int exp_sign = 0;
double frac = 0.0;
/* fixme: Do better error processing: e.g. at least stop parsing as soon as we find an error.
* At some point we'll need to do all of
* http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing.
*/
for (i = 0; ; i++)
{
c = data[i];
if (c >= '0' && c <= '9')
{
/* digit */
if (in_num)
{
if (in_exp)
{
}
else if (in_frac)
else
}
else
{
exp = 0;
exp_sign = 1;
val = c - '0';
sign = 1;
}
}
{
if (!in_num)
{
exp = 0;
exp_sign = 1;
val = 0;
sign = 1;
}
frac = 1;
}
{
/* fixme: Should we add `&& !in_exp' to the above condition?
* It looks like the current code will parse `1e3e4' (as 1e4). */
exp = 0;
exp_sign = 1;
}
{
}
else if (in_num)
{
/* end of number */
{
/* Handle relative coordinates. This switch statement attempts
to determine _what_ the coords are relative to. This is
underspecified in the 12 Apr working draft. */
{
case 'l':
case 'm':
case 'c':
case 's':
case 'q':
case 't':
} else {
}
break;
case 'a':
/* rule: sixth and seventh are x and y, rest are not
relative */
break;
case 'h':
/* rule: x-relative */
break;
case 'v':
/* rule: y-relative */
break;
}
}
if (c=='.') {
val = 0;
frac = 1;
}
else {
}
}
if (c == '\0')
break;
{
val = 0;
exp = 0;
exp_sign = 1;
}
else if (c == 'z' || c == 'Z')
{
}
else if (c >= 'A' && c <= 'Z' && c != 'E')
{
}
else if (c >= 'a' && c <= 'z' && c != 'e')
{
}
/* else c _should_ be whitespace or , */
}
}
{
}
return bpath;
}
{
bool closed=false;
if (i) {
os << " ";
}
case NR_LINETO:
break;
case NR_CURVETO:
break;
case NR_MOVETO_OPEN:
case NR_MOVETO:
if (closed) {
os << "z ";
}
break;
default:
}
}
if (closed) {
os << " z ";
}
// std::string s = os.str();
// gchar *ret = g_strdup(s.c_str());
// delete (s);
// return ret;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :