idisp.c 2.8 KB

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