1 /* Copyright (C) 1989, 1995, 1996, 1997, 1998, 1999 Aladdin Enterprises. All rights reserved.
2
3 This software is provided AS-IS with no warranty, either express or
4 implied.
5
6 This software is distributed under license and may not be copied,
7 modified or distributed except as expressly authorized under the terms
8 of the license contained in the file LICENSE in this distribution.
9
10 For more information about licensing, please refer to
11 http://www.ghostscript.com/licensing/. For information on
12 commercial licensing, go to http://www.artifex.com/licensing/ or
13 contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 San Rafael, CA 94903, U.S.A., +1(415)492-9861.
15 */
16
17 /* $Id: zpath.c,v 1.5 2002/06/16 03:43:51 lpd Exp $ */
18 /* Basic path operators */
19 #include "math_.h"
20 #include "ghost.h"
21 #include "oper.h"
22 #include "igstate.h"
23 #include "gsmatrix.h"
24 #include "gspath.h"
25 #include "store.h"
26
27 /* Forward references */
28 private int common_to(i_ctx_t *,
29 int (*)(gs_state *, floatp, floatp));
30 private int common_curve(i_ctx_t *,
31 int (*)(gs_state *, floatp, floatp, floatp, floatp, floatp, floatp));
32
33 /* - newpath - */
34 private int
znewpath(i_ctx_t * i_ctx_p)35 znewpath(i_ctx_t *i_ctx_p)
36 {
37 return gs_newpath(igs);
38 }
39
40 /* - currentpoint <x> <y> */
41 private int
zcurrentpoint(i_ctx_t * i_ctx_p)42 zcurrentpoint(i_ctx_t *i_ctx_p)
43 {
44 os_ptr op = osp;
45 gs_point pt;
46 int code = gs_currentpoint(igs, &pt);
47
48 if (code < 0)
49 return code;
50 push(2);
51 make_real(op - 1, pt.x);
52 make_real(op, pt.y);
53 return 0;
54 }
55
56 /* <x> <y> moveto - */
57 int
zmoveto(i_ctx_t * i_ctx_p)58 zmoveto(i_ctx_t *i_ctx_p)
59 {
60 return common_to(i_ctx_p, gs_moveto);
61 }
62
63 /* <dx> <dy> rmoveto - */
64 int
zrmoveto(i_ctx_t * i_ctx_p)65 zrmoveto(i_ctx_t *i_ctx_p)
66 {
67 return common_to(i_ctx_p, gs_rmoveto);
68 }
69
70 /* <x> <y> lineto - */
71 int
zlineto(i_ctx_t * i_ctx_p)72 zlineto(i_ctx_t *i_ctx_p)
73 {
74 return common_to(i_ctx_p, gs_lineto);
75 }
76
77 /* <dx> <dy> rlineto - */
78 int
zrlineto(i_ctx_t * i_ctx_p)79 zrlineto(i_ctx_t *i_ctx_p)
80 {
81 return common_to(i_ctx_p, gs_rlineto);
82 }
83
84 /* Common code for [r](move/line)to */
85 private int
common_to(i_ctx_t * i_ctx_p,int (* add_proc)(gs_state *,floatp,floatp))86 common_to(i_ctx_t *i_ctx_p,
87 int (*add_proc)(gs_state *, floatp, floatp))
88 {
89 os_ptr op = osp;
90 double opxy[2];
91 int code;
92
93 if ((code = num_params(op, 2, opxy)) < 0 ||
94 (code = (*add_proc)(igs, opxy[0], opxy[1])) < 0
95 )
96 return code;
97 pop(2);
98 return 0;
99 }
100
101 /* <x1> <y1> <x2> <y2> <x3> <y3> curveto - */
102 int
zcurveto(i_ctx_t * i_ctx_p)103 zcurveto(i_ctx_t *i_ctx_p)
104 {
105 return common_curve(i_ctx_p, gs_curveto);
106 }
107
108 /* <dx1> <dy1> <dx2> <dy2> <dx3> <dy3> rcurveto - */
109 int
zrcurveto(i_ctx_t * i_ctx_p)110 zrcurveto(i_ctx_t *i_ctx_p)
111 {
112 return common_curve(i_ctx_p, gs_rcurveto);
113 }
114
115 /* Common code for [r]curveto */
116 private int
common_curve(i_ctx_t * i_ctx_p,int (* add_proc)(gs_state *,floatp,floatp,floatp,floatp,floatp,floatp))117 common_curve(i_ctx_t *i_ctx_p,
118 int (*add_proc)(gs_state *, floatp, floatp, floatp, floatp, floatp, floatp))
119 {
120 os_ptr op = osp;
121 double opxy[6];
122 int code;
123
124 if ((code = num_params(op, 6, opxy)) < 0)
125 return code;
126 code = (*add_proc)(igs, opxy[0], opxy[1], opxy[2], opxy[3], opxy[4], opxy[5]);
127 if (code >= 0)
128 pop(6);
129 return code;
130 }
131
132 /* - closepath - */
133 int
zclosepath(i_ctx_t * i_ctx_p)134 zclosepath(i_ctx_t *i_ctx_p)
135 {
136 return gs_closepath(igs);
137 }
138
139 /* - initclip - */
140 private int
zinitclip(i_ctx_t * i_ctx_p)141 zinitclip(i_ctx_t *i_ctx_p)
142 {
143 return gs_initclip(igs);
144 }
145
146 /* - clip - */
147 private int
zclip(i_ctx_t * i_ctx_p)148 zclip(i_ctx_t *i_ctx_p)
149 {
150 return gs_clip(igs);
151 }
152
153 /* - eoclip - */
154 private int
zeoclip(i_ctx_t * i_ctx_p)155 zeoclip(i_ctx_t *i_ctx_p)
156 {
157 return gs_eoclip(igs);
158 }
159
160 /* ------ Initialization procedure ------ */
161
162 const op_def zpath_op_defs[] =
163 {
164 {"0clip", zclip},
165 {"0closepath", zclosepath},
166 {"0currentpoint", zcurrentpoint},
167 {"6curveto", zcurveto},
168 {"0eoclip", zeoclip},
169 {"0initclip", zinitclip},
170 {"2lineto", zlineto},
171 {"2moveto", zmoveto},
172 {"0newpath", znewpath},
173 {"6rcurveto", zrcurveto},
174 {"2rlineto", zrlineto},
175 {"2rmoveto", zrmoveto},
176 op_def_end(0)
177 };
178