1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
7
This software is distributed under license and may not be copied, modified
8
or distributed except as expressly authorized under the terms of that
9
license. Refer to licensing information at http://www.artifex.com/
10
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: zcharx.c 8250 2007-09-25 13:31:24Z giles $ */
15
/* Level 2 character operators */
18
#include "gsmatrix.h" /* for gxfont.h */
20
#include "gxfixed.h" /* for gxfont.h */
30
/* Common setup for glyphshow and .glyphwidth. */
32
glyph_show_setup(i_ctx_t *i_ctx_p, gs_glyph *pglyph)
36
switch (gs_currentfont(igs)->FontType) {
37
case ft_CID_encrypted:
38
case ft_CID_user_defined:
41
check_int_leu(*op, gs_max_glyph - gs_min_cid_glyph);
42
*pglyph = (gs_glyph) op->value.intval + gs_min_cid_glyph;
45
check_type(*op, t_name);
46
*pglyph = name_index(imemory, op);
48
return op_show_enum_setup(i_ctx_p);
51
/* <charname> glyphshow - */
53
zglyphshow(i_ctx_t *i_ctx_p)
56
gs_text_enum_t *penum;
59
if ((code = glyph_show_setup(i_ctx_p, &glyph)) != 0 ||
60
(code = gs_glyphshow_begin(igs, glyph, imemory, &penum)) < 0)
62
*(op_proc_t *)&penum->enum_client_data = zglyphshow;
63
if ((code = op_show_finish_setup(i_ctx_p, penum, 1, NULL)) < 0) {
64
ifree_object(penum, "zglyphshow");
67
return op_show_continue_pop(i_ctx_p, 1);
70
/* <charname> .glyphwidth <wx> <wy> */
72
zglyphwidth(i_ctx_t *i_ctx_p)
75
gs_text_enum_t *penum;
78
if ((code = glyph_show_setup(i_ctx_p, &glyph)) != 0 ||
79
(code = gs_glyphwidth_begin(igs, glyph, imemory, &penum)) < 0)
81
if ((code = op_show_finish_setup(i_ctx_p, penum, 1, finish_stringwidth)) < 0) {
82
ifree_object(penum, "zglyphwidth");
85
return op_show_continue_pop(i_ctx_p, 1);
88
/* <string> <numarray|numstring> xshow - */
89
/* <string> <numarray|numstring> yshow - */
90
/* <string> <numarray|numstring> xyshow - */
92
moveshow(i_ctx_t *i_ctx_p, bool have_x, bool have_y)
95
gs_text_enum_t *penum;
96
int code = op_show_setup(i_ctx_p, op - 1);
98
uint i, size, widths_needed;
100
extern bool CPSI_mode;
104
format = num_array_format(op);
107
size = num_array_size(op, format);
108
values = (float *)ialloc_byte_array(size, sizeof(float), "moveshow");
110
return_error(e_VMerror);
112
memset(values, 0, size * sizeof(values[0])); /* Safety. */
113
if ((code = gs_xyshow_begin(igs, op[-1].value.bytes, r_size(op - 1),
114
(have_x ? values : (float *)0),
115
(have_y ? values : (float *)0),
116
size, imemory, &penum)) < 0) {
117
ifree_object(values, "moveshow");
121
/* CET 13-29.PS page 2 defines a longer width array
122
then the text requires, and CPSI silently ignores extra elements.
123
So we need to compute exact number of characters
124
to know how many elements to load and type check. */
125
code = gs_text_count_chars(igs, gs_get_text_params(penum), imemory);
128
widths_needed = code;
129
if (have_x && have_y)
132
widths_needed = size;
133
for (i = 0; i < widths_needed; ++i) {
136
switch (code = num_array_get(imemory, op, format, i, &value)) {
138
values[i] = (float)value.value.intval; break;
140
values[i] = value.value.realval; break;
142
code = gs_note_error(e_rangecheck);
145
ifree_object(values, "moveshow");
149
if ((code = op_show_finish_setup(i_ctx_p, penum, 2, NULL)) < 0) {
150
ifree_object(values, "moveshow");
154
return op_show_continue(i_ctx_p);
157
zxshow(i_ctx_t *i_ctx_p)
159
return moveshow(i_ctx_p, true, false);
162
zyshow(i_ctx_t *i_ctx_p)
164
return moveshow(i_ctx_p, false, true);
167
zxyshow(i_ctx_t *i_ctx_p)
169
return moveshow(i_ctx_p, true, true);
172
/* ------ Initialization procedure ------ */
174
const op_def zcharx_op_defs[] =
176
op_def_begin_level2(),
177
{"1glyphshow", zglyphshow},
178
{"1.glyphwidth", zglyphwidth},
180
{"2xyshow", zxyshow},