1 /* Copyright (C) 1989, 1995, 1996, 1997, 1998, 1999 artofcode LLC. All rights reserved.
2
3 This program is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2 of the License, or (at your
6 option) any later version.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 59 Temple Place, Suite 330, Boston, MA, 02111-1307.
16
17 */
18
19 /*$Id: zpath.c,v 1.2.6.1.2.1 2003/01/17 00:49:06 giles Exp $ */
20 /* Basic path operators */
21 #include "math_.h"
22 #include "ghost.h"
23 #include "oper.h"
24 #include "igstate.h"
25 #include "gsmatrix.h"
26 #include "gspath.h"
27 #include "store.h"
28
29 /* Forward references */
30 private int common_to(P2(i_ctx_t *,
31 int (*)(P3(gs_state *, floatp, floatp))));
32 private int common_curve(P2(i_ctx_t *,
33 int (*)(P7(gs_state *, floatp, floatp, floatp, floatp, floatp, floatp))));
34
35 /* - newpath - */
36 private int
znewpath(i_ctx_t * i_ctx_p)37 znewpath(i_ctx_t *i_ctx_p)
38 {
39 return gs_newpath(igs);
40 }
41
42 /* - currentpoint <x> <y> */
43 private int
zcurrentpoint(i_ctx_t * i_ctx_p)44 zcurrentpoint(i_ctx_t *i_ctx_p)
45 {
46 os_ptr op = osp;
47 gs_point pt;
48 int code = gs_currentpoint(igs, &pt);
49
50 if (code < 0)
51 return code;
52 push(2);
53 make_real(op - 1, pt.x);
54 make_real(op, pt.y);
55 return 0;
56 }
57
58 /* <x> <y> moveto - */
59 int
zmoveto(i_ctx_t * i_ctx_p)60 zmoveto(i_ctx_t *i_ctx_p)
61 {
62 return common_to(i_ctx_p, gs_moveto);
63 }
64
65 /* <dx> <dy> rmoveto - */
66 int
zrmoveto(i_ctx_t * i_ctx_p)67 zrmoveto(i_ctx_t *i_ctx_p)
68 {
69 return common_to(i_ctx_p, gs_rmoveto);
70 }
71
72 /* <x> <y> lineto - */
73 int
zlineto(i_ctx_t * i_ctx_p)74 zlineto(i_ctx_t *i_ctx_p)
75 {
76 return common_to(i_ctx_p, gs_lineto);
77 }
78
79 /* <dx> <dy> rlineto - */
80 int
zrlineto(i_ctx_t * i_ctx_p)81 zrlineto(i_ctx_t *i_ctx_p)
82 {
83 return common_to(i_ctx_p, gs_rlineto);
84 }
85
86 /* Common code for [r](move/line)to */
87 private int
common_to(i_ctx_t * i_ctx_p,int (* add_proc)(P3 (gs_state *,floatp,floatp)))88 common_to(i_ctx_t *i_ctx_p,
89 int (*add_proc)(P3(gs_state *, floatp, floatp)))
90 {
91 os_ptr op = osp;
92 double opxy[2];
93 int code;
94
95 if ((code = num_params(op, 2, opxy)) < 0 ||
96 (code = (*add_proc)(igs, opxy[0], opxy[1])) < 0
97 )
98 return code;
99 pop(2);
100 return 0;
101 }
102
103 /* <x1> <y1> <x2> <y2> <x3> <y3> curveto - */
104 int
zcurveto(i_ctx_t * i_ctx_p)105 zcurveto(i_ctx_t *i_ctx_p)
106 {
107 return common_curve(i_ctx_p, gs_curveto);
108 }
109
110 /* <dx1> <dy1> <dx2> <dy2> <dx3> <dy3> rcurveto - */
111 int
zrcurveto(i_ctx_t * i_ctx_p)112 zrcurveto(i_ctx_t *i_ctx_p)
113 {
114 return common_curve(i_ctx_p, gs_rcurveto);
115 }
116
117 /* Common code for [r]curveto */
118 private int
common_curve(i_ctx_t * i_ctx_p,int (* add_proc)(P7 (gs_state *,floatp,floatp,floatp,floatp,floatp,floatp)))119 common_curve(i_ctx_t *i_ctx_p,
120 int (*add_proc)(P7(gs_state *, floatp, floatp, floatp, floatp, floatp, floatp)))
121 {
122 os_ptr op = osp;
123 double opxy[6];
124 int code;
125
126 if ((code = num_params(op, 6, opxy)) < 0)
127 return code;
128 code = (*add_proc)(igs, opxy[0], opxy[1], opxy[2], opxy[3], opxy[4], opxy[5]);
129 if (code >= 0)
130 pop(6);
131 return code;
132 }
133
134 /* - closepath - */
135 int
zclosepath(i_ctx_t * i_ctx_p)136 zclosepath(i_ctx_t *i_ctx_p)
137 {
138 return gs_closepath(igs);
139 }
140
141 /* - initclip - */
142 private int
zinitclip(i_ctx_t * i_ctx_p)143 zinitclip(i_ctx_t *i_ctx_p)
144 {
145 return gs_initclip(igs);
146 }
147
148 /* - clip - */
149 private int
zclip(i_ctx_t * i_ctx_p)150 zclip(i_ctx_t *i_ctx_p)
151 {
152 return gs_clip(igs);
153 }
154
155 /* - eoclip - */
156 private int
zeoclip(i_ctx_t * i_ctx_p)157 zeoclip(i_ctx_t *i_ctx_p)
158 {
159 return gs_eoclip(igs);
160 }
161
162 /* ------ Initialization procedure ------ */
163
164 const op_def zpath_op_defs[] =
165 {
166 {"0clip", zclip},
167 {"0closepath", zclosepath},
168 {"0currentpoint", zcurrentpoint},
169 {"6curveto", zcurveto},
170 {"0eoclip", zeoclip},
171 {"0initclip", zinitclip},
172 {"2lineto", zlineto},
173 {"2moveto", zmoveto},
174 {"0newpath", znewpath},
175 {"6rcurveto", zrcurveto},
176 {"2rlineto", zrlineto},
177 {"2rmoveto", zrmoveto},
178 op_def_end(0)
179 };
180