⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gs_setpd.ps

📁 遗传算法工具箱 希望高手指点 GATOOLS
💻 PS
📖 第 1 页 / 共 2 页
字号:
 } bind def

% Select media (input or output).  The hard work is done in an operator:
%	<pagedict> <attrdict> <policydict> <keys> .matchmedia <key> true
%	<pagedict> <attrdict> <policydict> <keys> .matchmedia false
%	<pagedict> null <policydict> <keys> .matchmedia null true
/.selectmedia		% <orig> <request> <merged> <failed>     <-- retained
			%   <attrdict> <policydict> <attrkeys> <mediakey>
			%   .selectmedia
 { 5 index 5 -2 roll 4 index .matchmedia
		% Stack: orig request merged failed attrkeys mediakey
		%   (key true | false)
    { 4 index 3 1 roll put pop
    }
    {	% Adobe's implementations have a "big hairy heuristic"
	% to choose the set of keys to report as having failed the match.
	% For the moment, we report any keys that are in the request
	% and don't have the same value as in the original dictionary.
      5 index 1 index .knownget
       { 4 index 3 1 roll put }
       { 3 index exch .undef }
      ifelse
       {	% Stack: <orig> <request> <merged> <failed> <attrkey>
	 3 index 1 index .knownget
	  { 5 index 2 index .knownget { ne } { pop true } ifelse }
	  { true }
	 ifelse		% Stack: ... <failed> <attrkey> <report>
	  { 2 copy /rangecheck put }
	 if pop
       }
      forall
    }
   ifelse
 } bind def

% Apply Policies to any unprocessed failed requests.
% As we process each request entry, we replace the error name
% in the <failed> dictionary with the policy value,
% and we replace the key in the <merged> dictionary with its prior value
% (or remove it if it had no prior value).
/.applypolicies		% <orig> <merged> <failed> .applypolicies
			%   <orig> <merged'> <failed'>
 { 1 index /Policies get 1 index
    { type /integertype eq
       { pop		% already processed
       }
       { 2 copy .knownget not { 1 index /PolicyNotFound get } if
			% Stack: <orig> <merged> <failed> <Policies> <key>
			%   <policy>
	 dup 1 ne
	  {	% Set errorinfo and signal a configurationerror.
		% Note that we currently treat all Policy values other than 1
		% the same as 0.
	    pop dup 4 index exch get 2 array astore
	    $error /errorinfo 3 -1 roll put
	    cleartomark
	    /setpagedevice load /configurationerror signalerror
	  }
	  {	% Roll back the failed request to its previous status.
DEBUG { (Rolling back.\n) print pstack flush } if
	    3 index 2 index 3 -1 roll put
	    4 index 1 index .knownget
	     { 4 index 3 1 roll put }
	     { 3 index exch .undef }
	    ifelse
	  }
	 ifelse
       }
      ifelse
    }
   forall pop
 } bind def

% Prepare to present parameters to the device, by spreading them onto the
% operand stack and removing any that shouldn't be presented.
/.prepareparams		% <params> .prepareparams -mark- <key1> <value1> ...
 { mark exch dup
    {			% Stack: -mark- key1 value1 ... merged key value
      .presentspecial 2 index .knownget
       { exec { 3 -1 roll } { pop pop } ifelse }
       { 3 -1 roll }
      ifelse
    }
   forall pop
 } bind def

% Put device parameters without resetting currentpagedevice.
% (.putdeviceparams clears the current page device.)
/.putdeviceparamsonly	% <device> <Policies|null> <require_all> -mark-
			%   <key1> <value1> ... .putdeviceparamsonly
			% On success: <device> <eraseflag>
			% On failure: <device> <Policies|null> <req_all> -mark-
			%   <key1> <error1> ...
 { .currentpagedevice
    { counttomark 4 add 1 roll .putdeviceparams
      dup type /booleantype eq { 3 } { counttomark 5 add } ifelse -1 roll
      .setpagedevice
    }
    { pop .putdeviceparams
    }
   ifelse
 } bind def

% Try setting the device parameters from the merged request.
/.trysetparams		% <merged> <(ignored)> <device> <Policies>
			%   .trysetparams
 { true 4 index .prepareparams
			% Add the computed .MediaSize.
			% Stack: merged (ignored) device Policies -true-
			%   -mark- key1 value1 ...
   counttomark 5 add index .computemediasize
   exch pop exch pop /.MediaSize exch
DEBUG { (Putting.\n) print pstack flush } if
   .putdeviceparamsonly
DEBUG { (Result of putting.\n) print pstack flush } if
 } bind def

