Coverage Report

Created: 2025-12-31 07:31

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