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