% Compute the media size and initial matrix from a merged request (after
% media selection).
/.computemediasize	% <request> .computemediasize
			%   <request> <matrix> <[width height]>
 { dup /PageSize get					% requested page size
   1 index /InputAttributes get
     2 index (%MediaSource) get get /PageSize get	% media size
							% (may be a range)
   2 index /Policies get
     dup /PageSize .knownget
      { exch pop } { /PolicyNotFound get } ifelse	% PageSize policy,
							% affects scaling
   3 index /Orientation .knownget not { null } if
   matrix .matchpagesize pop		% (can't fail)
   2 array astore
 } bind def

% ---------------- setpagedevice itself ---------------- %

/setpagedevice
 { mark exch currentpagedevice

		% Check whether we are changing OutputDevice;
		% also handle the case where the current device
		% is not a page device.
		% Stack: mark <request> <current>
DEBUG { (Checking.\n) print pstack flush } if

   dup /OutputDevice .knownget
    {		% Current device is a page device.
      2 index /OutputDevice .knownget
       {	% A specific OutputDevice was requested.
	 2 copy eq
	  { pop pop null }
	  { exch pop }
	 ifelse
       }
       { pop null
       }
      ifelse
    }
    {		% Current device is not a page device.
		% Use the default device.
      1 index /OutputDevice .knownget not { .defaultdevicename } if
    }
   ifelse
   dup null eq
    { pop
    }
    { exch pop .defaultdeviceparams
		% In case of duplicate keys, .dicttomark takes the entry
		% lower on the stack, so we can just append the defaults here.
      .requiredattrs { } forall .dicttomark
    }
   ifelse

		% Check whether a viewer wants to intervene.
		% We must check both the request (which takes precedence)
		% and the current dictionary.
		% Stack: mark <request> <orig>
   exch dup /ViewerPreProcess .knownget
    { exec }
    { 1 index /ViewerPreProcess .knownget { exec } if }
   ifelse exch

		% Construct a merged request from the actual request plus
		% any keys that should always be propagated.
		% Stack: mark <request> <orig>
DEBUG { (Merging.\n) print pstack flush } if

   exch 1 index length 1 index length add dict
   .copiedkeys
    {		% Stack: <orig> <request> <merged> <key>
      3 index 1 index .knownget { 3 copy put pop } if pop
    }
   forall
		% Stack: <orig> <request> <merged>
   dup 2 index
    {		% stack: <orig> <request> <merged> <merged> <rkey> <rvalue>
      .mergespecial 2 index .knownget { exec } if
      put dup
    }
   forall pop
		% Hack: if FIXEDRESOLUTION is true, discard any attempt to
		% change HWResolution.
   FIXEDRESOLUTION { dup /HWResolution .undef } if

		% Select input and output media.
		% Stack: mark <orig> <request> <merged>
DEBUG { (Selecting.\n) print pstack flush } if

   0 dict	% <failed>
   1 index /InputAttributes .knownget
    { 2 index /Policies get
      .inputattrkeys (%MediaSource) cvn .selectmedia
    } if
   1 index /OutputAttributes .knownget
    { 2 index /Policies get
      .outputattrkeys (%MediaDestination) cvn .selectmedia
     } if
   3 -1 roll 4 1 roll		% temporarily swap orig & request
   .applypolicies
   3 -1 roll 4 1 roll		% swap back

		% Construct the new device, and attempt to set its attributes.
		% Stack: mark <orig> <request> <merged> <failed>
DEBUG { (Constructing.\n) print pstack flush } if

   currentdevice .devicename 2 index /OutputDevice get eq
    { currentdevice }
    { 1 index /OutputDevice get finddevice }
   ifelse
		%**************** We should copy the device here,
		%**************** but since we can't close the old device,
		%**************** we don't.  This is WRONG.
	%****************copydevice
   2 index /Policies get
   .trysetparams
   dup type /booleantype ne
    {		% The request failed.
		% Stack: ... <orig> <request> <merged> <failed> <device>
		%   <Policies> true mark <name> <errorname> ...
DEBUG { (Recovering.\n) print pstack flush } if
      counttomark 4 add index
      counttomark 2 idiv { dup 4 -2 roll put } repeat
      pop pop pop
		% Stack: mark ... <orig> <request> <merged> <failed> <device>
		%   <Policies>
      6 2 roll 3 -1 roll 4 1 roll
      .applypolicies
      3 -1 roll 4 1 roll 6 -2 roll
      .trysetparams		% shouldn't fail!
      dup type /booleantype ne
       { 2 { counttomark 1 add 1 roll cleartomark } repeat
         /setpagedevice load exch signalerror
       }
      if
    }
   if

		% The attempt succeeded.  Install the new device.
		% Stack: mark ... <merged> <failed> <device> <eraseflag>
DEBUG { (Installing.\n) print pstack flush } if

   pop 2 .endpage
    { 1 true .outputpage
      (>>setpagedevice, press <return> to continue<<\n) .confirm
    }
   if
		% .setdevice clears the current page device!
   .currentpagedevice pop exch
   .setdevice pop
   .setpagedevice

		% Merge the request into the current page device.
		% Stack: mark ... <merged> <failed>
   exch currentpagedevice dup length 2 index length add dict
   .copydict .copydict
		% Initialize the default matrix, taking media matching
		% into account.
   .computemediasize pop initmatrix concat
   dup /PageOffset .knownget
    {		% Translate by the given number of 1/72" units in device X/Y.
      dup 0 get exch 1 get
      2 index /HWResolution get dup 1 get exch 0 get
      4 -1 roll mul 72 div   3 1 roll mul 72 div
      idtransform translate
    }
   if
		% We must install the new page device dictionary
		% before calling the Install procedure.
   dup .setpagedevice
   .setdefaultscreen	% Set the default screen before calling Install.
   dup /Install .knownget { exec } if
   matrix currentmatrix .setdefaultmatrix
		% Erase and initialize the page.
   erasepage initgraphics
   .beginpage

		% Clean up, calling PolicyReport if needed.
		% Stack: mark ... <failed> <merged>
DEBUG { (Finishing.\n) print pstack flush } if

   exch dup length 0 ne
    { 1 index /Policies get /PolicyReport get
      counttomark 1 add 2 roll cleartomark
      exec
    }
    { cleartomark
    }
   ifelse

 } odef

end				% level2dict
.setlanguagelevel

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -