Coverage Report

Created: 2025-06-10 07:06

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