gs_devn.ps 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. % Copyright (C) 2001, 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_devn.ps,v 1.3 2002/11/13 20:23:10 alexcher Exp $
  16. % DeviceN color space method dictionary; this depends on gs_sepr.ps
  17. % verify that DeviceN and Separation color spaces are supported
  18. /.setdevicenspace where
  19. {
  20. pop
  21. /.setseparationspace where
  22. { pop //false }
  23. { //true }
  24. ifelse
  25. }
  26. { //true }
  27. ifelse
  28. { currentfile closefile }
  29. if
  30. .currentglobal true .setglobal
  31. .cspace_util begin
  32. %
  33. % <c1> ... <cm> <array> apply_devn_tint_xform <c1>' ... <cn>' <array>
  34. %
  35. % Apply the tint transformation for the DeviceN color intensity values.
  36. /apply_devn_tint_xform
  37. {
  38. dup 1 get length 1 add exch
  39. mark 2 index 2 add 2 roll
  40. index 3 get exec
  41. counttomark 2 add -2 roll pop
  42. }
  43. bind def
  44. colorspacedict
  45. /DeviceN
  46. mark
  47. /cs_potential_indexed_base true
  48. /cs_potential_pattern_base true
  49. /cs_potential_alternate false
  50. /cs_potential_icc_alternate false
  51. /cs_get_ncomps { 1 get length } bind
  52. /cs_get_range { 1 get length [ exch { 0 1 } repeat ] } bind
  53. /cs_get_default_color { 1 get length { 1 } repeat } bind
  54. /cs_get_currentgray
  55. { //apply_devn_tint_xform exec 2 get //.cs_get_currentgray exec }
  56. bind
  57. /cs_get_currentrgb
  58. { //apply_devn_tint_xform exec 2 get //.cs_get_currentrgb exec }
  59. bind
  60. /cs_get_currentcmyk
  61. { //apply_devn_tint_xform exec 2 get //.cs_get_currentcmyk exec }
  62. bind
  63. % a lot of validation is done by the cs_validate method
  64. /cs_validate
  65. {
  66. //check_array exec
  67. dup 1 get //check_array exec
  68. {
  69. type dup /nametype ne exch /stringtype ne and
  70. //setcspace_typecheck
  71. if
  72. }
  73. forall
  74. dup 2 get //.cs_validate exec //.cs_potential_alternate exec not
  75. //setcspace_rangecheck
  76. if
  77. dup 3 get //check_array exec xcheck not
  78. //setcspace_typecheck
  79. if
  80. }
  81. bind
  82. % substitute the base space if appropriate
  83. /cs_substitute
  84. {
  85. dup 2 get //.cs_substitute exec 2 copy eq
  86. { pop pop dup }
  87. {
  88. % retain only the new alternate space
  89. exch pop
  90. % build all new structures in local VM
  91. .currentglobal 3 1 roll //false .setglobal
  92. % construct a new array and insert the new base color space
  93. 1 index dup length array copy dup 2 4 -1 roll put
  94. % restore VM mode
  95. 3 -1 roll .setglobal
  96. }
  97. ifelse
  98. }
  99. bind
  100. %
  101. % The Ghostscript interpreter works better when tinttransform procedures
  102. % are translated into functions. Attempt to do that here.
  103. %
  104. /cs_prepare //converttinttransform
  105. %
  106. % Install the current color space.
  107. %
  108. % The current Ghostscript color space implementation requires that
  109. % color spaces that provide a base or alternative color space set
  110. % that base/alternative color space to be the current color space
  111. % before attempting to set the original color space.
  112. %
  113. % Beginning with Acrobat 5, PDF apparently supports 1-component
  114. % DeviceN color spaces with the single component "All" (the "PDF
  115. % Reference", 3rd ed., p. 206 still describes this as illegal).
  116. % We translate such calls to Separation color spaces.
  117. %
  118. /cs_install
  119. {
  120. % save the current color space
  121. currentcolorspace
  122. % set the base color space as the current color space
  123. 1 index 2 get //forcesetcolorspace
  124. % set the indexed color space; restore the earlier space on error
  125. mark 2 index
  126. dup 1 get dup length 1 eq exch 0 get /All eq and
  127. {
  128. dup length array copy
  129. dup 0 /Separation put
  130. dup 1 /All put
  131. { .setseparationspace }
  132. }
  133. { { .setdevicenspace } }
  134. ifelse
  135. stopped
  136. { cleartomark setcolorspace stop }
  137. { pop pop pop }
  138. ifelse
  139. }
  140. bind
  141. /cs_prepare_color { dup 1 get length //check_num_stack exec pop } bind
  142. %
  143. % If a DeviceN color space is not supported in native mode by
  144. % the current process color model, Adobe implementations will always
  145. % execute the tint transform procedure when setcolor is invoked.
  146. % Ghostscript may have turned this transform into a sampled function,
  147. % and even if this is not the case, will have sampled the transform
  148. % when the color space is first set. Some applications depend on
  149. % the Adobe behavior, so we implement it via the cs_complete_setcolor
  150. % method.
  151. %
  152. /cs_complete_setcolor
  153. {
  154. .usealternate
  155. {
  156. pop currentcolor
  157. currentcolorspace 3 get exec
  158. currentcolorspace 2 get
  159. //clear_setcolor_operands exec
  160. }
  161. { pop }
  162. ifelse
  163. }
  164. bind
  165. .dicttomark
  166. put
  167. end % .cspace_util
  168. .setglobal