Debian Codegraph @

third_party/spiro/ppedit/bezctx_quartz.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 <Carbon/Carbon.h>
22
23 #include "zmisc.h"
24 #include "bezctx.h"
25 #include "bezctx_quartz.h"
26
27
28 typedef struct {
29 bezctx base;
30 CGMutablePathRef pathref;
31 int is_open;
32 } bezctx_quartz;
33
34 static void
35 bezctx_quartz_moveto(bezctx *z, double x, double y, int is_open) {
36 bezctx_quartz *bc = (bezctx_quartz *)z;
37 if (!bc->is_open) CGPathCloseSubpath(bc->pathref);
38 CGPathMoveToPoint(bc->pathref, NULL, x, y);
39 bc->is_open = is_open;
40 }
41
42 static void
43 bezctx_quartz_lineto(bezctx *z, double x, double y) {
44 bezctx_quartz *bc = (bezctx_quartz *)z;
45 CGPathAddLineToPoint(bc->pathref, NULL, x, y);
46 }
47
48 static void
49 bezctx_quartz_quadto(bezctx *z, double x1, double y1, double x2, double y2)
50 {
51 bezctx_quartz *bc = (bezctx_quartz *)z;
52 CGPathAddQuadCurveToPoint(bc->pathref, NULL, x1, y1, x2, y2);
53 }
54
55 bezctx *
56 new_bezctx_quartz(void) {
57 bezctx_quartz *result = znew(bezctx_quartz, 1);
58
59 result->base.moveto = bezctx_quartz_moveto;
60 result->base.lineto = bezctx_quartz_lineto;
61 result->base.quadto = bezctx_quartz_quadto;
62 result->base.mark_knot = NULL;
63 result->pathref = CGPathCreateMutable();
64 result->is_open = 1;
65 return &result->base;
66 }
67
68
69 CGMutablePathRef
70 bezctx_to_quartz(bezctx *z)
71 {
72 bezctx_quartz *bc = (bezctx_quartz *)z;
73 CGMutablePathRef result = bc->pathref;
74
75 if (!bc->is_open) CGPathCloseSubpath(result);
76 zfree(bc);
77 return result;
78 }