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

📄 gs_init.ps

📁 GhostScript的源代码
💻 PS
📖 第 1 页 / 共 4 页
字号:
    { exch pop HWResolution 1 DEVICEYRESOLUTION put }
   if
   or { /HWResolution HWResolution } if
	% Check for device sizes specified in pixels.
   /DEVICEWIDTH where dup
    { exch pop HWSize 0 DEVICEWIDTH put }
   if
   /DEVICEHEIGHT where dup
    { exch pop HWSize 1 DEVICEHEIGHT put }
   if
   or { /HWSize HWSize } if
	% Check for device sizes specified in points.
   /DEVICEWIDTHPOINTS where dup
    { exch pop PageSize 0 DEVICEWIDTHPOINTS put }
   if
   /DEVICEHEIGHTPOINTS where dup
    { exch pop PageSize 1 DEVICEHEIGHTPOINTS put }
   if
   or { /PageSize PageSize } if
	% Check whether any parameters were set.
   dup mark eq { pop } { defaultdevice putdeviceprops } ifelse
   end
%END DEVICE
% Set any device properties defined on the command line.
% If BufferSpace is defined but not MaxBitmap, set MaxBitmap to BufferSpace.
systemdict /BufferSpace known
systemdict /MaxBitmap known not and
 { systemdict /MaxBitmap BufferSpace put
 } if
dup getdeviceprops
counttomark 2 idiv
 { systemdict 2 index known
    { pop dup load counttomark 2 roll }
    { pop pop }
   ifelse
 } repeat
counttomark dup 0 ne
 { 2 add -1 roll putdeviceprops }
 { pop pop }
ifelse
setdevice		% does an erasepage
% If the media size is fixed, update the current page device dictionary.
FIXEDMEDIA
dup { pop systemdict /.currentpagedevice known } if
dup { pop .currentpagedevice exch pop } if
not { (%END MEDIA) .skipeof } if
currentpagedevice dup length dict .copydict
dup /Policies
	% Stack: <pagedevice> <pagedevice> /Policies
1 index /InputAttributes
2 copy get dup length dict .copydict
	% Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
	%   /InputAttributes <inputattrs'>
dup 0 2 copy get dup length dict .copydict
	% Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
	%   /InputAttributes <inputattrs'> <inputattrs'> 0 <attrs0'>
dup /PageSize 7 index /PageSize get
put				% PageSize in 0
put				% 0 in InputAttributes
put				% InputAttributes in pagedevice
% Also change the page size policy so we don't get an error.
	% Stack: <pagedevice> <pagedevice> /Policies
2 copy get dup length dict .copydict
	% Stack: <pagedevice> <pagedevice> /Policies <policies'>
dup /PageSize 7 put		% PageSize in Policies
put				% Policies in pagedevice
.setpagedevice
%END MEDIA
%END DISPLAYING

(END DEVICE) VMDEBUG

% Establish a default upper limit in the character cache,
% namely, enough room for a 18-point character at the resolution
% of the default device, or for a character consuming 1% of the
% maximum cache size, whichever is larger.
mark
	% Compute limit based on character size.
  18 dup dtransform
  exch abs cvi 31 add 32 idiv 4 mul	% X raster
  exch abs cvi mul		% Y
	% Compute limit based on allocated space.
  cachestatus pop pop pop pop pop exch pop 0.01 mul cvi
  .max dup 10 idiv exch
setcacheparams
% Conditionally disable the character cache.
NOCACHE { 0 setcachelimit } if

(END CONFIG) VMDEBUG

% Establish an appropriate halftone screen and BG/UCR functions.
% We make this a procedure so we can call it again when switching devices.

