Coverage Report

Created: 2022-10-31 07:00

/src/ghostpdl/psi/zpath.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2021 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.,  1305 Grant Avenue - Suite 200, Novato,
13
   CA 94945, U.S.A., +1(415)492-9861, 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
110k
{
36
110k
    return gs_newpath(igs);
37
110k
}
38
39
/* - currentpoint <x> <y> */
40
static int
41
zcurrentpoint(i_ctx_t *i_ctx_p)
42
30.5k
{
43
30.5k
    os_ptr op = osp;
44
30.5k
    gs_point pt;
45
30.5k
    int code = gs_currentpoint(igs, &pt);
46
47
30.5k
    if (code < 0)
48
14
        return code;
49
30.5k
    push(2);
50
30.5k
    make_real(op - 1, pt.x);
51
30.5k
    make_real(op, pt.y);
52
30.5k
    return 0;
53
30.5k
}
54
55
/* - .currentpoint_valid <bool> */
56
static int
57
zcurrentpoint_valid(i_ctx_t *i_ctx_p)
58
0
{
59
0
    os_ptr op = osp;
60
0
    gs_point pt;
61
0
    int code = gs_currentpoint(igs, &pt);
62
63
0
    push(1);
64
0
    make_bool(op, code == 0);
65
0
    return 0;
66
0
}
67
68
/* <x> <y> moveto - */
69
int
70
zmoveto(i_ctx_t *i_ctx_p)
71
509k
{
72
509k
    return common_to(i_ctx_p, gs_moveto);
73
509k
}
74
75
/* <dx> <dy> rmoveto - */
76
int
77
zrmoveto(i_ctx_t *i_ctx_p)
78
3.84k
{
79
3.84k
    return common_to(i_ctx_p, gs_rmoveto);
80
3.84k
}
81
82
/* <x> <y> lineto - */
83
int
84
zlineto(i_ctx_t *i_ctx_p)
85
901k
{
86
901k
    return common_to(i_ctx_p, gs_lineto);
87
901k
}
88
89
/* <dx> <dy> rlineto - */
90
int
91
zrlineto(i_ctx_t *i_ctx_p)
92
13.1k
{
93
13.1k
    return common_to(i_ctx_p, gs_rlineto);
94
13.1k
}
95
96
/* Common code for [r](move/line)to */
97
static int
98
common_to(i_ctx_t *i_ctx_p,
99
          int (*add_proc)(gs_gstate *, double, double))
100
1.42M
{
101
1.42M
    os_ptr op = osp;
102
1.42M
    double opxy[2];
103
1.42M
    int code;
104
105
1.42M
    if ((code = num_params(op, 2, opxy)) < 0 ||
106
1.42M
        (code = (*add_proc)(igs, opxy[0], opxy[1])) < 0
107
1.42M
        )
108
145
        return code;
109
1.42M
    pop(2);
110
1.42M
    return 0;
111
1.42M
}
112
113
/* <x1> <y1> <x2> <y2> <x3> <y3> curveto - */
114
int
115
zcurveto(i_ctx_t *i_ctx_p)
116
333k
{
117
333k
    return common_curve(i_ctx_p, gs_curveto);
118
333k
}
119
120
/* <dx1> <dy1> <dx2> <dy2> <dx3> <dy3> rcurveto - */
121
int
122
zrcurveto(i_ctx_t *i_ctx_p)
123
20
{
124
20
    return common_curve(i_ctx_p, gs_rcurveto);
125
20
}
126
127
/* Common code for [r]curveto */
128
static int
129
common_curve(i_ctx_t *i_ctx_p,
130
             int (*add_proc)(gs_gstate *, double, double, double, double, double, double))
131
333k
{
132
333k
    os_ptr op = osp;
133
333k
    double opxy[6];
134
333k
    int code;
135
136
333k
    if ((code = num_params(op, 6, opxy)) < 0)
137
41
        return code;
138
333k
    code = (*add_proc)(igs, opxy[0], opxy[1], opxy[2], opxy[3], opxy[4], opxy[5]);
139
333k
    if (code >= 0)
140
333k
        pop(6);
141
333k
    return code;
142
333k
}
143
144
/* - closepath - */
145
int
146
zclosepath(i_ctx_t *i_ctx_p)
147
428k
{
148
428k
    return gs_closepath(igs);
149
428k
}
150
151
/* - initclip - */
152
static int
153
zinitclip(i_ctx_t *i_ctx_p)
154
152
{
155
152
    return gs_initclip(igs);
156
152
}
157
158
/* - clip - */
159
static int
160
zclip(i_ctx_t *i_ctx_p)
161
1.37k
{
162
1.37k
    return gs_clip(igs);
163
1.37k
}
164
165
/* - eoclip - */
166
static int
167
zeoclip(i_ctx_t *i_ctx_p)
168
219
{
169
219
    return gs_eoclip(igs);
170
219
}
171
172
/* ------ Initialization procedure ------ */
173
174
const op_def zpath_op_defs[] =
175
{
176
    {"0clip", zclip},
177
    {"0closepath", zclosepath},
178
    {"0currentpoint", zcurrentpoint},
179
    {"0.currentpoint_valid", zcurrentpoint_valid},
180
    {"6curveto", zcurveto},
181
    {"0eoclip", zeoclip},
182
    {"0initclip", zinitclip},
183
    {"2lineto", zlineto},
184
    {"2moveto", zmoveto},
185
    {"0newpath", znewpath},
186
    {"6rcurveto", zrcurveto},
187
    {"2rlineto", zrlineto},
188
    {"2rmoveto", zrmoveto},
189
    op_def_end(0)
190
};