summaryrefslogtreecommitdiff
path: root/Master/xemtex/gslib/gs_dps2.ps
blob: c84b5be9b65e440d848801b0212a3dd08461f4d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
%    Copyright (C) 1990, 1996, 1997, 1998, 2000 Aladdin Enterprises.  All rights reserved.
% 
% This program is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by the
% Free Software Foundation; either version 2 of the License, or (at your
% option) any later version.
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
% Public License for more details.
%
% You should have received a copy of the GNU General Public License along
% with this program; if not, write to the Free Software Foundation, Inc.,
% 59 Temple Place, Suite 330, Boston, MA, 02111-1307.

% $Id: gs_dps2.ps,v 1.3.4.1.2.1 2003/04/12 14:02:38 giles Exp $
% Initialization file for basic Display PostScript functions
% that are also included in Level 2.

level2dict begin

% ------ Halftones ------ %

/.makestackdict
	{ { counttomark -1 roll } forall .dicttomark
	} bind def
/currenthalftone		% - currenthalftone <dict>
	{ mark .currenthalftone
	   { { exch pop }		% halftone
	     { /HalftoneType 1		% screen
		{ /Frequency /Angle /SpotFunction }
	       .makestackdict
	     }
	     { /HalftoneType 2		% colorscreen
		{ /RedFrequency /RedAngle /RedSpotFunction
		  /GreenFrequency /GreenAngle /GreenSpotFunction
		  /BlueFrequency /BlueAngle /BlueSpotFunction
		  /GrayFrequency /GrayAngle /GraySpotFunction
		}
	       .makestackdict
	     }
	   }
	  exch get exec
	} odef
% Define sethalftone so it converts types 1-4 to type 5.
/.makehalftoneRGBV {	% <dict> <type> <keys> <keysRGBV>
  4 -1 roll exch { 1 index exch get exch } forall 15 1 roll
  14 -2 roll mark 15 1 roll { /Gray /Blue /Green /Red } {
		% stack: v0 v1 v2 type keys comp
    mark
    2 index 0 get 8 -1 roll
    4 index 1 get 9 -1 roll
    6 index 2 get 10 -1 roll
		% stack: type keys comp mark k0 v0 k1 v1 k2 v2
    /HalftoneType 10 index .dicttomark
    counttomark 2 roll
  } forall pop pop
  /Default 1 index .dicttomark exch pop { .sethalftone5 }
} bind def

% The value of each entry in .halftonetypes is a procedure:
%	<setdict> <htdict> <<proc>> <setdict'> <htdict'> <sethalftoneproc>
% This allows us to use these procedures both for actually implementing
% sethalftone and for converting subsidiary dictionaries of HalftoneType 5
% halftones.
systemdict begin
15 dict /.halftonetypes 1 index def begin
  1 {
    mark exch /Default exch .dicttomark { .sethalftone5 }
  } bind def
  2 {
    1 { /Frequency /Angle /SpotFunction } {
      /RedFrequency /RedAngle /RedSpotFunction
      /GreenFrequency /GreenAngle /GreenSpotFunction
      /BlueFrequency /BlueAngle /BlueSpotFunction
      /GrayFrequency /GrayAngle /GraySpotFunction
    } .makehalftoneRGBV
  } bind def
  3 {
    mark exch /Default exch .dicttomark { .sethalftone5 }
  } bind def
  4 {
    3 { /Width /Height /Thresholds } {
      /RedWidth /RedHeight /RedThresholds
      /GreenWidth /GreenHeight /GreenThresholds
      /BlueWidth /BlueHeight /BlueThresholds
      /GrayWidth /GrayHeight /GrayThresholds
    } .makehalftoneRGBV
  } bind def
  5 {
    pop dup length dict copy
    mark 1 index {
		% Even HalftoneType 5 dictionaries have entries other than
		% subsidiary halftone dictionaries.
      dup type /dicttype ne {
	0
      } {
	dup /HalftoneType .knownget not { 0 } if
      } ifelse dup 5 gt {
		% Stack: dict mark ... keyN dictN httypeN
		% Assume that all HalftoneTypes > 5 convert to 5.
	1 index 3 1 roll
	//.halftonetypes exch get exec pop /Default get
		% Stack: dict mark ... keyN setdict'N htdict'N
	counttomark 1 add index 3 index 4 -1 roll put
      } {
	pop
      } ifelse
    } forall .dicttomark { .sethalftone5 }
  } bind def
