1
0

gs_dscp.ps 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. % Copyright (C) 2000 Artifex Software Inc. 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. % $Id: gs_dscp.ps,v 1.6 2002/02/21 21:49:28 giles Exp $
  16. % Postscript interface routines to DSC parser
  17. /send_orientation { % <orientation> send_orientation -
  18. % .parse_dsc_comments returns -1 for an Orientation key with an
  19. % unrecognized value.
  20. dup 0 ge {
  21. << /Orientation 2 index >> setpagedevice
  22. } if pop
  23. } bind def
  24. % This dictionary contains local handlers for DSC comments.
  25. % See header in zdscpars.c for more information.
  26. % <dsc_dict> handler <dsc_dict>
  27. /DSCparseprocs mark
  28. /Orientation { dup /Orientation get send_orientation } bind
  29. /PageOrientation { dup /PageOrientation .knownget { send_orientation }
  30. { dup /Orientation .knownget { send_orientation } if }
  31. ifelse } bind
  32. /Page { dup /Orientation .knownget { send_orientation } if } bind
  33. /NOP { } bind
  34. .dicttomark readonly def
  35. % This procedure is called whenever a DSC comment is found by the interpreter
  36. /do_parse_dsc false def
  37. /parse_dsc { % <file> <DSC string> [<prev proc>]
  38. % parse_dsc -
  39. % Run any previously installed parser.
  40. 0 get dup null eq { pop } { 3 copy exec pop } ifelse
  41. do_parse_dsc { % Check if this parser is enabled
  42. currentglobal true setglobal % Go to global VM, save old state
  43. 3 1 roll % Put old VM state under <file> <string>
  44. dsc_dict exch % <VM state> <file> <dict> <string>
  45. .parse_dsc_comments % <VM state> <file> <dict> <DSC name>
  46. 4 -1 roll % Get old VM state from under <file> <dict> <DSC name>
  47. setglobal % restore previous VM state
  48. //DSCparseprocs exch .knownget { % Check DSC name against local handler list
  49. exec % execute any local handler
  50. } if
  51. } if
  52. pop pop % remove file, dict
  53. } bind def
  54. % Check whether the currently installed parser is the one defined in this file.
  55. /.using_parse_dsc { % - .using_parse_dsc <proc> <using?>
  56. currentuserparams /ProcessDSCComment get
  57. dup null eq { pop {{//null} //parse_dsc exec} } if
  58. dup length 3 eq {
  59. dup dup length 1 sub get /parse_dsc load eq
  60. } {
  61. false
  62. } ifelse
  63. } bind def
  64. % Establish a binding for dsc_dict.
  65. userdict /dsc_dict null put
  66. % - dsc_init -
  67. /dsc_init { % Initialize DSC parser
  68. currentglobal true setglobal
  69. /dsc_dict 50 dict store % Size must be large enough for all DSC values
  70. dsc_dict .initialize_dsc_parser
  71. .using_parse_dsc {
  72. % Already using this parser.
  73. pop
  74. } {
  75. % Encapsulate the previous parser. We know it is in global VM:
  76. % allocate the new one in global VM as well.
  77. 1 array astore
  78. /parse_dsc load /exec load 3 array astore cvx readonly
  79. << /ProcessDSCComment 3 -1 roll >>
  80. setuserparams
  81. } ifelse
  82. setglobal
  83. /do_parse_dsc true def
  84. } bind def
  85. % Enable the DSC parser defined in this file.
  86. % - enable_dsc -
  87. /enable_dsc {
  88. dsc_init
  89. } bind def
  90. % Disable the DSC parser defined in this file.
  91. % - disable_dsc -
  92. /disable_dsc {
  93. % There might be another parser installed: if so, restore it.
  94. % (If it has encapsulated our parser, we can't.)
  95. .using_parse_dsc {
  96. % Restore the parser we encapsulated.
  97. 0 get 0 get
  98. currentglobal true setglobal exch
  99. << /ProcessDSCComment 3 -1 roll >>
  100. exch setglobal setuserparams
  101. } {
  102. pop
  103. } ifelse
  104. % If we couldn't restore the old parser, at least disable ours.
  105. /do_parse_dsc false def
  106. } bind def