% Use an ordered dither for low-resolution devices.
/.setloresscreen	% <dpi> .setloresscreen -
 {	% The following 'ordered dither' spot function was contributed by
	% Gregg Townsend.  Thanks, Gregg!
   16.001 div 0			% not 16: avoids rounding problems
    { 1 add 7.9999 mul cvi exch 1 add 7.9999 mul cvi 16 mul add <
	0E 8E 2E AE 06 86 26 A6 0C 8C 2C AC 04 84 24 A4
	CE 4E EE 6E C6 46 E6 66 CC 4C EC 6C C4 44 E4 64
	3E BE 1E 9E 36 B6 16 96 3C BC 1C 9C 34 B4 14 94
	FE 7E DE 5E F6 76 D6 56 FC 7C DC 5C F4 74 D4 54
	01 81 21 A1 09 89 29 A9 03 83 23 A3 0B 8B 2B AB
	C1 41 E1 61 C9 49 E9 69 C3 43 E3 63 CB 4B EB 6B
	31 B1 11 91 39 B9 19 99 33 B3 13 93 3B BB 1B 9B
	F1 71 D1 51 F9 79 D9 59 F3 73 D3 53 FB 7B DB 5B
	0D 8D 2D AD 05 85 25 A5 0F 8F 2F AF 07 87 27 A7
	CD 4D ED 6D C5 45 E5 65 CF 4F EF 6F C7 47 E7 67
	3D BD 1D 9D 35 B5 15 95 3F BF 1F 9F 37 B7 17 97
	FD 7D DD 5D F5 75 D5 55 FF 7F DF 5F F7 77 D7 57
	02 82 22 A2 0A 8A 2A AA 00 80 20 A0 08 88 28 A8
	C2 42 E2 62 CA 4A EA 6A C0 40 E0 60 C8 48 E8 68
	32 B2 12 92 3A BA 1A 9A 30 B0 10 90 38 B8 18 98
	F2 72 D2 52 FA 7A DA 5A F0 70 D0 50 F8 78 D8 58
     > exch get 256 div
    }
   bind
		% Use correct, per-plane screens for CMYK devices only.
   //systemdict /setcolorscreen known processcolors 4 eq and
    { 3 copy 6 copy setcolorscreen }
    { setscreen }
   ifelse
   0 array cvx settransfer	% Genoa CET won't accept a packed array!
   /setstrokeadjust where { pop true setstrokeadjust } if
 } bind def
% Use a 45-degree spot screen for high-resolution devices.
/.sethiresscreen	% <dpi> .sethiresscreen -
 {	% According to information published by Hewlett-Packard,
	% they use a 60 line screen on 300 DPI printers and
	% an 85 line screen on 600 DPI printers.
	% However, we use a 106 line screen, which produces smoother-
	% looking shades but fewer of them (32 vs. 50).
	% 46 was suggested as a good frequency value for printers
	% between 200 and 400 DPI, so we use it for lower resolutions.
	% Imagesetters need even higher frequency screens.
   //systemdict /DITHERPPI known
    { DITHERPPI
    }
    { dup cvi 100 idiv 15 .min
       {null 46 46 60 60 60 106 106 106 106 133 133 133 133 133 150}
      exch get
     }
   ifelse
   1 index 4.01 div .min	% at least a 4x4 cell
   45
	% The following screen algorithm is used by permission of the author.
    { 1 add 180 mul cos 1 0.08 add mul exch 2 add 180 mul cos 
      1 0.08 sub mul add 2 div % (C) 1989 Berthold K.P. Horn
    }
   bind
	% Determine whether we have lots of process colors.
	% If so, don't bother with color screening or gamma correction.
	% Also don't do gamma correction on very high-resolution devices.
	% (This should depend on dot gain, not resolution, but we don't
	% currently have a way to determine this.)
   currentdevice mark
     /RedValues 0 /GreenValues 0 /BlueValues 0 /GrayValues 0
   .dicttomark .getdeviceparams
   counttomark 2 idiv 1 sub { exch pop min } repeat
   exch pop exch pop 32 lt 4 index 800 lt and 5 1 roll
	% Stack: doscreen dpi freq angle proc
	% Ghostscript currently doesn't use correct, per-plane halftones
	% unless setcolorscreen has been executed.  Since these are
	% computationally much more expensive than binary halftones,
	% we check to make sure they are really warranted, i.e., we have
	% a high-resolution CMYK device (i.e., not a display) with
	% fewer than 5 bits per plane (i.e., not a true-color device).
   4 -1 roll 150 ge
    { /setcolorscreen where
       { pop //systemdict /COLORSCREEN known
	  { COLORSCREEN }
	  { 3 index }
	 ifelse
	 dup false ne
	  { 4 1 roll 3 copy 6 copy 13 -1 roll
	% For really high-quality screening on printers, we need to
	% give each plane its own screen angle.  Unfortunately,
	% this currently has very large space and time costs.
	    true eq		% true => different angles,
				% 0 => same angles
	     { { 45 90 15 75 } { 3 1 roll exch pop 12 3 roll } forall
	     }
	    if setcolorscreen
	  }
	  { pop setscreen	% false => single binary screen
	  }
	 ifelse
       }
       { setscreen		% setcolorscreen not known
       }
      ifelse
    }
    { setscreen			% not high resolution
    }
   ifelse
			% Stack: doscreen
    {	% Set the transfer function to lighten up the grays.
	% We correct at the high end so that very light grays
	% don't disappear completely if they darken <1 screen pixel.
	% Parameter values closer to 1 are better for devices with
	% less dot spreading; lower values are better with more spreading.
	% The value 0.8 is a compromise that will probably please no one!
	%
	% Because of a bug in FrameMaker, we have to accept operands
	% outside the valid range of [0..1].
      { dup dup 0.0 gt exch 1.0 lt and
	 { 0.8 exp dup dup 0.9375 gt exch 0.999 lt and	% > 15/16
	    { .currentscreenlevels 1 sub	% tweak to avoid boundary
	      1 exch div 1 exch sub .min
	    }
	   if
	 }
	if
      }
    }
    {	% Set the transfer function to the identity.
      0 array cvx		% Genoa CET won't accept a packed array!
    }
   ifelse settransfer
   /setstrokeadjust where { pop false setstrokeadjust } if
	% Increase fill adjustment so that we effectively use Adobe's
	% any-part-of-pixel rule.
   0.5 .setfilladjust
 } bind def
