home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_ll3.ps < prev    next >
Text File  |  2003-12-13  |  11KB  |  341 lines

  1. %    Copyright (C) 1997, 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_ll3.ps,v 1.18.2.1 2003/12/12 22:07:58 giles Exp $
  14. % Initialization file for PostScript LanguageLevel 3 functions.
  15. % This file must be loaded after gs_lev2.ps and gs_res.ps.
  16. % These definitions go into ll3dict or various ProcSets.
  17. % NOTE: the interpreter creates ll3dict.
  18.  
  19. ll3dict begin
  20.  
  21. % We need LanguageLevel 2 or higher in order to have setuserparams and
  22. % defineresource.
  23. languagelevel dup 2 .max .setlanguagelevel
  24.  
  25. % ------ Idiom recognition ------ %
  26.  
  27. /IdiomRecognition false .definepsuserparam
  28.  
  29. % Modify `bind' to apply idiom recognition afterwards.
  30. /.bindscratch 128 string def
  31. % Note that since this definition of `bind' may get bound in,
  32. % it has to function properly even at lower language levels,
  33. % where IdiomRecognition may not be defined.
  34. /.bind {        % <proc> .bind <proc'>
  35.   //.bind currentuserparams /IdiomRecognition
  36.   .knownget not { false } if {
  37.     (*) {
  38.       /IdiomSet findresource
  39.       false exch {
  40.         % Stack: proc false dummykey [template substitute]
  41.     exch pop dup 1 get exch 0 get
  42.         % Stack: proc false substitute template
  43.     3 index .eqproc {
  44.       2 index gcheck 1 index gcheck not and {
  45.         pop
  46.       } {
  47.         3 -1 roll pop exch not exit
  48.       } ifelse
  49.     } {
  50.       pop
  51.     } ifelse
  52.       } forall { exit } if
  53.     } //.bindscratch /IdiomSet resourceforall
  54.   } if
  55. } odef
  56. currentdict /.bindscratch .undef
  57.  
  58. DELAYBIND NOBIND or not { 
  59.   /bind /.bind load def
  60. } if
  61.  
  62. % ------ HalftoneTypes 6, 10, 16 and HalftoneMode ------ %
  63.  
  64. % This code depends on an internal HalftoneType 7 with the following keys:
  65. %    Width, Height, Width2, Height2, TransferFunction:
  66. %      as for HalftoneType 16.
  67. %    Thresholds: a string or bytestring holding the thresholds,
  68. %      (Width x Height + Width2 x Height2) x BitsPerSample / 8 bytes,
  69. %      as for HalftoneType 16 except that the samples may be either
  70. %      8 or 16 bits wide.
  71. %    BitsPerSample: 8 or 16.
  72.  
  73. % Note that this HalftoneType never appears in halftone dictionaries given
  74. % to sethalftone, only as a component in those given to .sethalftone5,
  75. % so its numeric value can be chosen ad lib as long as it differs from the
  76. % other values that are legal in component dictionaries for .sethalftone5
  77. % (currently only 1 and 3).
  78.  
  79. /.makehalftone7 {    % <dict> <dict> <source> <Width> <Height>
  80.             %   (<Width2> <Height2> | null) <BPS> .makehalftone7
  81.             %   <setdict> <dict5> { .sethalftone5 }
  82.   8 dict begin
  83.   /HalftoneType 7 def
  84.   /BitsPerSample exch def
  85.   dup null eq {
  86.     pop 0
  87.   } {
  88.     /Height2 1 index def /Width2 2 index def mul
  89.   } ifelse 3 1 roll
  90.   /Height 1 index def
  91.   /Width 2 index def
  92.   mul add BitsPerSample 8 idiv mul .bigstring
  93.         % Stack: dict dict source str
  94.   dup type /stringtype eq { readstring } { .readbytestring } ifelse
  95.   not { /sethalftone load /rangecheck signalerror exit } if
  96.   readonly /Thresholds exch def
  97.   /TransferFunction .knownget { /TransferFunction exch def } if
  98.         % If the original Thresholds was a file, replace it with
  99.         % a new one.
  100.   dup /Thresholds get type /filetype eq {
  101.     dup /Thresholds [ Thresholds ] cvx 0 () .subfiledecode put
  102.   } if
  103.   mark /HalftoneType 5 /Default currentdict end .dicttomark
  104.   { .sethalftone5 }
  105. } bind def
  106.  
  107. /.bigstring {    % <size> .bigstring <string|bytestring>
  108.   dup 65400 gt { .bytestring } { string } ifelse
  109. } bind def
  110.  
  111. /.readbytestring {    % <source> <bytestring> .readbytestring
  112.             %   <bytestring> <filled>
  113.         % Note that since bytestrings don't implement getinterval,
  114.         % if filled is false, there is no way to tell how much
  115.         % was read.
  116.   true exch 0 1 2 index length 1 sub {
  117.         % Stack: source true str index
  118.     3 index read not { pop exch not exch exit } if
  119.     3 copy put pop pop
  120.   } for 3 -1 roll pop exch
  121. } bind def
  122.  
  123. /.sethalftone6 {    % <dict> <dict> .sethalftone6 <setdict> <dict5>
  124.             %   { .sethalftone5 }
  125.             % Keys: Width, Height, Thresholds, T'Function
  126.   dup /Thresholds get
  127.   1 index /Width get 2 index /Height get
  128.   null 8 .makehalftone7
  129. } bind def
  130.  
  131. /.sethalftone10 {    % <dict> <dict> .sethalftone10 <setdict> <dict5>
  132.             %   { .sethalftone5 }
  133.             % Keys: Xsquare, Ysquare, Thresholds, T'Function
  134.         % Note that this is the only one of these three HalftoneTypes
  135.         % that allows either a file or a string for Thresholds.
  136.   dup /Thresholds get dup type /stringtype eq { 0 () .subfiledecode } if
  137.   1 index /Xsquare get dup 3 index /Ysquare get dup
  138.   8 .makehalftone7
  139. } bind def
  140.  
  141. /.sethalftone16 {    % <dict> <dict> .sethalftone16 <setdict> <dict5>
  142.             %   { .sethalftone5 }
  143.             % Keys: Width, Height, Width2, Height2,
  144.             %   Thresholds, T'Function
  145.   dup /Thresholds get
  146.   1 index /Width get 2 index /Height get
  147.   3 index /Width2 .knownget {  % 2-rectangle case
  148.     4 index /Height2 get
  149.   } {            % 1-rectangle case
  150.     null
  151.   } ifelse 16 .makehalftone7
  152. } bind def
  153.  
  154. .halftonetypes begin
  155.   6 /.sethalftone6 load def
  156.   10 /.sethalftone10 load def
  157.   16 /.sethalftone16 load def
  158. end
  159.  
  160. % Redefine the halftone-setting operators to honor HalftoneMode.
  161. /setcolorscreen {
  162.   /HalftoneMode getuserparam 0 eq {
  163.     //setcolorscreen
  164.   } {
  165.     12 { pop } repeat .getdefaulthalftone
  166.     { //sethalftone }
  167.     { .setdefaulthalftone }
  168.     ifelse
  169.   } ifelse
  170. } odef
  171. /setscreen {
  172.   /HalftoneMode getuserparam 0 eq {
  173.     //setscreen
  174.   } {
  175.     pop pop pop .getdefaulthalftone
  176.     { //sethalftone }
  177.     { .setdefaulthalftone }
  178.     ifelse
  179.   } ifelse
  180. } odef
  181. /sethalftone {
  182.   /HalftoneMode getuserparam 0 eq {
  183.     //sethalftone
  184.   } {
  185.     pop .getdefaulthalftone
  186.     { //sethalftone }
  187.     { .setdefaulthalftone }
  188.     ifelse
  189.   } ifelse
  190. } odef
  191.  
  192. % ------ ImageTypes 3 and 4 (masked images) ------ %
  193.  
  194. .imagetypes
  195.   dup 3 /.image3 load put
  196.   dup 4 /.image4 load put
  197. % We also detect ImageType 103 here: it isn't worth making a separate file
  198. % just for this.
  199.   /.image3x where { pop dup 103 /.image3x load put } if
  200. pop
  201.  
  202. % ------ Functions ------ %
  203.  
  204. % Define the FunctionType resource category.
  205. /Generic /Category findresource dup maxlength 3 add dict .copydict begin
  206.   /InstanceType /integertype def
  207. /FunctionType currentdict end /Category defineresource pop
  208.  
  209. {0 2 3} { dup /FunctionType defineresource pop } forall
  210.  
  211. % ------ Smooth shading ------ %
  212.  
  213. % Define the ShadingType resource category.
  214. /Generic /Category findresource dup maxlength 3 add dict .copydict begin
  215.   /InstanceType /integertype def
  216. /ShadingType currentdict end /Category defineresource pop
  217.  
  218. systemdict /.shadingtypes mark        % not ll3dict
  219.   1 /.buildshading1 load
  220.   2 /.buildshading2 load
  221.   3 /.buildshading3 load
  222.   4 /.buildshading4 load
  223.   5 /.buildshading5 load
  224.   6 /.buildshading6 load
  225.   7 /.buildshading7 load
  226. .dicttomark put
  227.  
  228. systemdict /.reuseparamdict mark
  229.   /Intent 2
  230.   /AsyncRead false
  231.   /CloseSource true
  232. .dicttomark readonly put
  233. /.buildshading {    % <shadingdict> .buildshading <shading>
  234.         % Unfortunately, we always need to make the DataSource reusable,
  235.         % because if clipping is involved, even shfill may need to read
  236.         % the source data multiple times.  If it weren't for this,
  237.         % we would only need to create a reusable stream if the ultimate
  238.         % source of the data is a procedure (since the library can't
  239.         % suspend shading to do a procedure callout).
  240.   dup /DataSource .knownget {
  241.     dup type /filetype eq {
  242.       //.reuseparamdict /ReusableStreamDecode filter
  243.       .currentglobal 1 index gcheck .setglobal
  244.         % Stack: shdict rsdfile saveglobal
  245.       2 index dup length dict copy exch .setglobal
  246.       dup /DataSource 4 -1 roll put exch pop
  247.     } {
  248.       pop
  249.     } ifelse
  250.   } if
  251.     % The .buildshading operators use the current color space
  252.     % for ColorSpace.
  253.   dup /ShadingType get //.shadingtypes exch get
  254.   1 index /ColorSpace get setcolorspace exec
  255. } bind def
  256. systemdict /.reuseparamdict undef
  257.  
  258. /.buildpattern2 {    % <template> <matrix> .buildpattern2
  259.             %   <template> <pattern>
  260.     % We want to build the pattern without doing gsave/grestore,
  261.     % since we want it to load the CIE caches.
  262.   1 index /Shading get
  263.   mark currentcolor currentcolorspace
  264.   counttomark 4 add -3 roll mark 4 1 roll
  265.     % Stack: -mark- ..color.. cspace -mark- template matrix shadingdict
  266.   { .buildshading } stopped {
  267.     cleartomark setcolorspace setcolor pop stop
  268.   } if
  269.   .buildshadingpattern
  270.   3 -1 roll pop counttomark 1 add 2 roll setcolorspace setcolor pop
  271. } bind def
  272.  
  273. .patterntypes
  274.   2 /.buildpattern2 load put
  275.  
  276. /shfill {        % <shadingdict> shfill -
  277.     % Currently, .shfill requires that the color space
  278.     % in the pattern be the current color space.
  279.     % Disable overprintmode for shfill
  280.   dup gsave
  281.   0 .setoverprintmode { .buildshading .shfill } stopped
  282.   grestore { stop } if
  283.   pop
  284. } odef
  285.  
  286. % Establish an initial smoothness value that matches Adobe RIPs.
  287. 0.02 setsmoothness
  288.  
  289. % ------ DeviceN color space ------ %
  290.  
  291. %% Replace 1 (gs_ciecs3.ps)
  292. (gs_ciecs3.ps) runlibfile
  293.  
  294. %% Replace 1 (gs_devn.ps)
  295. (gs_devn.ps) runlibfile
  296.  
  297. % ------ Miscellaneous ------ %
  298.  
  299. % Make the setoverprintmode and currentoverprintmode operators visible (3015)
  300. % Because of the requirements of PDF, the .currentoverprintmode and
  301. % .setoverprintmode operators have integer parameters.  Thus wee need to
  302. % convert the Postscript bool parameters to integers.
  303. %
  304. /setoverprintmode         % bool setoverprint -
  305. {
  306.   { 1 } { 0 } ifelse        % convert bool to integer
  307.   //.setoverprintmode
  308. } odef
  309.  
  310. /currentoverprintmode         % - currentoverprintmode bool
  311. {
  312.   //.currentoverprintmode
  313.   0 ne                % convert integers to bool
  314. } odef
  315.  
  316. % Define additional user and system parameters.
  317. /HalftoneMode 0 .definepsuserparam
  318. /MaxSuperScreen 1016 .definepsuserparam
  319. pssystemparams begin        % read-only, so use .forcedef
  320.   /MaxDisplayAndSourceList 160000 .forcedef
  321. end
  322.  
  323. % Define the IdiomSet resource category.
  324. { /IdiomSet } {
  325.   /Generic /Category findresource dup maxlength 3 add dict .copydict begin
  326.     /InstanceType /dicttype def
  327.   currentdict end /Category defineresource pop
  328. } forall
  329.  
  330. /languagelevel 3 def
  331. % When running in LanguageLevel 3 mode, this interpreter is supposed to be
  332. % compatible with Adobe version 3010.
  333. /version (3010) readonly def
  334.  
  335. .setlanguagelevel
  336.  
  337. end            % ll3dict
  338.