1
% Copyright (C) 1990, 1996, 1997, 1998, 2000 Aladdin Enterprises. All rights reserved.
3
% This software is provided AS-IS with no warranty, either express or
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.
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.
16
% $Id: gs_dps2.ps 8954 2008-08-08 04:22:38Z ray $
17
% Initialization file for basic Display PostScript functions
18
% that are also included in Level 2.
22
% ------ Errors ------ %
24
% These errors are only defined in Level 2 and DPS.
25
{ /configurationerror /undefinedresource /unregistered }
26
{ .registererror } forall
28
% ------ Halftones ------ %
31
{ { counttomark -1 roll } forall .dicttomark
33
/currenthalftone % - currenthalftone <dict>
34
{ mark .currenthalftone
35
{ { exch pop } % halftone
36
{ /HalftoneType 1 % screen
37
{ /Frequency /Angle /SpotFunction }
38
.makestackdict readonly
40
{ /HalftoneType 2 % colorscreen
41
{ /RedFrequency /RedAngle /RedSpotFunction
42
/GreenFrequency /GreenAngle /GreenSpotFunction
43
/BlueFrequency /BlueAngle /BlueSpotFunction
44
/GrayFrequency /GrayAngle /GraySpotFunction
46
.makestackdict readonly
51
% Define sethalftone so it converts types 1-4 to type 5.
52
/.makehalftoneRGBV { % <dict> <type> <keys> <keysRGBV>
53
4 -1 roll exch { 1 index exch get exch } forall 15 1 roll
54
14 -2 roll mark 15 1 roll { /Gray /Blue /Green /Red } {
55
% stack: v0 v1 v2 type keys comp
57
2 index 0 get 8 -1 roll
58
4 index 1 get 9 -1 roll
59
6 index 2 get 10 -1 roll
60
% stack: type keys comp mark k0 v0 k1 v1 k2 v2
61
/HalftoneType 10 index .dicttomark
64
/Default 1 index .dicttomark exch pop { .sethalftone5 }
67
% The value of each entry in .halftonetypes is a procedure:
68
% <setdict> <htdict> <<proc>> <setdict'> <htdict'> <sethalftoneproc>
69
% This allows us to use these procedures both for actually implementing
70
% sethalftone and for converting subsidiary dictionaries of HalftoneType 5
73
15 dict /.halftonetypes 1 index def begin
75
mark exch /Default exch .dicttomark { .sethalftone5 }
78
1 { /Frequency /Angle /SpotFunction } {
79
/RedFrequency /RedAngle /RedSpotFunction
80
/GreenFrequency /GreenAngle /GreenSpotFunction
81
/BlueFrequency /BlueAngle /BlueSpotFunction
82
/GrayFrequency /GrayAngle /GraySpotFunction
86
mark exch /Default exch .dicttomark { .sethalftone5 }
89
3 { /Width /Height /Thresholds } {
90
/RedWidth /RedHeight /RedThresholds
91
/GreenWidth /GreenHeight /GreenThresholds
92
/BlueWidth /BlueHeight /BlueThresholds
93
/GrayWidth /GrayHeight /GrayThresholds
97
pop dup length dict copy
99
% Even HalftoneType 5 dictionaries have entries other than
100
% subsidiary halftone dictionaries.
101
dup type /dicttype ne {
104
dup /HalftoneType .knownget not { 0 } if
106
% Stack: dict mark ... keyN dictN httypeN
107
% Assume that all HalftoneTypes > 5 convert to 5.
109
//.halftonetypes exch get exec pop /Default get
110
% Stack: dict mark ... keyN setdict'N htdict'N
111
counttomark 1 add index 3 index 4 -1 roll put
115
} forall .dicttomark { .sethalftone5 }
119
/sethalftone { % <dict> sethalftone -
120
% We must create the new dictionary in the same VM as the
121
% operand; otherwise, invalidaccess errors may occur.
122
.currentglobal 1 .argindex dup gcheck .setglobal
123
dup //.halftonetypes 1 index /HalftoneType get
124
dup type /integertype ne {
125
/sethalftone .systemvar /typecheck signalerror
128
/sethalftone .systemvar /rangecheck signalerror
133
% Redefine setscreen and setcolorscreen to recognize halftone dictionaries,
134
% and to insert the Frequency and Angle into Type 1 halftones, per
136
/.fixsethalftonescreen % <freq> <angle> <dict> .fix...screen
137
% <freq> <angle> <dict> <dict'>
138
{ dup dup /HalftoneType get 1 eq
139
{ dup wcheck not { dup length .copydict } if
140
dup /Frequency 5 index put
141
dup /Angle 4 index put
142
languagelevel 3 ge { dup /AccurateScreens dup getuserparam put } if
146
/setscreen % <ignore*2> <dict> setscreen -
147
{ dup type /dicttype eq
148
{ .fixsethalftonescreen sethalftone pop pop pop }
152
/setcolorscreen % <ignore*11> <dict> setcolorscreen -
153
{ dup type /dicttype eq
154
{ .fixsethalftonescreen sethalftone 12 { pop } repeat }
158
% Redefine currentscreen and currentcolorscreen to extract the Frequency
159
% and Angle from Type 1 halftones, per Adobe TN 5085.
160
/.fixcurrenthalftonescreen % <dict> .fix... <freq> <angle> <proc>
161
{ dup /HalftoneType get 1 eq
162
{ dup /Frequency get 1 index /Angle get }
163
{ 60.0 0.0 } % Adobe returns these as reals
166
/currentscreen % - currentscreen 60 0 <dict>
168
{ { .fixcurrenthalftonescreen } % halftone
170
{ 12 3 roll 9 { pop } repeat % colorscreen
171
dup type /dicttype eq { .fixcurrenthalftonescreen } if
176
/currentcolorscreen % - currentcolorscreen (60 0 <dict>)*4
178
{ { .fixcurrenthalftonescreen 3 copy 6 copy } % halftone
180
% The procedure might not be readable....
181
dup rcheck { dup length array copy cvx } if
189
% ------ User objects ------ %
192
.userdict /UserObjects
194
% In order to get proper error recovery behavior, we need to be careful
195
% not to pop any operands from the stack until we're done.
196
% The code below faithfully duplicates the apparent array-growing
197
% behavior of Adobe interpreters.
198
/defineuserobject { % <index> <value> defineuserobject -
200
% .localvmarray throws limitcheck but CET 31-02 wants rangecheck
201
/defineuserobject .systemvar /rangecheck signalerror
203
.UserObjects .knownget {
204
length dup 3 .argindex le {
205
% Stack: index value len
206
2 index eq { 1 index 2 mul } { 1 index 1 add } ifelse
207
.localvmarray .UserObjects get
209
.UserObjects 3 -1 roll put
214
.UserObjects 3 .argindex 1 add 10 .max .localvmarray put
216
.UserObjects get 2 .argindex 2 index put pop pop
218
/execuserobject { % <index> execuserobject -
219
dup type /integertype ne {
220
% Adobe validates the argument before accessing UserObjects - CET 31-03
221
/execuserobject .systemvar /typecheck signalerror
223
.UserObjects get 1 .argindex get exch pop exec
225
/undefineuserobject { % <index> undefineuserobject -
226
dup type /integertype ne {
227
% Adobe validates the argument before accessing UserObjects - CET 31-11
228
/undefineuserobject .systemvar /typecheck signalerror
230
.UserObjects get 1 .argindex //null put pop
233
% ------ Cache control ------ %
235
% Dummy definitions for cache control operators
237
/ucachestatus { % - ucachestatus -mark- ? ? ? ? <size>
238
mark 0 0 0 0 /MaxUPathItem getuserparam
240
/setucacheparams { % -mark- ... <size> setucacheparams -
241
% Provoke an appropriate error if needed.
242
counttomark 1 lt { () 0 get } if
243
dup 0 or /MaxUPathItem getuserparam .max
244
1 dict dup /MaxUPathItem 4 -1 roll put setuserparams cleartomark