idisp.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* Copyright (C) 2001, Ghostgum Software Pty Ltd. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author
  4. or distributor accepts any responsibility for the consequences of using it,
  5. or for whether it serves any particular purpose or works at all, unless he
  6. or she says so in writing. Refer to the Aladdin Ghostscript Free Public
  7. License (the "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License,
  9. normally in a plain ASCII text file named PUBLIC. The License grants you
  10. the right to copy, modify and redistribute AFPL Ghostscript, but only
  11. under certain conditions described in the License. Among other things, the
  12. License requires that the copyright notice and this notice be preserved on
  13. all copies.
  14. */
  15. /* idisp.c */
  16. /*
  17. * This allows the interpreter to set the callback structure
  18. * of the "display" device. This must set at the end of
  19. * initialization and before the device is used.
  20. * This is harmless if the 'display' device is not included.
  21. * If gsapi_set_display_callback() is not called, this code
  22. * won't even be used.
  23. */
  24. #include "stdio_.h"
  25. #include "stdpre.h"
  26. #include "iapi.h"
  27. #include "ghost.h"
  28. #include "gp.h"
  29. #include "gscdefs.h"
  30. #include "gsmemory.h"
  31. #include "gstypes.h"
  32. #include "gsdevice.h"
  33. #include "iref.h"
  34. #include "imain.h"
  35. #include "iminst.h"
  36. #include "oper.h"
  37. #include "ostack.h"
  38. #include "gx.h"
  39. #include "gxdevice.h"
  40. #include "gxdevmem.h"
  41. #include "idisp.h"
  42. #include "gdevdsp.h"
  43. #include "gdevdsp2.h"
  44. int
  45. display_set_callback(gs_main_instance *minst, display_callback *callback)
  46. {
  47. i_ctx_t *i_ctx_p = minst->i_ctx_p;
  48. bool was_open;
  49. int code;
  50. int exit_code = 0;
  51. os_ptr op = osp;
  52. gx_device *dev;
  53. gx_device_display *ddev;
  54. /* If display device exists, copy prototype if needed and return
  55. * device true
  56. * If it doesn't exist, return
  57. * false
  58. */
  59. const char getdisplay[] =
  60. "devicedict /display known dup { /display finddevice exch } if";
  61. code = gs_main_run_string(minst, getdisplay, 0, &exit_code,
  62. &minst->error_object);
  63. if (code < 0)
  64. return code;
  65. op = osp;
  66. check_type(*op, t_boolean);
  67. if (op->value.boolval) {
  68. /* display device was included in Ghostscript so we need
  69. * to set the callback structure pointer within it.
  70. * If the device is already open, close it before
  71. * setting callback, then reopen it.
  72. */
  73. check_read_type(op[-1], t_device);
  74. dev = op[-1].value.pdevice;
  75. was_open = dev->is_open;
  76. if (was_open) {
  77. code = gs_closedevice(dev);
  78. if (code < 0)
  79. return_error(code);
  80. }
  81. ddev = (gx_device_display *) dev;
  82. ddev->callback = callback;
  83. if (was_open) {
  84. code = gs_opendevice(dev);
  85. if (code < 0)
  86. return_error(code);
  87. }
  88. pop(1); /* device */
  89. }
  90. pop(1); /* boolean */
  91. return 0;
  92. }