1 /* Copyright (C) 2001, Ghostgum Software Pty Ltd. All rights reserved.
2
3 This software is provided AS-IS with no warranty, either express or
4 implied.
5
6 This software is distributed under license and may not be copied,
7 modified or distributed except as expressly authorized under the terms
8 of the license contained in the file LICENSE in this distribution.
9
10 For more information about licensing, please refer to
11 http://www.ghostscript.com/licensing/. For information on
12 commercial licensing, go to http://www.artifex.com/licensing/ or
13 contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 San Rafael, CA 94903, U.S.A., +1(415)492-9861.
15 */
16
17 /* idisp.c */
18 /* $Id: idisp.c,v 1.7 2004/07/03 10:51:14 ghostgum Exp $ */
19
20 /*
21 * This allows the interpreter to set the callback structure
22 * of the "display" device. This must set at the end of
23 * initialization and before the device is used.
24 * This is harmless if the 'display' device is not included.
25 * If gsapi_set_display_callback() is not called, this code
26 * won't even be used.
27 */
28
29 #include "stdio_.h"
30 #include "stdpre.h"
31 #include "iapi.h"
32 #include "ghost.h"
33 #include "gp.h"
34 #include "gscdefs.h"
35 #include "gsmemory.h"
36 #include "gstypes.h"
37 #include "gsdevice.h"
38 #include "iref.h"
39 #include "imain.h"
40 #include "iminst.h"
41 #include "oper.h"
42 #include "ostack.h"
43 #include "gx.h"
44 #include "gxdevice.h"
45 #include "gxdevmem.h"
46 #include "idisp.h"
47 #include "gdevdevn.h"
48 #include "gsequivc.h"
49 #include "gdevdsp.h"
50 #include "gdevdsp2.h"
51
52 int
display_set_callback(gs_main_instance * minst,display_callback * callback)53 display_set_callback(gs_main_instance *minst, display_callback *callback)
54 {
55 i_ctx_t *i_ctx_p = minst->i_ctx_p;
56 bool was_open;
57 int code;
58 int exit_code = 0;
59 os_ptr op = osp;
60 gx_device *dev;
61 gx_device_display *ddev;
62
63 /* If display device exists, copy prototype if needed and return
64 * device true
65 * If it doesn't exist, return
66 * false
67 */
68 const char getdisplay[] =
69 "devicedict /display known dup { /display finddevice exch } if";
70 code = gs_main_run_string(minst, getdisplay, 0, &exit_code,
71 &minst->error_object);
72 if (code < 0)
73 return code;
74
75 op = osp;
76 check_type(*op, t_boolean);
77 if (op->value.boolval) {
78 /* display device was included in Ghostscript so we need
79 * to set the callback structure pointer within it.
80 * If the device is already open, close it before
81 * setting callback, then reopen it.
82 */
83 check_read_type(op[-1], t_device);
84 dev = op[-1].value.pdevice;
85
86 was_open = dev->is_open;
87 if (was_open) {
88 code = gs_closedevice(dev);
89 if (code < 0)
90 return_error(code);
91 }
92
93 ddev = (gx_device_display *) dev;
94 ddev->callback = callback;
95
96 if (was_open) {
97 code = gs_opendevice(dev);
98 if (code < 0) {
99 dprintf("**** Unable to open the display device, quitting.\n");
100 return_error(code);
101 }
102 }
103 pop(1); /* device */
104 }
105 pop(1); /* boolean */
106 return 0;
107 }
108
109
110