星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gs_cspace.ps 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. % Copyright (C) 2002 Aladdin Enterprises. 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_cspace.ps 10566 2009-12-29 01:17:48Z alexcher $
  16. % basic colorspace mechanism
  17. %
  18. % There have been some major changes to the PostScript colour handling.
  19. % In particular, the vast majority of the colour space code has been
  20. % converted from PostScript to C. This file has been extensively
  21. % modified, as has gs_icc.ps. The remaining PostScript files which
  22. % previously implemented colour space handling; gs_ciecs2.ps, gs_ciecs3.ps
  23. % gs_devcs.ps, gs_devn.ps, gs_devpxl.ps, gs_indxd.ps, gs_patrn.ps and
  24. % gs_sepr.ps have been superceded by the C code and removed.
  25. %
  26. % gs_lev2.ps and gs_ll3.ps have also been modified so that they no longer
  27. % attempt to execute these PostScript files.
  28. %
  29. .currentglobal true .setglobal
  30. systemdict begin
  31. %
  32. % gs_res.ps, and possibly other files, use this dictionary. Formerly
  33. % in cspace_util, moved to systemdict.
  34. %
  35. 20 dict dup /colorspacedict exch def
  36. begin % colorspacedict
  37. %
  38. % gs_res.ps uses these entries in colorspacedict
  39. % to populate the ColorSpaceFamily resource, so we need
  40. % to add the supported spaces.
  41. %
  42. /DeviceGray [] def
  43. /DeviceRGB [] def
  44. /DeviceCMYK [] def
  45. end % colorspacedict
  46. %
  47. % Global, read-only, unpacked, array-form device color spaces
  48. % We need to return an array argument in response to currentcolorspace
  49. % even if the argument presented to setcolorspace was a simple device
  50. % space name. Not only that, but in order to satisfy some Adobe
  51. % applications, it must be the *same* array every time. The only way
  52. % to do that is to define an appropriate set initial arrays and always return
  53. % one of those. These arrays are defined here.
  54. %
  55. /DeviceGray_array /DeviceGray 1 array astore readonly def
  56. /DeviceRGB_array /DeviceRGB 1 array astore readonly def
  57. /DeviceCMYK_array /DeviceCMYK 1 array astore readonly def
  58. %
  59. % - initgraphics -
  60. %
  61. % The internal routine gs_initgraphics doesn't (re)set the color space,
  62. % so we must redefine the operation to do it here.
  63. %
  64. %
  65. /initgraphics
  66. { initgraphics systemdict /DeviceGray_array get setcolorspace }
  67. .bind odef
  68. %
  69. % These routines used for the NOSUBSTDEVICECOLORS switch. This prevents
  70. % substitution of DeviceGray, DeviceRGB and DeviceCMYK with a Default*
  71. % colour space when /UseCIEColors is true. If the job includes a
  72. % definition of /DefaltGray, DefaultRGB or DefaultCMYK then it also executes
  73. % .includecolorspace to allow the device to record the substitute space.
  74. %
  75. /..page_default_spaces 3 dict def
  76. %
  77. % Used internally to retrieve any relevant default colour space.
  78. %
  79. % <Default space name> ..nosubstdevicetest false
  80. % <Default space name> [space] true
  81. %
  82. % If the boolean is true then the C code must set the additional colour space
  83. % and execute .includecolorspace before finally setting a DeviceGray space.
  84. %
  85. /..nosubstdevicetest
  86. {
  87. false mark 3 -1 roll
  88. % If we have already recorded this space, don't repeat it.
  89. systemdict /..page_default_spaces get 1 index known {
  90. cleartomark
  91. } {
  92. {
  93. % Check to see if this space was defined by defineresource, if so then
  94. % the job defined it, otherwise its the usual default, so ignore it.
  95. dup /ColorSpace resourcestatus {
  96. pop 0 eq {
  97. % Default* defined by defineresource
  98. systemdict /..page_default_spaces get 1 index //true put
  99. dup /ColorSpace findresource 4 2 roll pop pop true
  100. }{
  101. cleartomark
  102. } ifelse
  103. }{
  104. cleartomark
  105. } ifelse
  106. } stopped
  107. {cleartomark}if
  108. } ifelse
  109. }bind def
  110. %
  111. % <color_space_name> ..includecolorspace -
  112. %
  113. /..includecolorspace
  114. {
  115. % If we have already recorded this space, don't repeat it.
  116. systemdict /..page_default_spaces get 1 index known {
  117. pop
  118. } {
  119. mark exch
  120. {
  121. % Check to see if this space was defined by defineresource, if so then
  122. % the job defined it, otherwise its the usual default, so ignore it.
  123. dup /ColorSpace resourcestatus {
  124. pop 0 eq {
  125. % Job defined /Default*, so record it and allow the device access to it
  126. systemdict /..page_default_spaces get 1 index //true put
  127. gsave
  128. { dup /ColorSpace findresource //setcolorspace exec .includecolorspace
  129. } stopped pop
  130. grestore
  131. } if
  132. } if
  133. } stopped pop
  134. cleartomark
  135. } ifelse
  136. } bind def
  137. %
  138. % <color_space> <color_space_name> cs_substitute_generic <color_space1> <color_space2>
  139. %
  140. /cs_substitute_generic
  141. { .getuseciecolor
  142. {NOSUBSTDEVICECOLORS
  143. { //..includecolorspace exec dup }
  144. { /ColorSpace findresource }
  145. ifelse
  146. }
  147. { pop dup }
  148. ifelse
  149. }
  150. bind def
  151. %
  152. % <color_space> <color_space_name> cs_substitute_DeviceRGB_for_PDFX_or_PDFA <color_space1> <color_space2>
  153. %
  154. /cs_substitute_DeviceRGB_for_PDFX_or_PDFA
  155. { systemdict /PDFX .knownget not { false } if
  156. systemdict /PDFA .knownget not { false } if
  157. or {
  158. dup /ColorSpace resourcestatus {
  159. pop pop
  160. } {
  161. (Error: Need a /DefaultRGB /ColorSpace resource for generating a PDF/X or PDF/A document.) =
  162. /cs_substitute_DeviceRGB_for_PDFX_or_PDFA cvx /undefined signalerror
  163. } ifelse
  164. /ColorSpace findresource
  165. } {
  166. //cs_substitute_generic exec
  167. } ifelse
  168. } bind def
  169. end
  170. %
  171. % Set the initial device space
  172. %
  173. systemdict /DeviceGray_array get setcolorspace
  174. .setglobal