|
Packit Service |
2781ba |
/* This file is part of GEGL editor -- a gtk frontend for GEGL
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
2781ba |
* it under the terms of the GNU General Public License as published by
|
|
Packit Service |
2781ba |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
2781ba |
* (at your option) any later version.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
2781ba |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
2781ba |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
2781ba |
* GNU General Public License for more details.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
2781ba |
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Copyright (C) 2003, 2004, 2006, 2007, 2008 Øyvind Kolås
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "config.h"
|
|
Packit Service |
2781ba |
#include "gegl-path-spiro.h"
|
|
Packit Service |
2781ba |
#include <gegl.h>
|
|
Packit Service |
2781ba |
#include <math.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <spiroentrypoints.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
struct {
|
|
Packit Service |
2781ba |
/* Called by spiro to start a contour */
|
|
Packit Service |
2781ba |
void (*moveto)(bezctx *bc, double x, double y, int is_open);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Called by spiro to move from the last point to the next one on a straight line */
|
|
Packit Service |
2781ba |
void (*lineto)(bezctx *bc, double x, double y);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Called by spiro to move from the last point to the next along a quadratic bezier spline */
|
|
Packit Service |
2781ba |
/* (x1,y1) is the quadratic bezier control point and (x2,y2) will be the new end point */
|
|
Packit Service |
2781ba |
void (*quadto)(bezctx *bc, double x1, double y1, double x2, double y2);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Called by spiro to move from the last point to the next along a cubic bezier spline */
|
|
Packit Service |
2781ba |
/* (x1,y1) and (x2,y2) are the two off-curve control point and (x3,y3) will be the new end point */
|
|
Packit Service |
2781ba |
void (*curveto)(bezctx *bc, double x1, double y1, double x2, double y2,
|
|
Packit Service |
2781ba |
double x3, double y3);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* I'm not entirely sure what this does -- I just leave it blank */
|
|
Packit Service |
2781ba |
void (*mark_knot)(bezctx *bc, int knot_idx);
|
|
Packit Service |
2781ba |
GeglPathList *path;
|
|
Packit Service |
2781ba |
} bezcontext;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void moveto (bezctx *bc, double x, double y, int is_open)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
bezcontext.path = gegl_path_list_append (bezcontext.path, 'M', x, y);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
static void lineto (bezctx *bc, double x, double y)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
bezcontext.path = gegl_path_list_append (bezcontext.path, 'L', x, y);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
static void quadto (bezctx *bc, double x1, double y1, double x2, double y2)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
g_print ("%s\n", G_STRFUNC);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
static void curveto(bezctx *bc,
|
|
Packit Service |
2781ba |
double x1, double y1,
|
|
Packit Service |
2781ba |
double x2, double y2,
|
|
Packit Service |
2781ba |
double x3, double y3)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
bezcontext.path = gegl_path_list_append (bezcontext.path, 'C', x1, y1, x2, y2, x3, y3);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglPathList *gegl_path_spiro_flatten (GeglPathList *original)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglPathList *iter;
|
|
Packit Service |
2781ba |
spiro_cp *points;
|
|
Packit Service |
2781ba |
gboolean is_spiro = TRUE;
|
|
Packit Service |
2781ba |
gboolean closed = FALSE;
|
|
Packit Service |
2781ba |
gint count;
|
|
Packit Service |
2781ba |
gint i;
|
|
Packit Service |
2781ba |
/* first we do a run through the path checking it's length
|
|
Packit Service |
2781ba |
* and determining whether we can flatten the incoming path
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
for (count=0,iter = original; iter; iter=iter->next)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
switch (iter->d.type)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
case 'z':
|
|
Packit Service |
2781ba |
closed = TRUE;
|
|
Packit Service |
2781ba |
case 'v':
|
|
Packit Service |
2781ba |
case 'o':
|
|
Packit Service |
2781ba |
case 'O':
|
|
Packit Service |
2781ba |
case '[':
|
|
Packit Service |
2781ba |
case ']':
|
|
Packit Service |
2781ba |
case '{':
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
default:
|
|
Packit Service |
2781ba |
is_spiro=FALSE;
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
count ++;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!is_spiro)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
return original;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
points = g_new0 (spiro_cp, count);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
iter = original;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
for (i=0; iter; iter=iter->next, i++)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (iter->d.type == 'z')
|
|
Packit Service |
2781ba |
continue;
|
|
Packit Service |
2781ba |
points[i].x = iter->d.point[0].x;
|
|
Packit Service |
2781ba |
points[i].y = iter->d.point[0].y;
|
|
Packit Service |
2781ba |
switch (iter->d.type)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
case 'C':
|
|
Packit Service |
2781ba |
points[i].x = iter->d.point[2].x;
|
|
Packit Service |
2781ba |
points[i].y = iter->d.point[2].y;
|
|
Packit Service |
2781ba |
points[i].ty = SPIRO_G4;
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
case 'L':
|
|
Packit Service |
2781ba |
points[i].ty = SPIRO_G4;
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
case 'v':
|
|
Packit Service |
2781ba |
points[i].ty = SPIRO_CORNER;
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
case 'o':
|
|
Packit Service |
2781ba |
points[i].ty = SPIRO_G4;
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
case 'O':
|
|
Packit Service |
2781ba |
points[i].ty = SPIRO_G2;
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
case '[':
|
|
Packit Service |
2781ba |
points[i].ty = SPIRO_LEFT;
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
case ']':
|
|
Packit Service |
2781ba |
points[i].ty = SPIRO_RIGHT;
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
case '{':
|
|
Packit Service |
2781ba |
points[i].ty = SPIRO_OPEN_CONTOUR;
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
case '0':
|
|
Packit Service |
2781ba |
points[i].ty = SPIRO_G2;
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
case 'V':
|
|
Packit Service |
2781ba |
points[i].ty = SPIRO_CORNER;
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
case 'z':
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
/*case '}':
|
|
Packit Service |
2781ba |
points[i].ty = SPIRO_END_CONTOUR;
|
|
Packit Service |
2781ba |
break;*/
|
|
Packit Service |
2781ba |
default:
|
|
Packit Service |
2781ba |
points[i].ty = SPIRO_G4;
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
bezcontext.moveto = moveto;
|
|
Packit Service |
2781ba |
bezcontext.lineto = lineto;
|
|
Packit Service |
2781ba |
bezcontext.curveto = curveto;
|
|
Packit Service |
2781ba |
bezcontext.quadto = quadto;
|
|
Packit Service |
2781ba |
bezcontext.path = NULL;
|
|
Packit Service |
2781ba |
SpiroCPsToBezier(points,count - (closed?1:0), closed, (void*)&bezcontext);
|
|
Packit Service |
2781ba |
g_free (points);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return bezcontext.path;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
void gegl_path_spiro_init (void)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
static gboolean done = FALSE;
|
|
Packit Service |
2781ba |
if (done)
|
|
Packit Service |
2781ba |
return;
|
|
Packit Service |
2781ba |
done = TRUE;
|
|
Packit Service |
2781ba |
gegl_path_add_type ('v', 2, "spiro corner");
|
|
Packit Service |
2781ba |
gegl_path_add_type ('o', 2, "spiro g4");
|
|
Packit Service |
2781ba |
gegl_path_add_type ('O', 2, "spiro g2");
|
|
Packit Service |
2781ba |
gegl_path_add_type ('[', 2, "spiro left");
|
|
Packit Service |
2781ba |
gegl_path_add_type (']', 2, "spiro right");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_path_add_flattener (gegl_path_spiro_flatten);
|
|
Packit Service |
2781ba |
}
|