Coverage Report

Created: 2025-06-10 07:19

/src/ghostpdl/psi/zpath.c
Line
Count
Source
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
536k
{
36
536k
    return gs_newpath(igs);
37
536k
}
38
39
/* - currentpoint <x> <y> */
40
static int
41
zcurrentpoint(i_ctx_t *i_ctx_p)
42
12.5k
{
43
12.5k
    os_ptr op = osp;
44
12.5k
    gs_point pt;
45
12.5k
    int code = gs_currentpoint(igs, &pt);
46
47
12.5k
    if (code < 0)
48
2
        return code;
49
12.5k
    push(2);
50
12.5k
    make_real(op - 1, pt.x);
51
12.5k
    make_real(op, pt.y);
52
12.5k
    return 0;
53
12.5k
}
54
55
/* <x> <y> moveto - */
56
int
57
zmoveto(i_ctx_t *i_ctx_p)
58
659k
{
59
659k
    return common_to(i_ctx_p, gs_moveto);
60
659k
}
61
62
/* <dx> <dy> rmoveto - */
63
int
64
zrmoveto(i_ctx_t *i_ctx_p)
65
1.54k
{
66
1.54k
    return common_to(i_ctx_p, gs_rmoveto);
67
1.54k
}
68
69
/* <x> <y> lineto - */
70
int
71
zlineto(i_ctx_t *i_ctx_p)
72
1.09M
{
73
1.09M
    return common_to(i_ctx_p, gs_lineto);
74
1.09M
}
75
76
/* <dx> <dy> rlineto - */
77
int
78
zrlineto(i_ctx_t *i_ctx_p)
79
25.3k
{
80
25.3k
    return common_to(i_ctx_p, gs_rlineto);
81
25.3k
}
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.78M
{
88
1.78M
    os_ptr op = osp;
89
1.78M
    double opxy[2];
90
1.78M
    int code;
91
92
1.78M
    check_op(2);
93
1.78M
    if ((code = num_params(op, 2, opxy)) < 0 ||
94
1.78M
        (code = (*add_proc)(igs, opxy[0], opxy[1])) < 0
95
1.78M
        )
96
6
        return code;
97
1.78M
    pop(2);
98
1.78M
    return 0;
99
1.78M
}
100
101
/* <x1> <y1> <x2> <y2> <x3> <y3> curveto - */
102
int
103
zcurveto(i_ctx_t *i_ctx_p)
104
759k
{
105
759k
    return common_curve(i_ctx_p, gs_curveto);
106
759k
}
107
108
/* <dx1> <dy1> <dx2> <dy2> <dx3> <dy3> rcurveto - */
109
int
110
zrcurveto(i_ctx_t *i_ctx_p)
111
3
{
112
3
    return common_curve(i_ctx_p, gs_rcurveto);
113
3
}
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
759k
{
120
759k
    os_ptr op = osp;
121
759k
    double opxy[6];
122
759k
    int code;
123
124
759k
    check_op(6);
125
759k
    if ((code = num_params(op, 6, opxy)) < 0)
126
3
        return code;
127
759k
    code = (*add_proc)(igs, opxy[0], opxy[1], opxy[2], opxy[3], opxy[4], opxy[5]);
128
759k
    if (code >= 0)
129
759k
        pop(6);
130
759k
    return code;
131
759k
}
132
133
/* - closepath - */
134
int
135
zclosepath(i_ctx_t *i_ctx_p)
136
288k
{
137
288k
    return gs_closepath(igs);
138
288k
}
139
140
/* - initclip - */
141
static int
142
zinitclip(i_ctx_t *i_ctx_p)
143
14
{
144
14
    return gs_initclip(igs);
145
14
}
146
147
/* - clip - */
148
static int
149
zclip(i_ctx_t *i_ctx_p)
150
28
{
151
28
    return gs_clip(igs);
152
28
}
153
154
/* - eoclip - */
155
static int
156
zeoclip(i_ctx_t *i_ctx_p)
157
4
{
158
4
    return gs_eoclip(igs);
159
4
}
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
};