Coverage Report

Created: 2022-10-31 07:00

/src/ghostpdl/psi/zcharx.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
/* Level 2 character operators */
18
#include "ghost.h"
19
#include "oper.h"
20
#include "gsmatrix.h"   /* for gxfont.h */
21
#include "gstext.h"
22
#include "gxfixed.h"    /* for gxfont.h */
23
#include "gxfont.h"
24
#include "gxtext.h"
25
#include "ialloc.h"
26
#include "ichar.h"
27
#include "igstate.h"
28
#include "iname.h"
29
#include "ibnum.h"
30
#include "memory_.h"
31
32
/* Common setup for glyphshow and .glyphwidth. */
33
static int
34
glyph_show_setup(i_ctx_t *i_ctx_p, gs_glyph *pglyph)
35
4
{
36
4
    os_ptr op = osp;
37
38
4
    switch (gs_currentfont(igs)->FontType) {
39
0
        case ft_CID_encrypted:
40
0
        case ft_CID_user_defined:
41
0
        case ft_CID_TrueType:
42
0
        case ft_CID_bitmap:
43
0
            check_int_leu(*op, GS_MAX_GLYPH - GS_MIN_CID_GLYPH);
44
0
            *pglyph = (gs_glyph) op->value.intval + GS_MIN_CID_GLYPH;
45
0
            break;
46
4
        default:
47
4
            check_type(*op, t_name);
48
1
            *pglyph = name_index(imemory, op);
49
4
    }
50
1
    return op_show_enum_setup(i_ctx_p);
51
4
}
52
53
/* <charname> glyphshow - */
54
static int
55
zglyphshow(i_ctx_t *i_ctx_p)
56
4
{
57
4
    gs_glyph glyph = GS_NO_GLYPH;
58
4
    gs_text_enum_t *penum;
59
4
    int code;
60
61
4
    if ((code = glyph_show_setup(i_ctx_p, &glyph)) != 0)
62
3
        return code;
63
1
    if ((code = gs_glyphshow_begin(igs, glyph, imemory_local, &penum)) < 0)
64
1
        return code;
65
0
    *(op_proc_t *)&penum->enum_client_data = zglyphshow;
66
0
    if ((code = op_show_finish_setup(i_ctx_p, penum, 1, NULL)) < 0) {
67
0
        ifree_object(penum, "zglyphshow");
68
0
        return code;
69
0
    }
70
0
    return op_show_continue_pop(i_ctx_p, 1);
71
0
}
72
73
/* <string> <numarray|numstring> xshow - */
74
/* <string> <numarray|numstring> yshow - */
75
/* <string> <numarray|numstring> xyshow - */
76
static int
77
moveshow(i_ctx_t *i_ctx_p, bool have_x, bool have_y)
78
40
{
79
40
    os_ptr op = osp;
80
40
    gs_text_enum_t *penum = NULL;
81
40
    int code = op_show_setup(i_ctx_p, op - 1);
82
40
    int format;
83
40
    uint i, size, widths_needed;
84
40
    float *values;
85
40
    bool CPSI_mode = gs_currentcpsimode(imemory);
86
87
40
    if (code != 0)
88
37
        return code;
89
3
    format = num_array_format(op);
90
3
    if (format < 0)
91
3
        return format;
92
0
    size = num_array_size(op, format);
93
0
    values = (float *)ialloc_byte_array(size, sizeof(float), "moveshow");
94
0
    if (values == 0)
95
0
        return_error(gs_error_VMerror);
96
0
    if (CPSI_mode)
97
0
        memset(values, 0, size * sizeof(values[0])); /* Safety. */
98
0
    if ((code = gs_xyshow_begin(igs, op[-1].value.bytes, r_size(op - 1),
99
0
                                (have_x ? values : (float *)0),
100
0
                                (have_y ? values : (float *)0),
101
0
                                size, imemory_local, &penum)) < 0) {
102
0
        ifree_object(values, "moveshow");
103
0
        if (penum) /* if there was an error, the text_enum may not have been allocated */
104
0
            penum->text.x_widths = penum->text.y_widths = NULL;
105
0
        return code;
106
0
    }
107
0
    if (CPSI_mode) {
108
        /* CET 13-29.PS page 2 defines a longer width array
109
           then the text requires, and CPSI silently ignores extra elements.
110
           So we need to compute exact number of characters
111
           to know how many elements to load and type check. */
112
0
        code = gs_text_count_chars(igs, gs_get_text_params(penum), imemory);
113
0
        if (code < 0)
114
0
            return code;
115
0
        widths_needed = code;
116
0
        if (have_x && have_y)
117
0
            widths_needed <<= 1;
118
0
    } else
119
0
        widths_needed = size;
120
0
    for (i = 0; i < widths_needed; ++i) {
121
0
        ref value;
122
123
0
        switch (code = num_array_get(imemory, op, format, i, &value)) {
124
0
        case t_integer:
125
0
            values[i] = (float)value.value.intval; break;
126
0
        case t_real:
127
0
            values[i] = value.value.realval; break;
128
0
        case t_null:
129
0
            code = gs_note_error(gs_error_rangecheck);
130
            /* falls through */
131
0
        default:
132
0
            ifree_object(values, "moveshow");
133
0
        penum->text.x_widths = penum->text.y_widths = NULL;
134
0
            return code;
135
0
        }
136
0
    }
137
0
    if ((code = op_show_finish_setup(i_ctx_p, penum, 2, NULL)) < 0) {
138
0
        ifree_object(values, "moveshow");
139
0
        penum->text.x_widths = penum->text.y_widths = NULL;
140
0
        return code;
141
0
    }
142
0
    pop(2);
143
0
    return op_show_continue(i_ctx_p);
144
0
}
145
static int
146
zxshow(i_ctx_t *i_ctx_p)
147
11
{
148
11
    return moveshow(i_ctx_p, true, false);
149
11
}
150
static int
151
zyshow(i_ctx_t *i_ctx_p)
152
9
{
153
9
    return moveshow(i_ctx_p, false, true);
154
9
}
155
static int
156
zxyshow(i_ctx_t *i_ctx_p)
157
20
{
158
20
    return moveshow(i_ctx_p, true, true);
159
20
}
160
161
/* ------ Initialization procedure ------ */
162
163
const op_def zcharx_op_defs[] =
164
{
165
    op_def_begin_level2(),
166
    {"1glyphshow", zglyphshow},
167
    {"2xshow", zxshow},
168
    {"2xyshow", zxyshow},
169
    {"2yshow", zyshow},
170
    op_def_end(0)
171
};