home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_devn.ps < prev    next >
Text File  |  2002-11-14  |  6KB  |  192 lines

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