home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_dps2.ps < prev    next >
Text File  |  2002-02-22  |  7KB  |  217 lines

  1. %    Copyright (C) 1990, 1996, 1997, 1998, 2000 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_dps2.ps,v 1.5 2002/02/21 21:49:28 giles Exp $
  14. % Initialization file for basic Display PostScript functions
  15. % that are also included in Level 2.
  16.  
  17. level2dict begin
  18.  
  19. % ------ Halftones ------ %
  20.  
  21. /.makestackdict
  22.     { { counttomark -1 roll } forall .dicttomark
  23.     } bind def
  24. /currenthalftone        % - currenthalftone <dict>
  25.     { mark .currenthalftone
  26.        { { exch pop }        % halftone
  27.          { /HalftoneType 1        % screen
  28.         { /Frequency /Angle /SpotFunction }
  29.            .makestackdict
  30.          }
  31.          { /HalftoneType 2        % colorscreen
  32.         { /RedFrequency /RedAngle /RedSpotFunction
  33.           /GreenFrequency /GreenAngle /GreenSpotFunction
  34.           /BlueFrequency /BlueAngle /BlueSpotFunction
  35.           /GrayFrequency /GrayAngle /GraySpotFunction
  36.         }
  37.            .makestackdict
  38.          }
  39.        }
  40.       exch get exec
  41.     } odef
  42. % Define sethalftone so it converts types 1-4 to type 5.
  43. /.makehalftoneRGBV {    % <dict> <type> <keys> <keysRGBV>
  44.   4 -1 roll exch { 1 index exch get exch } forall 15 1 roll
  45.   14 -2 roll mark 15 1 roll { /Gray /Blue /Green /Red } {
  46.         % stack: v0 v1 v2 type keys comp
  47.     mark
  48.     2 index 0 get 8 -1 roll
  49.     4 index 1 get 9 -1 roll
  50.     6 index 2 get 10 -1 roll
  51.         % stack: type keys comp mark k0 v0 k1 v1 k2 v2
  52.     /HalftoneType 10 index .dicttomark
  53.     counttomark 2 roll
  54.   } forall pop pop
  55.   /Default 1 index .dicttomark exch pop { .sethalftone5 }
  56. } bind def
  57.  
  58. % The value of each entry in .halftonetypes is a procedure:
  59. %    <setdict> <htdict> <<proc>> <setdict'> <htdict'> <sethalftoneproc>
  60. % This allows us to use these procedures both for actually implementing
  61. % sethalftone and for converting subsidiary dictionaries of HalftoneType 5
  62. % halftones.
  63. systemdict begin
  64. 15 dict /.halftonetypes 1 index def begin
  65.   1 {
  66.     mark exch /Default exch .dicttomark { .sethalftone5 }
  67.   } bind def
  68.   2 {
  69.     1 { /Frequency /Angle /SpotFunction } {
  70.       /RedFrequency /RedAngle /RedSpotFunction
  71.       /GreenFrequency /GreenAngle /GreenSpotFunction
  72.       /BlueFrequency /BlueAngle /BlueSpotFunction
  73.       /GrayFrequency /GrayAngle /GraySpotFunction
  74.     } .makehalftoneRGBV
  75.   } bind def
  76.   3 {
  77.     mark exch /Default exch .dicttomark { .sethalftone5 }
  78.   } bind def
  79.   4 {
  80.     3 { /Width /Height /Thresholds } {
  81.       /RedWidth /RedHeight /RedThresholds
  82.       /GreenWidth /GreenHeight /GreenThresholds
  83.       /BlueWidth /BlueHeight /BlueThresholds
  84.       /GrayWidth /GrayHeight /GrayThresholds
  85.     } .makehalftoneRGBV
  86.   } bind def
  87.   5 {
  88.     pop dup length dict copy
  89.     mark 1 index {
  90.         % Even HalftoneType 5 dictionaries have entries other than
  91.         % subsidiary halftone dictionaries.
  92.       dup type /dicttype ne {
  93.     0
  94.       } {
  95.     dup /HalftoneType .knownget not { 0 } if
  96.       } ifelse dup 5 gt {
  97.         % Stack: dict mark ... keyN dictN httypeN
  98.         % Assume that all HalftoneTypes > 5 convert to 5.
  99.     1 index 3 1 roll
  100.     //.halftonetypes exch get exec pop /Default get
  101.         % Stack: dict mark ... keyN setdict'N htdict'N
  102.     counttomark 1 add index 3 index 4 -1 roll put
  103.       } {
  104.     pop
  105.       } ifelse
  106.     } forall .dicttomark { .sethalftone5 }
  107.   } bind def
  108. end
  109. end
  110. /sethalftone {        % <dict> sethalftone -
  111.     % We must create the new dictionary in the same VM as the
  112.     % operand; otherwise, invalidaccess errors may occur.
  113.   .currentglobal 1 index dup gcheck .setglobal
  114.   dup //.halftonetypes 1 index /HalftoneType get get exec exec
  115.   .setglobal pop
  116. } odef
  117. % Redefine setscreen and setcolorscreen to recognize halftone dictionaries,
  118. % and to insert the Frequency and Angle into Type 1 halftones, per
  119. % Adobe TN 5085.
  120. /.fixsethalftonescreen        % <freq> <angle> <dict> .fix...screen
  121.                 %   <freq> <angle> <dict> <dict'>
  122.  { dup dup /HalftoneType get 1 eq
  123.     { dup wcheck not { dup length .copydict } if
  124.       dup /Frequency 5 index put
  125.       dup /Angle 4 index put
  126.     }
  127.    if
  128.  } bind def
  129. /setscreen        % <ignore*2> <dict> setscreen -
  130.     { dup type /dicttype eq
  131.        { .fixsethalftonescreen sethalftone pop pop pop }
  132.        { //setscreen }
  133.       ifelse
  134.     } odef
  135. /setcolorscreen        % <ignore*11> <dict> setcolorscreen -
  136.     { dup type /dicttype eq
  137.        { .fixsethalftonescreen sethalftone 12 { pop } repeat }
  138.        { //setcolorscreen }
  139.       ifelse
  140.     } odef
  141. % Redefine currentscreen and currentcolorscreen to extract the Frequency
  142. % and Angle from Type 1 halftones, per Adobe TN 5085.
  143. /.fixcurrenthalftonescreen    % <dict> .fix... <freq> <angle> <proc>
  144.  { dup /HalftoneType get 1 eq
  145.     { dup /Frequency get 1 index /Angle get }
  146.     { 60 0 }
  147.    ifelse 3 2 roll
  148.  } bind def
  149. /currentscreen        % - currentscreen 60 0 <dict>
  150.     { .currenthalftone
  151.        { { .fixcurrenthalftonescreen }    % halftone
  152.          { }                % screen
  153.          { 12 3 roll 9 { pop } repeat    % colorscreen
  154.            dup type /dicttype eq { .fixcurrenthalftonescreen } if
  155.          }
  156.        }
  157.       exch get exec
  158.     } odef
  159. /currentcolorscreen    % - currentcolorscreen (60 0 <dict>)*4
  160.     { .currenthalftone
  161.        { { .fixcurrenthalftonescreen 3 copy 6 copy }    % halftone
  162.          { 3 copy 6 copy }            % screen
  163.          { }                % colorscreen
  164.        }
  165.       exch get exec
  166.     } odef
  167.  
  168. % ------ User objects ------ %
  169.  
  170. /.UserObjects {
  171.   .userdict /UserObjects
  172. } odef
  173. % In order to get proper error recovery behavior, we need to be careful
  174. % not to pop any operands from the stack until we're done.
  175. % The code below faithfully duplicates the apparent array-growing
  176. % behavior of Adobe interpreters.
  177. /defineuserobject {        % <index> <value> defineuserobject -
  178.   .UserObjects .knownget {
  179.     length dup 3 index le {
  180.         % Stack: index value len
  181.       2 index eq { 1 index 2 mul } { 1 index 1 add } ifelse
  182.       .localvmarray .UserObjects get
  183.       1 index copy pop
  184.       .UserObjects 3 -1 roll put
  185.     } {
  186.       pop
  187.     } ifelse
  188.   } {
  189.     .UserObjects 3 index 1 add 10 .max .localvmarray put
  190.   } ifelse
  191.   .UserObjects get 2 index 2 index put pop pop
  192. } odef
  193. /execuserobject {        % <index> execuserobject -
  194.   .UserObjects get 1 index get exch pop exec
  195. } odef
  196. /undefineuserobject {        % <index> undefineuserobject -
  197.   .UserObjects get 1 index null put pop
  198. } odef
  199.  
  200. % ------ Cache control ------ %
  201.  
  202. % Dummy definitions for cache control operators
  203.  
  204. /ucachestatus {            % - ucachestatus -mark- ? ? ? ? <size>
  205.     mark 0 0 0 0 .userdict /.ucachesize .knownget not { 0 } if
  206. } odef
  207. /setucacheparams {        % -mark- ... <size> setucacheparams -
  208.         % Provoke an appropriate error if needed.
  209.     counttomark 1 lt { () 0 get } if
  210.     0 or .userdict /.ucachesize 2 index 0 .max put cleartomark
  211. } odef
  212.  
  213. end                % level2dict
  214.