| 1 |
% Copyright (C) 2001-2023 Artifex Software, Inc. |
| 2 |
% All Rights Reserved. |
| 3 |
% |
| 4 |
% This software is provided AS-IS with no warranty, either express or |
| 5 |
% implied. |
| 6 |
% |
| 7 |
% This software is distributed under license and may not be copied, |
| 8 |
% modified or distributed except as expressly authorized under the terms |
| 9 |
% of the license contained in the file LICENSE in this distribution. |
| 10 |
% |
| 11 |
% Refer to licensing information at http://www.artifex.com or contact |
| 12 |
% Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, |
| 13 |
% CA 94129, USA, for further information. |
| 14 |
% |
| 15 |
|
| 16 |
% Initialization file for basic Display PostScript functions |
| 17 |
% that are also included in Level 2. |
| 18 |
|
| 19 |
level2dict begin |
| 20 |
|
| 21 |
% ------ Errors ------ % |
| 22 |
|
| 23 |
% These errors are only defined in Level 2 and DPS. |
| 24 |
{ /configurationerror /undefinedresource /unregistered } |
| 25 |
{ .registererror } forall |
| 26 |
|
| 27 |
% ------ Halftones ------ % |
| 28 |
|
| 29 |
/.makestackdict |
| 30 |
{ { counttomark -1 roll } forall .dicttomark |
| 31 |
} .internalbind def |
| 32 |
/currenthalftone % - currenthalftone <dict> |
| 33 |
{ mark .currenthalftone |
| 34 |
{ { exch pop } % halftone |
| 35 |
{ /HalftoneType 1 % screen |
| 36 |
{ /Frequency /Angle /SpotFunction } |
| 37 |
//.makestackdict exec readonly |
| 38 |
} |
| 39 |
{ /HalftoneType 2 % colorscreen |
| 40 |
{ /RedFrequency /RedAngle /RedSpotFunction |
| 41 |
/GreenFrequency /GreenAngle /GreenSpotFunction |
| 42 |
/BlueFrequency /BlueAngle /BlueSpotFunction |
| 43 |
/GrayFrequency /GrayAngle /GraySpotFunction |
| 44 |
} |
| 45 |
//.makestackdict exec readonly |
| 46 |
} |
| 47 |
} |
| 48 |
exch get exec |
| 49 |
} odef |
| 50 |
currentdict /.makestackdict undef |
| 51 |
|
| 52 |
% Define sethalftone so it converts types 1-4 to type 5. |
| 53 |
/.makehalftoneRGBV { % <dict> <type> <keys> <keysRGBV> |
| 54 |
4 -1 roll exch { 1 index exch get exch } forall 15 1 roll |
| 55 |
14 -2 roll mark 15 1 roll { /Gray /Blue /Green /Red } { |
| 56 |
% stack: v0 v1 v2 type keys comp |
| 57 |
mark |
| 58 |
2 index 0 get 8 -1 roll |
| 59 |
4 index 1 get 9 -1 roll |
| 60 |
6 index 2 get 10 -1 roll |
| 61 |
% stack: type keys comp mark k0 v0 k1 v1 k2 v2 |
| 62 |
/HalftoneType 10 index .dicttomark |
| 63 |
counttomark 2 roll |
| 64 |
} forall pop pop |
| 65 |
/Default 1 index .dicttomark exch pop { .sethalftone5 } |
| 66 |
} .internalbind def |
| 67 |
|
| 68 |
% The value of each entry in .halftonetypes is a procedure: |
| 69 |
% <setdict> <htdict> <<proc>> <setdict'> <htdict'> <sethalftoneproc> |
| 70 |
% This allows us to use these procedures both for actually implementing |
| 71 |
% sethalftone and for converting subsidiary dictionaries of HalftoneType 5 |
| 72 |
% halftones. |
| 73 |
systemdict begin |
| 74 |
15 dict /.halftonetypes 1 index def begin |
| 75 |
1 { |
| 76 |
mark exch /Default exch .dicttomark { .sethalftone5 } |
| 77 |
} .internalbind def |
| 78 |
2 { |
| 79 |
1 { /Frequency /Angle /SpotFunction } { |
| 80 |
/RedFrequency /RedAngle /RedSpotFunction |
| 81 |
/GreenFrequency /GreenAngle /GreenSpotFunction |
| 82 |
/BlueFrequency /BlueAngle /BlueSpotFunction |
| 83 |
/GrayFrequency /GrayAngle /GraySpotFunction |
| 84 |
} //.makehalftoneRGBV exec |
| 85 |
} .internalbind def |
| 86 |
3 { |
| 87 |
mark exch /Default exch .dicttomark { .sethalftone5 } |
| 88 |
} .internalbind def |
| 89 |
4 { |
| 90 |
3 { /Width /Height /Thresholds } { |
| 91 |
/RedWidth /RedHeight /RedThresholds |
| 92 |
/GreenWidth /GreenHeight /GreenThresholds |
| 93 |
/BlueWidth /BlueHeight /BlueThresholds |
| 94 |
/GrayWidth /GrayHeight /GrayThresholds |
| 95 |
} //.makehalftoneRGBV exec |
| 96 |
} .internalbind def |
| 97 |
5 { |
| 98 |
pop dup length dict copy |
| 99 |
mark 1 index { |
| 100 |
% Even HalftoneType 5 dictionaries have entries other than |
| 101 |
% subsidiary halftone dictionaries. |
| 102 |
dup type /dicttype ne { |
| 103 |
0 |
| 104 |
} { |
| 105 |
dup /HalftoneType .knownget not { 0 } if |
| 106 |
} ifelse dup 5 gt { |
| 107 |
% Stack: dict mark ... keyN dictN httypeN |
| 108 |
% Assume that all HalftoneTypes > 5 convert to 5. |
| 109 |
1 index 3 1 roll |
| 110 |
//.halftonetypes exch get exec pop /Default get |
| 111 |
% Stack: dict mark ... keyN setdict'N htdict'N |
| 112 |
counttomark 1 add index 3 index 4 -1 roll put |
| 113 |
} { |
| 114 |
pop |
| 115 |
} ifelse |
| 116 |
} forall .dicttomark { .sethalftone5 } |
| 117 |
} .internalbind def |
| 118 |
end |
| 119 |
end |
| 120 |
currentdict /.makehalftoneRGBV undef |
| 121 |
|
| 122 |
/sethalftone { % <dict> sethalftone - |
| 123 |
% We must create the new dictionary in the same VM as the |
| 124 |
% operand; otherwise, invalidaccess errors may occur. |
| 125 |
.currentglobal 1 .argindex dup gcheck .setglobal |
| 126 |
dup //.halftonetypes 1 index /HalftoneType get |
| 127 |
dup type /integertype ne { |
| 128 |
/sethalftone .systemvar /typecheck signalerror |
| 129 |
} if |
| 130 |
.knownget not { |
| 131 |
/sethalftone .systemvar /rangecheck signalerror |
| 132 |
} if |
| 133 |
exec exec |
| 134 |
.setglobal pop |
| 135 |
} .forcebind odef |
| 136 |
% Redefine setscreen and setcolorscreen to recognize halftone dictionaries, |
| 137 |
% and to insert the Frequency and Angle into Type 1 halftones, per |
| 138 |
% Adobe TN 5085. |
| 139 |
/.fixsethalftonescreen % <freq> <angle> <dict> .fix...screen |
| 140 |
% <freq> <angle> <dict> <dict'> |
| 141 |
{ dup dup /HalftoneType get 1 eq |
| 142 |
{ dup wcheck not { dup length dict .copydict } if |
| 143 |
dup /Frequency 5 index put |
| 144 |
dup /Angle 4 index put |
| 145 |
languagelevel 3 ge { dup /AccurateScreens dup getuserparam put } if |
| 146 |
} |
| 147 |
if |
| 148 |
} .internalbind def |
| 149 |
/setscreen % <ignore*2> <dict> setscreen - |
| 150 |
{ dup type /dicttype eq |
| 151 |
{ //.fixsethalftonescreen exec sethalftone pop pop pop } |
| 152 |
{ //setscreen } |
| 153 |
ifelse |
| 154 |
} .forcebind odef |
| 155 |
/setcolorscreen % <ignore*11> <dict> setcolorscreen - |
| 156 |
{ dup type /dicttype eq |
| 157 |
{ //.fixsethalftonescreen exec sethalftone 12 { pop } repeat } |
| 158 |
{ //setcolorscreen } |
| 159 |
ifelse |
| 160 |
} .forcebind odef |
| 161 |
currentdict /.fixsethalftonescreen undef |
| 162 |
|
| 163 |
% Redefine currentscreen and currentcolorscreen to extract the Frequency |
| 164 |
% and Angle from Type 1 halftones, per Adobe TN 5085. |
| 165 |
/.fixcurrenthalftonescreen % <dict> .fix... <freq> <angle> <proc> |
| 166 |
{ dup /HalftoneType get 1 eq |
| 167 |
{ dup /Frequency get 1 index /Angle get } |
| 168 |
{ 60.0 0.0 } % Adobe returns these as reals |
| 169 |
ifelse 3 2 roll |
| 170 |
} .internalbind def |
| 171 |
/currentscreen % - currentscreen 60 0 <dict> |
| 172 |
{ .currenthalftone |
| 173 |
{ { //.fixcurrenthalftonescreen exec }% halftone |
| 174 |
{ } % screen |
| 175 |
{ 12 3 roll 9 { pop } repeat % colorscreen |
| 176 |
dup type /dicttype eq { //.fixcurrenthalftonescreen exec } if |
| 177 |
} |
| 178 |
} |
| 179 |
exch get exec |
| 180 |
} odef |
| 181 |
/currentcolorscreen % - currentcolorscreen (60 0 <dict>)*4 |
| 182 |
{ .currenthalftone |
| 183 |
{ { //.fixcurrenthalftonescreen exec 3 copy 6 copy } % halftone |
| 184 |
{ % screen |
| 185 |
% The procedure might not be readable.... |
| 186 |
dup rcheck { dup length array copy cvx } if |
| 187 |
3 copy 6 copy |
| 188 |
} |
| 189 |
{ } % colorscreen |
| 190 |
} |
| 191 |
exch get exec |
| 192 |
} odef |
| 193 |
currentdict /.fixcurrenthalftonescreen undef |
| 194 |
|
| 195 |
% ------ User objects ------ % |
| 196 |
|
| 197 |
/.UserObjects { |
| 198 |
.userdict /UserObjects |
| 199 |
} .internalbind odef |
| 200 |
% In order to get proper error recovery behavior, we need to be careful |
| 201 |
% not to pop any operands from the stack until we're done. |
| 202 |
% The code below faithfully duplicates the apparent array-growing |
| 203 |
% behavior of Adobe interpreters. |
| 204 |
/defineuserobject { % <index> <value> defineuserobject - |
| 205 |
1 index 65535 gt { |
| 206 |
% .localvmarray throws limitcheck but CET 31-02 wants rangecheck |
| 207 |
/defineuserobject .systemvar /rangecheck signalerror |
| 208 |
} if |
| 209 |
.UserObjects .knownget { |
| 210 |
length dup 3 .argindex le { |
| 211 |
% Stack: index value len |
| 212 |
2 index eq { 1 index 2 mul } { 1 index 1 add } ifelse |
| 213 |
.localvmarray .UserObjects get |
| 214 |
1 index copy pop |
| 215 |
.UserObjects 3 -1 roll put |
| 216 |
} { |
| 217 |
pop |
| 218 |
} ifelse |
| 219 |
} { |
| 220 |
.UserObjects 3 .argindex 1 add 10 .max .localvmarray put |
| 221 |
} ifelse |
| 222 |
.UserObjects get 2 .argindex 2 index put pop pop |
| 223 |
} .forcebind odef |
| 224 |
/execuserobject { % <index> execuserobject - |
| 225 |
dup type /integertype ne { |
| 226 |
% Adobe validates the argument before accessing UserObjects - CET 31-03 |
| 227 |
/execuserobject .systemvar /typecheck signalerror |
| 228 |
} if |
| 229 |
.UserObjects get 1 .argindex get exch pop exec |
| 230 |
} .forcebind odef |
| 231 |
/undefineuserobject { % <index> undefineuserobject - |
| 232 |
dup type /integertype ne { |
| 233 |
% Adobe validates the argument before accessing UserObjects - CET 31-11 |
| 234 |
/undefineuserobject .systemvar /typecheck signalerror |
| 235 |
} if |
| 236 |
.UserObjects get 1 .argindex //null put pop |
| 237 |
} .forcebind odef |
| 238 |
currentdict /.UserObjects undef |
| 239 |
|
| 240 |
% ------ Cache control ------ % |
| 241 |
|
| 242 |
% Dummy definitions for cache control operators |
| 243 |
|
| 244 |
/ucachestatus { % - ucachestatus -mark- ? ? ? ? <size> |
| 245 |
mark 0 0 0 0 /MaxUPathItem getuserparam |
| 246 |
} odef |
| 247 |
/setucacheparams { % -mark- ... <size> setucacheparams - |
| 248 |
% Provoke an appropriate error if needed. |
| 249 |
counttomark 1 lt { () 0 get } if |
| 250 |
dup 0 or /MaxUPathItem getuserparam .max |
| 251 |
1 dict dup /MaxUPathItem 4 -1 roll put setuserparams cleartomark |
| 252 |
} odef |
| 253 |
|
| 254 |
end % level2dict |