% Set the default screen and BG/UCR based on the device resolution and
% process color capability.
/.setdefaultbgucr systemdict /setblackgeneration known { {
  processcolors 1 eq { { } } { { pop 0.0 } } ifelse
  dup setblackgeneration setundercolorremoval
} } { {
} } ifelse bind def
/.setdefaultscreen
 {	% Compute min(|dpi x|,|dpi y|) as the definition of the resolution.
   72 72 matrix defaultmatrix dtransform abs exch abs .min
   dup 150 lt //systemdict /DITHERPPI known not and
    { .setloresscreen } { .sethiresscreen }
   ifelse .setdefaultbgucr
 } bind def
.setdefaultscreen
initgraphics

% The interpreter relies on there being at least 2 entries
% on the graphics stack.  Establish the second one now.
gsave

% Define some control sequences as no-ops.
% This is a hack to get around problems
% in some common PostScript-generating applications.
<04> cvn { } def		% Apple job separator
<0404> cvn { } def		% two of the same
<1b> cvn { } def		% MS Windows LaserJet 4 prologue
				% (UEL = ESC %-12345X)
<1b45> cvn { } def		% PJL reset prologue (ESC E)
<1b451b> cvn { } def		% PJL reset epilogue (ESC E + UEL)
<041b> cvn { } def		% MS Windows LaserJet 4 epilogue (^D + UEL)
(\001M) cvn			% TBCP initiator
 { currentfile /TBCPDecode filter cvx exec
 } bind def
/@PJL				% H-P job control
 { currentfile //=string readline { pop } if
 } bind def

% If we want a "safer" system, disable some obvious ways to cause havoc.
SAFER not { (%END SAFER) .skipeof } if
/file
 { dup (r) eq 2 index (%pipe*) .stringmatch not and
   2 index (%std*) .stringmatch or
    { file }
    { /invalidfileaccess signalerror }
   ifelse
 } .bind odef
/renamefile { /invalidfileaccess signalerror } odef
/deletefile { /invalidfileaccess signalerror } odef
/putdeviceprops
 { counttomark
   dup 2 mod 0 eq { pop /rangecheck signalerror } if
   3 2 3 2 roll
    { dup index /OutputFile eq  
       { -2 roll 
         dup () ne { /putdeviceprops load /invalidfileaccess signalerror } if
         3 -1 roll
       }
       { pop
       }
      ifelse
    } for
   putdeviceprops
 } .bind odef

