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: zdps.c 8250 2007-09-25 13:31:24Z giles $ */
15
/* Display PostScript extensions */
22
#include "gxalloc.h" /* for names_array in allocator */
23
#include "gxfixed.h" /* for gxpath.h */
25
#include "btoken.h" /* for user_names_p */
33
/* Import the procedure for constructing user paths. */
34
extern int make_upath(i_ctx_t *, ref *, const gs_state *, gx_path *, bool);
36
/* ------ Graphics state ------ */
38
/* <screen_index> <x> <y> .setscreenphase - */
40
zsetscreenphase(i_ctx_t *i_ctx_p)
46
check_type(op[-2], t_integer);
47
check_type(op[-1], t_integer);
48
check_type(*op, t_integer);
49
x = op[-1].value.intval;
51
if (x != (int)x || y != (int)y ||
52
op[-2].value.intval < -1 ||
53
op[-2].value.intval >= gs_color_select_count
55
return_error(e_rangecheck);
56
code = gs_setscreenphase(igs, (int)x, (int)y,
57
(gs_color_select_t) op[-2].value.intval);
63
/* <screen_index> .currentscreenphase <x> <y> */
65
zcurrentscreenphase(i_ctx_t *i_ctx_p)
71
check_type(*op, t_integer);
72
if (op->value.intval < -1 ||
73
op->value.intval >= gs_color_select_count
75
return_error(e_rangecheck);
76
code = gs_currentscreenphase(igs, &phase,
77
(gs_color_select_t)op->value.intval);
81
make_int(op - 1, phase.x);
82
make_int(op, phase.y);
86
/* ------ Device-source images ------ */
88
/* <dict> .image2 - */
90
zimage2(i_ctx_t *i_ctx_p)
95
check_type(*op, t_dictionary);
101
gs_image2_t_init(&image);
102
if ((code = dict_matrix_param(imemory, op, "ImageMatrix",
103
&image.ImageMatrix)) < 0 ||
104
(code = dict_find_string(op, "DataSource", &pDataSource)) < 0 ||
105
(code = dict_float_param(op, "XOrigin", 0.0,
106
&image.XOrigin)) != 0 ||
107
(code = dict_float_param(op, "YOrigin", 0.0,
108
&image.YOrigin)) != 0 ||
109
(code = dict_float_param(op, "Width", 0.0,
110
&image.Width)) != 0 ||
112
(code = dict_float_param(op, "Height", 0.0,
113
&image.Height)) != 0 ||
115
(code = dict_bool_param(op, "PixelCopy", false,
116
&image.PixelCopy)) < 0
118
return (code < 0 ? code : gs_note_error(e_rangecheck));
119
check_stype(*pDataSource, st_igstate_obj);
120
image.DataSource = igstate_ptr(pDataSource);
124
if (dict_find_string(op, "UnpaintedPath", &ignoref) > 0) {
125
check_dict_write(*op);
126
image.UnpaintedPath = gx_path_alloc(imemory,
127
".image2 UnpaintedPath");
128
if (image.UnpaintedPath == 0)
129
return_error(e_VMerror);
131
image.UnpaintedPath = 0;
133
code = process_non_source_image(i_ctx_p,
134
(const gs_image_common_t *)&image,
136
if (image.UnpaintedPath) {
141
if (gx_path_is_null(image.UnpaintedPath))
144
code = make_upath(i_ctx_p, &rupath, igs, image.UnpaintedPath,
146
gx_path_free(image.UnpaintedPath, ".image2 UnpaintedPath");
149
code = idict_put_string(op, "UnpaintedPath", &rupath);
157
/* ------ View clipping ------ */
161
zviewclip(i_ctx_t *i_ctx_p)
163
return gs_viewclip(igs);
168
zeoviewclip(i_ctx_t *i_ctx_p)
170
return gs_eoviewclip(igs);
173
/* - initviewclip - */
175
zinitviewclip(i_ctx_t *i_ctx_p)
177
return gs_initviewclip(igs);
180
/* - viewclippath - */
182
zviewclippath(i_ctx_t *i_ctx_p)
184
return gs_viewclippath(igs);
187
/* ------ User names ------ */
189
/* <index> <name> defineusername - */
191
zdefineusername(i_ctx_t *i_ctx_p)
196
check_int_ltu(op[-1], max_array_size);
197
check_type(*op, t_name);
198
if (user_names_p == 0) {
199
int code = create_names_array(&user_names_p, imemory_local,
205
if (array_get(imemory, user_names_p,
206
op[-1].value.intval, &uname) >= 0) {
207
switch (r_type(&uname)) {
211
if (name_eq(&uname, op))
215
return_error(e_invalidaccess);
217
} else { /* Expand the array. */
219
uint old_size = r_size(user_names_p);
220
uint new_size = (uint) op[-1].value.intval + 1;
224
else if (new_size > max_array_size / 2)
225
new_size = max_array_size;
226
else if (new_size >> 1 < old_size)
227
new_size = (old_size > max_array_size / 2 ? max_array_size :
232
* The user name array is allocated in stable local VM,
233
* because it must be immune to save/restore.
236
gs_ref_memory_t *slmem =
237
(gs_ref_memory_t *)gs_memory_stable(imemory_local);
240
code = gs_alloc_ref_array(slmem, &new_array, a_all, new_size,
241
"defineusername(new)");
244
refcpy_to_new(new_array.value.refs, user_names_p->value.refs,
246
refset_null(new_array.value.refs + old_size,
247
new_size - old_size);
249
gs_free_ref_array(slmem, user_names_p, "defineusername(old)");
251
ref_assign(user_names_p, &new_array);
253
ref_assign(user_names_p->value.refs + op[-1].value.intval, op);
259
/* ------ Initialization procedure ------ */
261
const op_def zdps_op_defs[] =
264
{"1.currentscreenphase", zcurrentscreenphase},
265
{"3.setscreenphase", zsetscreenphase},
266
/* Device-source images */
267
{"1.image2", zimage2},
269
{"0eoviewclip", zeoviewclip},
270
{"0initviewclip", zinitviewclip},
271
{"0viewclip", zviewclip},
272
{"0viewclippath", zviewclippath},
274
{"2defineusername", zdefineusername},