Coverage Report

Created: 2025-06-10 07:15

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