end
end
/sethalftone {		% <dict> sethalftone -
	% We must create the new dictionary in the same VM as the
	% operand; otherwise, invalidaccess errors may occur.
  .currentglobal 1 index dup gcheck .setglobal
  dup //.halftonetypes 1 index /HalftoneType get get exec exec
  .setglobal pop
} odef
% Redefine setscreen and setcolorscreen to recognize halftone dictionaries,
% and to insert the Frequency and Angle into Type 1 halftones, per
% Adobe TN 5085.
/.fixsethalftonescreen		% <freq> <angle> <dict> .fix...screen
				%   <freq> <angle> <dict> <dict'>
 { dup dup /HalftoneType get 1 eq
    { dup wcheck not { dup length .copydict } if
      dup /Frequency 5 index put
      dup /Angle 4 index put
    }
   if
 } bind def
/setscreen		% <ignore*2> <dict> setscreen -
	{ dup type /dicttype eq
	   { .fixsethalftonescreen sethalftone pop pop pop }
	   { //setscreen }
	  ifelse
	} odef
/setcolorscreen		% <ignore*11> <dict> setcolorscreen -
	{ dup type /dicttype eq
	   { .fixsethalftonescreen sethalftone 12 { pop } repeat }
	   { //setcolorscreen }
	  ifelse
	} odef
% Redefine currentscreen and currentcolorscreen to extract the Frequency
% and Angle from Type 1 halftones, per Adobe TN 5085.
/.fixcurrenthalftonescreen	% <dict> .fix... <freq> <angle> <proc>
 { dup /HalftoneType get 1 eq
    { dup /Frequency get 1 index /Angle get }
    { 60 0 }
   ifelse 3 2 roll
 } bind def
/currentscreen		% - currentscreen 60 0 <dict>
	{ .currenthalftone
	   { { .fixcurrenthalftonescreen }	% halftone
	     { }				% screen
	     { 12 3 roll 9 { pop } repeat	% colorscreen
	       dup type /dicttype eq { .fixcurrenthalftonescreen } if
	     }
	   }
	  exch get exec
	} odef
/currentcolorscreen	% - currentcolorscreen (60 0 <dict>)*4
	{ .currenthalftone
	   { { .fixcurrenthalftonescreen 3 copy 6 copy }	% halftone
	     { 3 copy 6 copy }			% screen
	     { }				% colorscreen
	   }
	  exch get exec
	} odef

% ------ User objects ------ %

/.UserObjects {
  .userdict /UserObjects
} odef
% In order to get proper error recovery behavior, we need to be careful
% not to pop any operands from the stack until we're done.
% The code below faithfully duplicates the apparent array-growing
% behavior of Adobe interpreters.
/defineuserobject {		% <index> <value> defineuserobject -
  .UserObjects .knownget {
    length dup 3 index le {
		% Stack: index value len
      2 index eq { 1 index 2 mul } { 1 index 1 add } ifelse
      .localvmarray .UserObjects get
      1 index copy pop
      .UserObjects 3 -1 roll put
    } {
      pop
    } ifelse
  } {
    .UserObjects 3 index 1 add 10 .max .localvmarray put
  } ifelse
  .UserObjects get 2 index 2 index put pop pop
} odef
/execuserobject {		% <index> execuserobject -
  .UserObjects get 1 index get exch pop exec
} odef
/undefineuserobject {		% <index> undefineuserobject -
  .UserObjects get 1 index null put pop
} odef

% ------ Cache control ------ %

% Dummy definitions for cache control operators

/ucachestatus {			% - ucachestatus -mark- ? ? ? ? <size>
	mark 0 0 0 0 .userdict /.ucachesize .knownget not { 0 } if
} odef
/setucacheparams {		% -mark- ... <size> setucacheparams -
		% Provoke an appropriate error if needed.
	counttomark 1 lt { () 0 get } if
	0 or .userdict /.ucachesize 2 index 0 .max put cleartomark
} odef

end				% level2dict