Debian Codegraph @

third_party/spiro/ppedit/bezctx_libart.c

raw symbols SCIP
1 /*
2 ppedit - A pattern plate editor for Spiro splines.
3 Copyright (C) 2007 Raph Levien
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
19
20 */
21 #include <libart_lgpl/libart.h>
22 #include "zmisc.h"
23 #include "bezctx.h"
24 #include "bezctx_libart.h"
25
26 typedef struct {
27 bezctx base;
28 int n_bez;
29 int n_bez_max;
30 ArtBpath *bez;
31 } bezctx_libart;
32
33 static void
34 bezctx_libart_moveto(bezctx *z, double x, double y, int is_open) {
35 bezctx_libart *bc = (bezctx_libart *)z;
36 ArtBpath *bp;
37
38 if (bc->n_bez == bc->n_bez_max) {
39 bc->bez = zrenew(ArtBpath, bc->bez, bc->n_bez_max <<= 1);
40 }
41 bp = &bc->bez[bc->n_bez++];
42 bp->code = is_open ? ART_MOVETO_OPEN : ART_MOVETO;
43 bp->x3 = x;
44 bp->y3 = y;
45 }
46
47 void
48 bezctx_libart_lineto(bezctx *z, double x, double y) {
49 bezctx_libart *bc = (bezctx_libart *)z;
50 ArtBpath *bp;
51
52 if (bc->n_bez == bc->n_bez_max) {
53 bc->bez = zrenew(ArtBpath, bc->bez, bc->n_bez_max <<= 1);
54 }
55 bp = &bc->bez[bc->n_bez++];
56 bp->code = ART_LINETO;
57 bp->x3 = x;
58 bp->y3 = y;
59 }
60
61 void
62 bezctx_libart_quadto(bezctx *z, double x1, double y1, double x2, double y2)
63 {
64 bezctx_libart *bc = (bezctx_libart *)z;
65 ArtBpath *bp;
66 double x0, y0;
67
68 if (bc->n_bez == bc->n_bez_max) {
69 bc->bez = zrenew(ArtBpath, bc->bez, bc->n_bez_max <<= 1);
70 }
71 bp = &bc->bez[bc->n_bez++];
72 x0 = bp[-1].x3;
73 y0 = bp[-1].y3;
74 bp->code = ART_CURVETO;
75 bp->x1 = x1 + (1./3) * (x0 - x1);
76 bp->y1 = y1 + (1./3) * (y0 - y1);
77 bp->x2 = x1 + (1./3) * (x2 - x1);
78 bp->y2 = y1 + (1./3) * (y2 - y1);
79 bp->x3 = x2;
80 bp->y3 = y2;
81 }
82
83 void
84 bezctx_libart_curveto(bezctx *z, double x1, double y1, double x2, double y2,
85 double x3, double y3)
86 {
87 bezctx_libart *bc = (bezctx_libart *)z;
88 ArtBpath *bp;
89
90 if (bc->n_bez == bc->n_bez_max) {
91 bc->bez = zrenew(ArtBpath, bc->bez, bc->n_bez_max <<= 1);
92 }
93 bp = &bc->bez[bc->n_bez++];
94 bp->code = ART_CURVETO;
95 bp->x1 = x1;
96 bp->y1 = y1;
97 bp->x2 = x2;
98 bp->y2 = y2;
99 bp->x3 = x3;
100 bp->y3 = y3;
101 }
102
103 ArtBpath *
104 bezctx_to_bpath(bezctx *z) {
105 bezctx_libart *bc = (bezctx_libart *)z;
106 ArtBpath *result;
107
108 if (bc->n_bez == bc->n_bez_max) {
109 bc->bez = zrenew(ArtBpath, bc->bez, bc->n_bez_max <<= 1);
110 }
111 bc->bez[bc->n_bez].code = ART_END;
112 result = bc->bez;
113 zfree(bc);
114 return result;
115 }
116
117 bezctx *
118 new_bezctx_libart(void) {
119 bezctx_libart *result = znew(bezctx_libart, 1);
120
121 result->base.moveto = bezctx_libart_moveto;
122 result->base.lineto = bezctx_libart_lineto;
123 result->base.quadto = bezctx_libart_quadto;
124 result->base.curveto = bezctx_libart_curveto;
125 result->base.mark_knot = NULL;
126 result->n_bez = 0;
127 result->n_bez_max = 4;
128 result->bez = znew(ArtBpath, result->n_bez_max);
129 return &result->base;
130 }
131