svg-path.cpp revision e46784cf4de167b3c9e1a85f5381e0364ce0b6e9
#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 <cstring>
#include <string>
#include <cassert>
#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 "svg/path-string.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 */
bool rel; /* true if relative coords */
};
{
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++) {
}
}
{
#ifdef VERBOSE
int i;
}
#endif
case 'm':
/* moveto */
{
#ifdef VERBOSE
g_print ("'m' moveto %g,%g\n",
#endif
}
break;
case 'l':
/* lineto */
{
#ifdef VERBOSE
g_print ("'l' lineto %g,%g\n",
#endif
}
break;
case 'c':
/* curveto */
{
#ifdef VERBOSE
g_print ("'c' curveto %g,%g %g,%g, %g,%g\n",
#endif
}
break;
case 's':
/* smooth curveto */
{
#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
}
break;
case 'a':
{
}
break;
case 'z':
{
// This makes sure we do the right moveto if the closepath is followed by anything other than a moveto
}
}
break;
default:
}
}
{
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;
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)
{
exp_wait_sign = false;
}
else if (in_frac)
else
}
else
{
in_num = true;
exp = 0;
exp_sign = 1;
exp_wait_sign = false;
val = c - '0';
sign = 1;
}
}
{
if (!in_num)
{
in_num = true;
exp = 0;
exp_sign = 1;
exp_wait_sign = false;
val = 0;
sign = 1;
}
in_frac = true;
frac = 1;
}
{
/* 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;
exp = 0;
exp_sign = 1;
}
{
exp_wait_sign = false;
}
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=='.') {
in_num = true;
val = 0;
in_frac = true;
in_exp = false;
frac = 1;
}
else {
in_num = false;
in_frac = false;
in_exp = false;
}
}
if (c == '\0')
break;
{
val = 0;
in_num = true;
in_frac = false;
in_exp = false;
exp = 0;
exp_sign = 1;
exp_wait_sign = false;
}
else if (c >= 'A' && c <= 'Z' && c != 'E')
{
}
else if (c >= 'a' && c <= 'z' && c != 'e')
{
char next_cmd = c;
}
/* else c _should_ be whitespace or , */
}
rsvg_parse_path_do_cmd (ctx, true, 0);
}
{
return bpath;
}
{
bool closed=false;
case NR_LINETO:
}
break;
case NR_CURVETO:
break;
case NR_MOVETO_OPEN:
case NR_MOVETO:
if (closed) {
}
break;
default:
}
}
if (closed) {
}
}
/*
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 :