home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_patrn.ps < prev    next >
Text File  |  2002-11-14  |  8KB  |  300 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_patrn.ps,v 1.2 2002/11/13 20:23:10 alexcher Exp $
  14. % Pattern color space method dictionary.
  15.  
  16.  
  17. % verify that Pattern color spaces are supported
  18. /.setpatternspace where
  19.   { pop }
  20.   { currentfile closefile }
  21. ifelse
  22.  
  23. .currentglobal true .setglobal
  24. .cspace_util begin
  25.  
  26. %
  27. %   <name1 | array1>   get_pattern_base_cspace   <null | name2 | array2>
  28. %
  29. % If the Pattern color space has a base color space, push that base
  30. % color space onto the stack. Otherwise, push a null object.
  31. %
  32. /get_pattern_base_cspace
  33.   {
  34.     dup type /nametype eq
  35.       { pop //null }
  36.       {
  37.         dup length 1 gt
  38.           { 1 get }
  39.           { pop //null }
  40.         ifelse
  41.       }
  42.     ifelse
  43.   }
  44. bind def
  45.  
  46.  
  47. %
  48. %   <dict>   has_base_color   <bool>
  49. %
  50. % Determine if a Pattern "color" includes a base color. This is the case
  51. % if the pattern dictionary has PatternType 1 and PaintType 2.
  52. %
  53. /has_base_color
  54.   {
  55.     dup //null eq
  56.       { pop //false }
  57.       {
  58.         dup /PatternType get 1 eq
  59.           { /PaintType get 2 eq }
  60.           { pop //false }
  61.         ifelse
  62.       }
  63.     ifelse
  64.   }
  65. bind def
  66.  
  67. %
  68. %   <c1> ... <cn>  <pattern_dict>  <pattern_cspace>
  69. %   get_pattern_base_color
  70. %   <c1> ... <cn>  <base_cspace>  true
  71. % or
  72. %   <?c1?> ... <?cn?>  <dict>  <pattern>
  73. %   get_pattern_base_color
  74. %   false
  75. %
  76. % If a pattern dictionary has a base color, set up that base color and
  77. % color space, and push true. Otherwise, just push false. It is assumed
  78. % that if the pattern includes a base color, the Pattern color space
  79. % has a base color space.
  80. %
  81. /get_pattern_base_color
  82.   {
  83.     exch //has_base_color exec
  84.       { 1 get //true }
  85.       { pop //false }
  86.     ifelse
  87.   }
  88. bind def
  89.  
  90.  
  91. colorspacedict
  92. /Pattern
  93.   mark
  94.     /cs_potential_indexed_base false
  95.     /cs_potential_pattern_base false
  96.     /cs_potential_alternate false
  97.     /cs_potential_icc_alternate false
  98.  
  99.     %
  100.     % We employ the same convention for describing the number of
  101.     % components in a Pattern color space as is used by the graphic
  102.     % library. For pattern spaces with no underlying color space,
  103.     % the result is -1. If a Pattern space has an underlying color
  104.     % space with n components, the result is -(n + 1).
  105.     %
  106.     /cs_get_ncomps
  107.       {
  108.         //get_pattern_base_cspace exec dup //null eq
  109.           { pop 0 }
  110.           //.cs_get_ncomps
  111.         ifelse
  112.         1 add neg
  113.       }
  114.     bind
  115.  
  116.     % there is no "range" for a Pattern color space
  117.     /cs_get_range { {} cvlit } bind
  118.  
  119.     /cs_get_default_color { pop //null } bind
  120.  
  121.     /cs_get_currentgray
  122.       {
  123.         //get_pattern_base_color exec
  124.           //.cs_get_currentgray
  125.           { 0 }
  126.         ifelse
  127.       }
  128.     bind
  129.  
  130.     /cs_get_currentrgb
  131.       {
  132.         //get_pattern_base_color exec
  133.           //.cs_get_currentrgb
  134.           { 0 0 0 }
  135.         ifelse
  136.       }
  137.     bind
  138.  
  139.     /cs_get_currentcmyk
  140.       {
  141.         //get_pattern_base_color exec
  142.           //.cs_get_currentcmyk
  143.           { 0 0 0 1.0 }
  144.         ifelse
  145.       }
  146.     bind
  147.  
  148.     /cs_validate
  149.       {
  150.         dup //get_pattern_base_cspace exec dup //null eq
  151.           { pop }
  152.           {
  153.             //.cs_validate exec //.cs_potential_pattern_base exec not
  154.               //setcspace_rangecheck
  155.             if
  156.           }
  157.         ifelse
  158.       }
  159.     bind
  160.  
  161.     % substitute the base space if appropriate
  162.     /cs_substitute
  163.       {
  164.         dup //get_pattern_base_cspace exec dup //null eq
  165.           { pop dup }
  166.           {
  167.             //.cs_substitute exec 2 copy eq
  168.               { pop pop dup }
  169.               {
  170.                 % retain only the new alternate space
  171.                 exch pop
  172.  
  173.                 % build all new structures in local VM
  174.                .currentglobal 3 1 roll //false .setglobal
  175.  
  176.                 % construct a new array and insert the new base color space 
  177.                 1 index dup length array copy dup 1 4 -1 roll put
  178.  
  179.                 % restore VM mode
  180.                 3 -1 roll .setglobal
  181.               }
  182.             ifelse
  183.           }
  184.         ifelse
  185.       }
  186.     bind
  187.  
  188.     /cs_prepare {}
  189.  
  190.     %
  191.     % Install the current color space.
  192.     %
  193.     % The current Ghostscript color space implementation requires that
  194.     % color spaces that provide a base or alternative color space set
  195.     % that base/alternative color space to be the current color space
  196.     % before attempting to set the original color space.
  197.     %
  198.     % In principle, the only errors that are possible for .setpatternspace
  199.     % (given that setcolorspace itself is legal) are limitcheck and/or
  200.     % VMerror. The Ghostscript implementation allows a few others, so 
  201.     % we go through the full code to restore the current color space in
  202.     % the event of an error.
  203.     %
  204.     /cs_install
  205.       {
  206.         dup //get_pattern_base_cspace exec dup //null eq
  207.           {
  208.             pop
  209.             dup type /nametype eq
  210.               { pop { /Pattern } cvlit }
  211.             if
  212.             .setpatternspace
  213.           }
  214.           {
  215.             % save the current color space
  216.             currentcolorspace
  217.  
  218.             % set the base color space as the current color space
  219.             exch //forcesetcolorspace
  220.  
  221.             % set the pattern color space; restore the earlier space on error
  222.             mark 2 index
  223.               { .setpatternspace }
  224.             stopped
  225.               { cleartomark setcolorspace stop }
  226.               { pop pop pop }
  227.             ifelse
  228.           }
  229.         ifelse
  230.       }
  231.     bind
  232.  
  233.  
  234.     %
  235.     % Pattern dictionaries generated by makepattern will include an
  236.     % Implementation entry whose value is an internal data structure.
  237.     % Such structures are given executable type names that match their
  238.     % internal structure names. The names used for pattern
  239.     % implementations are gs_pattern1_instance_t and
  240.     % gs_pattern2_instance_t. It is unfortunate to have to expose such
  241.     % internal names at this level, but not easily avoided.
  242.     %
  243.     /cs_prepare_color
  244.       {
  245.         % verify that the topmost operand is a pattern dictionary
  246.         1 index dup type /dicttype ne
  247.           {
  248.             //null ne
  249.               //setcspace_typecheck
  250.             if
  251.             pop
  252.           }
  253.           {
  254.             dup /Implementation .knownget
  255.               {
  256.                 type dup dup
  257.                 /gs_pattern1_instance_t ne exch /gs_pattern2_instance_t ne and
  258.                 exch xcheck not
  259.                 or
  260.                   //setcspace_typecheck
  261.                 if
  262.               }
  263.               //setcspace_typecheck
  264.             ifelse
  265.  
  266.             % check if base color space operands are present
  267.             dup /PatternType get 1 eq
  268.               {
  269.                 /PaintType get 2 eq
  270.                   {
  271.                     % verify that a base color space exists
  272.                     //get_pattern_base_cspace exec dup //null eq
  273.                       //setcspace_rangecheck
  274.                     if
  275.                     exch 1 index //.cs_get_ncomps exec
  276.                     exch 1 index 3 add 1 roll
  277.                     //check_num_stack exec
  278.                     //.cs_get_ncomps exec 1 add -1 roll
  279.                   }
  280.                   { pop }
  281.                 ifelse
  282.               }
  283.               { pop pop }
  284.             ifelse
  285.           }
  286.         ifelse
  287.       }
  288.     bind
  289.  
  290.     /cs_complete_setcolor //pop_1
  291.  
  292.   .dicttomark
  293. put
  294.  
  295. end     % .cspace_util
  296. .setglobal
  297.