%END SAFER

% If we delayed binding, make it possible to do it later.
/.bindnow {
  //systemdict begin .bindoperators end
  % Temporarily disable the typecheck error.
  errordict /typecheck 2 copy get
  errordict /typecheck { pop } put	% pop the command
  0 1 .delaycount 1 sub { .delaybind exch get .bind pop } for
  //systemdict /.delaybind {} .forceput	% reclaim the space
  //systemdict /.bindnow .forceundef	% ditto
  put
  //systemdict /.forcedef .forceundef		% remove temptation
  //systemdict /.forceput .forceundef		% ditto
  //systemdict /.forceundef .forceundef		% ditto
} .bind odef

% Turn off array packing, since some PostScript code assumes that
% procedures are writable.
false setpacking

(END INIT) VMDEBUG

/.currentuserparams where {
  pop
	% Remove real user params from psuserparams.
  mark .currentuserparams counttomark 2 idiv {
    pop psuserparams exch undef
  } repeat pop
	% Update the copy of the user parameters.
  mark .currentuserparams counttomark 2 idiv {
    userparams 3 1 roll .forceput	% userparams is read-only
  } repeat pop
	% Turn on idiom recognition, if available.
  currentuserparams /IdiomRecognition known {
    /IdiomRecognition true .definepsuserparam
  } if
  psuserparams readonly pop
  systemdict /.definepsuserparam undef
	% Save a copy of userparams for use with save/restore
	% (and, if implemented, context switching).
  .currentglobal false .setglobal
     mark .currentuserparams psuserparams { } forall .dicttomark readonly
     /userparams exch .forcedef		% systemdict is read-only
  .setglobal
} if
/.currentsystemparams where {
  pop
	% Remove real system params from pssystemparams.
  mark .currentsystemparams counttomark 2 idiv {
    pop pssystemparams exch .forceundef
  } repeat pop
} if

% Conditionally turn off image interpolation.
NOINTERPOLATE not { (%END NOINTERPOLATE) .skipeof } if
/.nointerpolate {
  dup type /dicttype eq {
    dup /Interpolate .knownget not { false } if {
      dup gcheck .currentglobal exch .setglobal
      exch dup length dict copy
      dup /Interpolate .undef
      exch .setglobal
    } if
  } if
} bind odef
/image { .nointerpolate image } bind odef
/imagemask { .nointerpolate imagemask } bind odef
%END NOINTERPOLATE

% Establish local VM as the default.
false /setglobal where { pop setglobal } { .setglobal } ifelse
$error /.nosetlocal false put

(END GLOBAL) VMDEBUG

/.savelocalstate where {
	% If we might create new contexts, save away copies of all dictionaries
	% referenced from systemdict that are stored in local VM,
	% and also save a copy of the initial gstate.
  pop .savelocalstate
} {
	% If we're *not* running in a multi-context system and FAKEFONTS is
	% defined, add the fake fonts to LocalFontDirectory.
  .definefakefonts	% current VM is local
} ifelse

% Close up systemdict.
currentdict /filterdict .undef		% bound in where needed
currentdict /.cidfonttypes .undef	% ditto
currentdict /.colorrenderingtypes .undef	% ditto
currentdict /.formtypes .undef		% ditto
currentdict /.imagetypes .undef		% ditto
currentdict /.imagemasktypes .undef	% ditto
currentdict /.patterntypes .undef	% ditto
currentdict /.shadingtypes .undef	% ditto
end

% Clean up VM, and enable GC.
/vmreclaim where
 { pop NOGC not { 2 vmreclaim 0 vmreclaim } if
 } if
DELAYBIND not {
  systemdict /.forcedef .undef		% remove temptation
  systemdict /.forceput .undef		% ditto
  systemdict /.forceundef .undef	% ditto
} if
WRITESYSTEMDICT not { systemdict readonly pop } if

(END GC) VMDEBUG

% The interpreter will run the initial procedure (start).

⌨️ 快捷键说明

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