Coverage Report

Created: 2025-06-10 07:17

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