| 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 Level 2 functions. |
| 17 |
% When this is run, systemdict is still writable, |
| 18 |
% but (almost) everything defined here goes into level2dict. |
| 19 |
|
| 20 |
level2dict begin |
| 21 |
|
| 22 |
% ------ System and user parameters ------ % |
| 23 |
|
| 24 |
% User parameters must obey save/restore, and must also be maintained |
| 25 |
% per-context. We implement the former, and some of the latter, here |
| 26 |
% with PostScript code. NOTE: our implementation assumes that user |
| 27 |
% parameters change only as a result of setuserparams -- that there are |
| 28 |
% no user parameters that are ever changed dynamically by the interpreter |
| 29 |
% (although the interpreter may adjust the value presented to setuserparams) |
| 30 |
% |
| 31 |
% There are two types of user parameters: those which are actually |
| 32 |
% maintained in the interpreter, and those which exist only at the |
| 33 |
% PostScript level. We maintain the current state of both types in |
| 34 |
% a read-only local dictionary named userparams, defined in systemdict. |
| 35 |
% In a multi-context system, each context has its own copy of this |
| 36 |
% dictionary. In addition, there is a constant dictionary named |
| 37 |
% psuserparams where each key is the name of a user parameter that exists |
| 38 |
% only in PostScript and the value is a procedure to check that the value |
| 39 |
% is legal: setuserparams uses this for checking the values. |
| 40 |
% setuserparams updates userparams explicitly, in addition to setting |
| 41 |
% any user parameters in the interpreter; thus we can use userparams |
| 42 |
% to reset those parameters after a restore or a context switch. |
| 43 |
% NOTE: the name userparams is known to the interpreter, and in fact |
| 44 |
% the interpreter creates the userparams dictionary. |
| 45 |
|
| 46 |
% Check parameters that are managed at the PostScript level. |
| 47 |
/.checkparamtype { % <newvalue> <type> .checkparamtype <bool> |
| 48 |
exch type eq |
| 49 |
} .forcebind def |
| 50 |
/.checksetparams { % <newdict> <opname> <checkdict> |
| 51 |
% .checksetparams <newdict> |
| 52 |
2 .argindex { |
| 53 |
% Stack: newdict opname checkdict key newvalue |
| 54 |
3 copy 3 1 roll .knownget { |
| 55 |
exec not { |
| 56 |
pop pop pop load /typecheck signalerror |
| 57 |
} if |
| 58 |
dup type /stringtype eq { |
| 59 |
dup rcheck not { |
| 60 |
pop pop pop load /invalidaccess signalerror |
| 61 |
} if |
| 62 |
} if |
| 63 |
} { |
| 64 |
pop |
| 65 |
} ifelse pop pop |
| 66 |
} forall pop pop |
| 67 |
} .forcebind def |
| 68 |
|
| 69 |
% currentuser/systemparams creates and returns a dictionary in the |
| 70 |
% current VM. The easiest way to make this work is to copy any composite |
| 71 |
% PostScript-level parameters to global VM. Currently we have strings |
| 72 |
% as well as arrays. For arrays, we also need to copy any contents that |
| 73 |
% are in VM. Also copying string parameters insures the contents won't |
| 74 |
% be changed. Also be careful to preserve 'executable' state. |
| 75 |
/.copyparam { % <value> .copyparam <value'> |
| 76 |
dup type /arraytype eq { |
| 77 |
.currentglobal //true .setglobal exch |
| 78 |
dup wcheck exch dup xcheck exch % original attributes |
| 79 |
dup length array exch dup { % stack: destination_array original_array original_array |
| 80 |
dup type /arraytype eq { |
| 81 |
dup 2 index ne { % avoid recursion |
| 82 |
.copyparam % recurse to handle composite array elements |
| 83 |
} { |
| 84 |
% this array self referenced, do it again (yuk!) |
| 85 |
pop 1 index % get copy of destination array |
| 86 |
} ifelse |
| 87 |
} { |
| 88 |
dup type /stringtype eq { |
| 89 |
.copyparam |
| 90 |
} if |
| 91 |
} |
| 92 |
ifelse 3 1 roll % keep arrays on top |
| 93 |
} forall pop astore |
| 94 |
exch { cvx } if % set executable state |
| 95 |
exch not { readonly } if % set readonly attribute as original |
| 96 |
exch .setglobal |
| 97 |
} if |
| 98 |
dup type /stringtype eq { |
| 99 |
dup wcheck exch % save attr for setting readonly |
| 100 |
.currentglobal //true .setglobal |
| 101 |
1 index length string exch .setglobal |
| 102 |
copy exch not { readonly } if |
| 103 |
} if |
| 104 |
} .forcebind odef |
| 105 |
|
| 106 |
% Some user parameters are managed entirely at the PostScript level. |
| 107 |
% We take care of that here. |
| 108 |
systemdict begin |
| 109 |
/psuserparams 48 dict def |
| 110 |
/getuserparam { % <name> getuserparam <value> |
| 111 |
/userparams .systemvar 1 .argindex get exch pop |
| 112 |
} odef |
| 113 |
% Fill in userparams (created by the interpreter) with current values. |
| 114 |
mark .currentuserparams |
| 115 |
counttomark 2 idiv { |
| 116 |
userparams 3 1 roll put |
| 117 |
} repeat pop |
| 118 |
/.definepsuserparam { % <name> <value> .definepsuserparam - |
| 119 |
psuserparams 3 copy pop |
| 120 |
type cvlit //.checkparamtype /exec load 3 packedarray cvx put |
| 121 |
userparams 3 1 roll put |
| 122 |
} .forcebind def |
| 123 |
end |
| 124 |
/currentuserparams { % - currentuserparams <dict> |
| 125 |
/userparams .systemvar dup length dict .copydict |
| 126 |
} odef |
| 127 |
% We break out setuserparams into a separate procedure so that setvmxxx |
| 128 |
% can use it without affecting the command in case of an error. |
| 129 |
/.setuserparams2 { |
| 130 |
% Check that we will be able to set the PostScript-level |
| 131 |
% user parameters. |
| 132 |
/setuserparams /psuserparams .systemvar //.checksetparams exec |
| 133 |
% Set the C-level user params. If this succeeds, we know that |
| 134 |
% the password check succeeded. |
| 135 |
dup .setuserparams |
| 136 |
% Now set the PostScript-level params. |
| 137 |
% The interpreter may have adjusted the values of some of the |
| 138 |
% parameters, so we have to read them back. |
| 139 |
dup { |
| 140 |
/userparams .systemvar 2 index known { |
| 141 |
psuserparams 2 index known not { |
| 142 |
pop dup .getuserparam |
| 143 |
} if |
| 144 |
.copyparam |
| 145 |
% special protection for the security related parameters |
| 146 |
[ /PermitFileReading /PermitFileWriting /PermitFileControl ] |
| 147 |
{ 2 index eq { % force all strings to readonly but make sure the |
| 148 |
% array is in the correct VM space (local/global). |
| 149 |
currentglobal exch dup gcheck setglobal |
| 150 |
dup length array exch { readonly exch } forall astore |
| 151 |
exch setglobal |
| 152 |
} if |
| 153 |
} forall |
| 154 |
% protect top level of parameters that we copied |
| 155 |
dup type dup /arraytype eq exch /stringtype eq or { readonly } if |
| 156 |
/userparams .systemvar 3 1 roll .forceput % userparams is read-only |
| 157 |
} executeonly |
| 158 |
{ |
| 159 |
pop pop |
| 160 |
} ifelse |
| 161 |
} executeonly forall |
| 162 |
% A context switch might have occurred during the above loop, |
| 163 |
% causing the interpreter-level parameters to be reset. |
| 164 |
% Set them again to the new values. From here on, we are safe, |
| 165 |
% since a context switch will consult userparams. |
| 166 |
.setuserparams |
| 167 |
} .forcebind odef % must be bound and hidden for .forceput |
| 168 |
|
| 169 |
/setuserparams { % <dict> setuserparams - |
| 170 |
{.setuserparams2} stopped |
| 171 |
{/setuserparams load $error /errorname get signalerror} if |
| 172 |
} .forcebind odef |
| 173 |
% Initialize user parameters managed here. |
| 174 |
/JobName () .definepsuserparam |
| 175 |
|
| 176 |
% Restore must restore the user parameters. |
| 177 |
% (Since userparams is in local VM, save takes care of saving them.) |
| 178 |
/restore { % <save> restore - |
| 179 |
//restore /userparams .systemvar .setuserparams |
| 180 |
} .forcebind odef |
| 181 |
|
| 182 |
% The pssystemparams dictionary holds some system parameters that |
| 183 |
% are managed entirely at the PostScript level. |
| 184 |
systemdict begin |
| 185 |
currentdict /pssystemparams known not { |
| 186 |
/pssystemparams 40 dict readonly def |
| 187 |
} if |
| 188 |
/getsystemparam { % <name> getsystemparam <value> |
| 189 |
//pssystemparams 1 .argindex .knownget { exch pop } { .getsystemparam } ifelse |
| 190 |
} odef |
| 191 |
end |
| 192 |
/currentsystemparams { % - currentsystemparams <dict> |
| 193 |
mark .currentsystemparams //pssystemparams { } forall .dicttomark |
| 194 |
} odef |
| 195 |
/setsystemparams { % <dict> setsystemparams - |
| 196 |
% Check that we will be able to set the PostScript-level |
| 197 |
% system parameters. |
| 198 |
dup pop % check # of args |
| 199 |
/SAFETY .systemvar /safe get { |
| 200 |
% SAFER mode disallows some changes |
| 201 |
[ /GenericResourceDir /FontResourceDir /GenericResourcePathSep ] { |
| 202 |
2 copy .knownget { |
| 203 |
exch //pssystemparams exch .knownget { |
| 204 |
ne { /setsystemparams cvx /invalidaccess signalerror } if |
| 205 |
} { |
| 206 |
pop |
| 207 |
} ifelse |
| 208 |
} { |
| 209 |
pop |
| 210 |
} ifelse |
| 211 |
} forall |
| 212 |
} if |
| 213 |
/setsystemparams //pssystemparams mark exch { |
| 214 |
type cvlit //.checkparamtype /exec load 3 packedarray cvx |
| 215 |
} forall .dicttomark //.checksetparams exec |
| 216 |
% Set the C-level system params. If this succeeds, we know that |
| 217 |
% the password check succeeded. |
| 218 |
dup .setsystemparams |
| 219 |
% Now set the PostScript-level params. We must copy local strings |
| 220 |
% into global VM. |
| 221 |
dup |
| 222 |
{ //pssystemparams 2 index known |
| 223 |
{ % Stack: key newvalue |
| 224 |
.copyparam |
| 225 |
% protect top level parameters that we copied |
| 226 |
dup type dup /arraytype eq exch /stringtype eq or { readonly } if |
| 227 |
//pssystemparams 3 1 roll .forceput % pssystemparams is read-only |
| 228 |
} executeonly |
| 229 |
{ pop pop |
| 230 |
} |
| 231 |
ifelse |
| 232 |
} executeonly |
| 233 |
forall pop |
| 234 |
} .forcebind odef |
| 235 |
|
| 236 |
% Initialize the passwords. |
| 237 |
% NOTE: the names StartJobPassword and SystemParamsPassword are known to |
| 238 |
% the interpreter, and must be bound to noaccess strings. |
| 239 |
% The length of these strings must be max_password (iutil2.h) + 1. |
| 240 |
/StartJobPassword 65 string noaccess def |
| 241 |
/SystemParamsPassword 65 string noaccess def |
| 242 |
|
| 243 |
% Redefine cache parameter setting to interact properly with userparams. |
| 244 |
/setcachelimit { |
| 245 |
{ mark /MaxFontItem 2 .argindex .dicttomark setuserparams pop } |
| 246 |
stopped |
| 247 |
{ /setcachelimit .systemvar $error /errorname get signalerror |
| 248 |
} if |
| 249 |
} .forcebind odef |
| 250 |
/setcacheparams { |
| 251 |
% The MaxFontCache parameter is a system parameter, which we might |
| 252 |
% not be able to set. Fortunately, this doesn't matter, because |
| 253 |
% system parameters don't have to be synchronized between this code |
| 254 |
% and the VM. |
| 255 |
counttomark 1 add copy setcacheparams |
| 256 |
currentcacheparams % mark size lower upper |
| 257 |
3 -1 roll pop |
| 258 |
/MinFontCompress 3 1 roll |
| 259 |
/MaxFontItem exch |
| 260 |
.dicttomark { setuserparams cleartomark } stopped { |
| 261 |
/setcacheparams .systemvar $error /errorname get signalerror |
| 262 |
} if |
| 263 |
} .forcebind odef |
| 264 |
|
| 265 |
% Add bogus user and system parameters to satisfy badly written PostScript |
| 266 |
% programs that incorrectly assume the existence of all the parameters |
| 267 |
% listed in Appendix C of the Red Book. Note that some of these may become |
| 268 |
% real parameters later: code near the end of gs_init.ps takes care of |
| 269 |
% removing any such parameters from ps{user,system}params. |
| 270 |
|
| 271 |
% psuserparams |
| 272 |
/MaxFormItem 100000 .definepsuserparam |
| 273 |
/MaxPatternItem 20000 .definepsuserparam |
| 274 |
/MaxScreenItem 48000 .definepsuserparam |
| 275 |
/MaxUPathItem 0 .definepsuserparam |
| 276 |
|
| 277 |
% File Access Permission parameters |
| 278 |
.currentglobal //true .setglobal |
| 279 |
/.checkFilePermitparams { |
| 280 |
type /arraytype eq { |
| 281 |
currentuserparams /LockFilePermissions get { |
| 282 |
5 { pop } repeat /setuserparams cvx /invalidaccess signalerror |
| 283 |
}{ |
| 284 |
% in addition to validating the value, ensure the value is read/only |
| 285 |
dup { readonly exch } forall |
| 286 |
.currentglobal exch dup gcheck .setglobal length array exch .setglobal |
| 287 |
astore readonly |
| 288 |
} |
| 289 |
ifelse |
| 290 |
} { |
| 291 |
5 { pop } repeat /setuserparams cvx /typecheck signalerror |
| 292 |
} |
| 293 |
ifelse |
| 294 |
//true |
| 295 |
} .forcebind def |
| 296 |
% Initialize the File Permission access control to wide open |
| 297 |
% These will only be accessed via current/set userparams. |
| 298 |
% Values are a string containing multiple nul terminated path strings |
| 299 |
/PermitFileReading dup [ (*) ] .definepsuserparam |
| 300 |
psuserparams exch /.checkFilePermitparams load put |
| 301 |
/PermitFileWriting dup [ (*) ] .definepsuserparam |
| 302 |
psuserparams exch /.checkFilePermitparams load put |
| 303 |
/PermitFileControl dup [ (*) ] .definepsuserparam |
| 304 |
psuserparams exch /.checkFilePermitparams load put |
| 305 |
.setglobal |
| 306 |
|
| 307 |
pssystemparams |
| 308 |
dup /CurDisplayList 0 .forceput |
| 309 |
dup /CurFormCache 0 .forceput |
| 310 |
dup /CurInputDevice () .forceput |
| 311 |
dup /CurOutlineCache 0 .forceput |
| 312 |
dup /CurOutputDevice () .forceput |
| 313 |
dup /CurPatternCache 0 .forceput |
| 314 |
dup /CurUPathCache 0 .forceput |
| 315 |
dup /CurScreenStorage 0 .forceput |
| 316 |
dup /CurSourceList 0 .forceput |
| 317 |
dup /DoPrintErrors //false .forceput |
| 318 |
dup /JobTimeout 0 .forceput |
| 319 |
dup /LicenseID (LN-001) .forceput % bogus |
| 320 |
dup /MaxDisplayList 140000 .forceput |
| 321 |
dup /MaxFormCache 100000 .forceput |
| 322 |
dup /MaxImageBuffer 524288 .forceput |
| 323 |
dup /MaxOutlineCache 65000 .forceput |
| 324 |
dup /MaxPatternCache 100000 .forceput |
| 325 |
dup /MaxUPathCache 300000 .forceput |
| 326 |
dup /MaxScreenStorage 84000 .forceput |
| 327 |
dup /MaxSourceList 25000 .forceput |
| 328 |
dup /PrinterName product .forceput |
| 329 |
dup /RamSize 4194304 .forceput |
| 330 |
/WaitTimeout 40 .forceput |
| 331 |
|
| 332 |
% Define the procedures for handling comment scanning. The names |
| 333 |
% %ProcessComment and %ProcessDSCComment are known to the interpreter. |
| 334 |
% These procedures take the file and comment string and file as operands. |
| 335 |
/.checkprocesscomment { |
| 336 |
dup //null eq { |
| 337 |
pop //true |
| 338 |
} { |
| 339 |
dup xcheck { |
| 340 |
type dup /arraytype eq exch /packedarraytype eq or |
| 341 |
} { |
| 342 |
pop //false |
| 343 |
} ifelse |
| 344 |
} ifelse |
| 345 |
} .forcebind def |
| 346 |
/ProcessComment //null .definepsuserparam |
| 347 |
psuserparams /ProcessComment {//.checkprocesscomment exec} put |
| 348 |
(%ProcessComment) cvn { |
| 349 |
/ProcessComment getuserparam |
| 350 |
dup //null eq { pop pop pop } { exec } ifelse |
| 351 |
} .internalbind def |
| 352 |
/ProcessDSCComment //null .definepsuserparam |
| 353 |
psuserparams /ProcessDSCComment {//.checkprocesscomment exec} put |
| 354 |
/.loadingfont //false def |
| 355 |
(%ProcessDSCComment) cvn { |
| 356 |
/ProcessDSCComment getuserparam |
| 357 |
dup //null eq .loadingfont or { pop pop pop } { exec } ifelse |
| 358 |
} .internalbind def |
| 359 |
|
| 360 |
% ------ Miscellaneous ------ % |
| 361 |
|
| 362 |
(<<) cvn % - << -mark- |
| 363 |
/mark load def |
| 364 |
% (>> is defined primitively.) |
| 365 |
/languagelevel 2 def |
| 366 |
% When running in Level 2 mode, this interpreter is supposed to be |
| 367 |
% compatible with Adobe version 2017. |
| 368 |
/version (2017) readonly def |
| 369 |
|
| 370 |
% If binary tokens are supported by this interpreter, |
| 371 |
% set an appropriate default binary object format. |
| 372 |
/setobjectformat where |
| 373 |
{ pop |
| 374 |
/RealFormat getsystemparam (IEEE) eq { 1 } { 3 } ifelse |
| 375 |
/ByteOrder getsystemparam { 1 add } if |
| 376 |
setobjectformat |
| 377 |
} if |
| 378 |
|
| 379 |
% Aldus Freehand versions 2.x check for the presence of the |
| 380 |
% setcolor operator, and if it is missing, substitute a procedure. |
| 381 |
% Unfortunately, the procedure takes different parameters from |
| 382 |
% the operator. As a result, files produced by this application |
| 383 |
% cause an error if the setcolor operator is actually defined |
| 384 |
% and 'bind' is ever used. Aldus fixed this bug in Freehand 3.0, |
| 385 |
% but there are a lot of files created by the older versions |
| 386 |
% still floating around. Therefore, at Adobe's suggestion, |
| 387 |
% we implement the following dreadful hack in the 'where' operator: |
| 388 |
% If the key is /setcolor, and |
| 389 |
% there is a dictionary named FreeHandDict, and |
| 390 |
% currentdict is that dictionary, |
| 391 |
% then "where" consults only that dictionary and not any other |
| 392 |
% dictionaries on the dictionary stack. |
| 393 |
.wheredict /setcolor { |
| 394 |
/FreeHandDict .where { |
| 395 |
/FreeHandDict get currentdict eq { |
| 396 |
pop currentdict /setcolor known { currentdict //true } { //false } ifelse |
| 397 |
} { |
| 398 |
.where |
| 399 |
} ifelse |
| 400 |
} { |
| 401 |
.where |
| 402 |
} ifelse |
| 403 |
} .internalbind put |
| 404 |
|
| 405 |
% ------ Virtual memory ------ % |
| 406 |
|
| 407 |
/currentglobal % - currentglobal <bool> |
| 408 |
/currentshared load def |
| 409 |
/gcheck % <obj> gcheck <bool> |
| 410 |
/scheck load def |
| 411 |
/setglobal % <bool> setglobal - |
| 412 |
/setshared load def |
| 413 |
% We can make the global dictionaries very small, because they auto-expand. |
| 414 |
/globaldict currentdict /shareddict .knownget not { 4 dict } if def |
| 415 |
/GlobalFontDirectory SharedFontDirectory def |
| 416 |
|
| 417 |
% VMReclaim and VMThreshold are user parameters. |
| 418 |
/setvmthreshold { % <int> setvmthreshold - |
| 419 |
mark /VMThreshold 2 .argindex .dicttomark {.setuserparams2} stopped |
| 420 |
{pop /setvmthreshold load $error /errorname get signalerror} |
| 421 |
{pop} ifelse |
| 422 |
} odef |
| 423 |
/vmreclaim { % <int> vmreclaim - |
| 424 |
dup 0 gt { |
| 425 |
dup 2 le 1 index type /integertype eq and { |
| 426 |
pop % ignore user requests for vmreclaim |
| 427 |
% (reclaim will still happen controlled by vmthreshold) |
| 428 |
} |
| 429 |
{ .vmreclaim } % let internal operator handle error conditions |
| 430 |
ifelse |
| 431 |
} { |
| 432 |
% VMReclaim userparam controls enable/disable GC |
| 433 |
mark /VMReclaim 2 index .dicttomark {.setuserparams2} stopped |
| 434 |
{pop /vmreclaim load $error /errorname get signalerror} |
| 435 |
{pop} ifelse |
| 436 |
} ifelse |
| 437 |
} .forcebind odef |
| 438 |
-1 setvmthreshold |
| 439 |
|
| 440 |
% ------ IODevices ------ % |
| 441 |
|
| 442 |
/.getdevparams where { |
| 443 |
pop /currentdevparams { % <iodevice> currentdevparams <dict> |
| 444 |
.getdevparams .dicttomark |
| 445 |
} odef |
| 446 |
} if |
| 447 |
/.putdevparams where { |
| 448 |
pop /setdevparams { % <iodevice> <dict> setdevparams - |
| 449 |
dup type /dicttype ne { /setdevparams .systemvar /typecheck signalerror } if |
| 450 |
mark 1 index { } forall counttomark 2 add index |
| 451 |
.putdevparams pop pop |
| 452 |
} odef |
| 453 |
} if |
| 454 |
|
| 455 |
% ------ Job control ------ % |
| 456 |
|
| 457 |
serverdict begin |
| 458 |
|
| 459 |
% We could protect the job information better, but we aren't attempting |
| 460 |
% (currently) to protect ourselves against maliciousness. |
| 461 |
|
| 462 |
/.jobsave //null def % top-level save object |
| 463 |
/.jobsavelevel 0 def % save depth of job (0 if .jobsave is null, |
| 464 |
% 1 otherwise) |
| 465 |
/.adminjob //true def % status of current unencapsulated job |
| 466 |
|
| 467 |
end % serverdict |
| 468 |
|
| 469 |
% Because there may be objects on the e-stack created since the job save, |
| 470 |
% we have to clear the e-stack before doing the end-of-job restore. |
| 471 |
% We do this by executing a 2 .stop, which is caught by the 2 .stopped |
| 472 |
% in .runexec; we leave on the o-stack a procedure to execute aftewards. |
| 473 |
% |
| 474 |
%**************** The definition of startjob is not complete yet, since |
| 475 |
% it doesn't reset stdin/stdout. |
| 476 |
/.startnewjob { % <exit_bool> <password_level> |
| 477 |
% .startnewjob - |
| 478 |
serverdict /.jobsave get dup //null eq { pop } { restore } ifelse |
| 479 |
exch { |
| 480 |
% Unencapsulated job |
| 481 |
serverdict /.jobsave //null put |
| 482 |
serverdict /.jobsavelevel 0 put |
| 483 |
serverdict /.adminjob 3 -1 roll 1 gt put |
| 484 |
} { |
| 485 |
% Encapsulated job |
| 486 |
pop |
| 487 |
serverdict /.jobsave save put |
| 488 |
serverdict /.jobsavelevel 1 put |
| 489 |
.userdict /quit { stop } .forcebind put % CET 28-10 requires a procedure |
| 490 |
} ifelse |
| 491 |
% Reset the interpreter state. |
| 492 |
clear cleardictstack |
| 493 |
initgraphics |
| 494 |
//false setglobal |
| 495 |
} .internalbind def |
| 496 |
/.startjob { % <exit_bool> <password> <finish_proc> |
| 497 |
% .startjob <ok_bool> |
| 498 |
vmstatus pop pop serverdict /.jobsavelevel get eq |
| 499 |
2 .argindex .checkpassword 0 gt and { |
| 500 |
exch .checkpassword exch count 3 roll count 3 sub { pop } repeat |
| 501 |
cleardictstack |
| 502 |
% Reset the e-stack back to the 2 .stopped in .runexec, |
| 503 |
% passing the finish_proc to be executed afterwards. |
| 504 |
2 .stop |
| 505 |
} { % Password check failed |
| 506 |
pop pop pop //false |
| 507 |
} ifelse |
| 508 |
} odef |
| 509 |
/startjob { % <exit_bool> <password> startjob <ok_bool> |
| 510 |
% This is a hack. We really need some way to indicate explicitly |
| 511 |
% to the interpreter that we are under control of a job server. |
| 512 |
1 .argindex type /booleantype ne { |
| 513 |
/startjob .systemvar /typecheck signalerror |
| 514 |
} if |
| 515 |
{ .startnewjob //true } .startjob |
| 516 |
} odef |
| 517 |
|
| 518 |
systemdict begin |
| 519 |
/quit { % - quit - |
| 520 |
//systemdict begin serverdict /.jobsave get //null eq |
| 521 |
{ end //quit } |
| 522 |
{ /quit .systemvar /invalidaccess /signalerror load end exec } |
| 523 |
ifelse |
| 524 |
} .internalbind odef |
| 525 |
end |
| 526 |
|
| 527 |
% We would like to define exitserver as a procedure, using the code |
| 528 |
% that the Red Book says is equivalent to it. However, since startjob |
| 529 |
% resets the exec stack, we can't do this, because control would never |
| 530 |
% proceed past the call on startjob if the exitserver is successful. |
| 531 |
% Instead, we need to construct exitserver out of pieces of startjob. |
| 532 |
|
| 533 |
serverdict begin |
| 534 |
|
| 535 |
/exitserver { % <password> exitserver - |
| 536 |
//true exch { .startnewjob } .startjob not { |
| 537 |
/exitserver cvx /invalidaccess signalerror |
| 538 |
} if |
| 539 |
} .internalbind def |
| 540 |
|
| 541 |
end % serverdict |
| 542 |
|
| 543 |
% ------ Compatibility ------ % |
| 544 |
|
| 545 |
% In Level 2 mode, the following replace the definitions that gs_statd.ps |
| 546 |
% installs in statusdict and serverdict. |
| 547 |
% Note that statusdict must be allocated in local VM. |
| 548 |
% We don't bother with many of these yet. |
| 549 |
|
| 550 |
% convenience function to make a dictionary from an object and a key |
| 551 |
/.pair2dict { exch mark 3 1 roll .dicttomark } .internalbind def |
| 552 |
|
| 553 |
currentglobal //false setglobal 25 dict exch setglobal begin |
| 554 |
currentsystemparams |
| 555 |
|
| 556 |
% The following do not depend on the presence of setpagedevice. |
| 557 |
/buildtime 1 index /BuildTime get def |
| 558 |
% Also define /buildtime in systemdict because Adobe does so and some fonts use it as ID |
| 559 |
systemdict /buildtime dup load put |
| 560 |
/byteorder 1 index /ByteOrder get def |
| 561 |
/checkpassword { .checkpassword 0 gt } .internalbind def |
| 562 |
dup /DoStartPage known |
| 563 |
{ /dostartpage { /DoStartPage getsystemparam } .internalbind def |
| 564 |
/setdostartpage { /DoStartPage //.pair2dict exec setsystemparams } .internalbind def |
| 565 |
} if |
| 566 |
dup /StartupMode known |
| 567 |
{ /dosysstart { /StartupMode getsystemparam 0 ne } .internalbind def |
| 568 |
/setdosysstart { { 1 } { 0 } ifelse /StartupMode //.pair2dict exec setsystemparams } .internalbind def |
| 569 |
} if |
| 570 |
%****** Setting jobname is supposed to set userparams.JobName, too. |
| 571 |
/jobname { /JobName getuserparam } .internalbind def |
| 572 |
/jobtimeout { /JobTimeout getuserparam } .internalbind def |
| 573 |
/ramsize { /RamSize getsystemparam } .internalbind def |
| 574 |
/realformat 1 index /RealFormat get def |
| 575 |
dup /PrinterName known |
| 576 |
{ /setprintername { /PrinterName //.pair2dict exec setsystemparams } .internalbind def |
| 577 |
} if |
| 578 |
/printername |
| 579 |
{ currentsystemparams /PrinterName .knownget not { () } if exch copy |
| 580 |
} .internalbind def |
| 581 |
currentuserparams /WaitTimeout known |
| 582 |
{ /waittimeout { /WaitTimeout getuserparam } .internalbind def |
| 583 |
} if |
| 584 |
|
| 585 |
% The following do require setpagedevice. |
| 586 |
/.setpagedevice where { pop } { (%END PAGEDEVICE) .skipeof } ifelse |
| 587 |
/defaulttimeouts |
| 588 |
{ currentsystemparams dup |
| 589 |
/JobTimeout .knownget not { 0 } if |
| 590 |
exch /WaitTimeout .knownget not { 0 } if |
| 591 |
currentpagedevice /ManualFeedTimeout .knownget not { 0 } if |
| 592 |
} .internalbind def |
| 593 |
/margins |
| 594 |
{ currentpagedevice /Margins .knownget { exch } { [0 0] } ifelse |
| 595 |
} .internalbind def |
| 596 |
/pagemargin |
| 597 |
{ currentpagedevice /PageOffset .knownget { 0 get } { 0 } ifelse |
| 598 |
} .internalbind def |
| 599 |
/pageparams |
| 600 |
{ currentpagedevice |
| 601 |
dup /Orientation .knownget { 1 and ORIENT1 { 1 xor } if } { 0 } ifelse exch |
| 602 |
dup /PageSize get aload pop 3 index 0 ne { exch } if 3 2 roll |
| 603 |
/PageOffset .knownget { 0 get } { 0 } ifelse 4 -1 roll |
| 604 |
} .internalbind def |
| 605 |
/setdefaulttimeouts |
| 606 |
{ exch mark /ManualFeedTimeout 3 -1 roll |
| 607 |
/Policies mark /ManualFeedTimeout 1 .dicttomark |
| 608 |
.dicttomark setpagedevice |
| 609 |
/WaitTimeout exch mark /JobTimeout 5 2 roll .dicttomark setsystemparams |
| 610 |
} .internalbind def |
| 611 |
/setduplexmode { /Duplex //.pair2dict exec setpagedevice } .internalbind def |
| 612 |
/setmargins |
| 613 |
{ exch 2 array astore /Margins //.pair2dict exec setpagedevice |
| 614 |
} .internalbind def |
| 615 |
/setpagemargin { 0 2 array astore /PageOffset //.pair2dict exec setpagedevice } .internalbind def |
| 616 |
/setpageparams |
| 617 |
{ mark /PageSize 6 -2 roll |
| 618 |
4 index 1 and ORIENT1 { 1 } { 0 } ifelse ne { exch } if 2 array astore |
| 619 |
/Orientation 5 -1 roll ORIENT1 { 1 xor } if |
| 620 |
/PageOffset counttomark 2 add -1 roll 0 2 array astore |
| 621 |
.dicttomark setpagedevice |
| 622 |
} .internalbind def |
| 623 |
/setresolution |
| 624 |
{ count 1 lt { /setresolution cvx /stackunderflow signalerror } if |
| 625 |
dup type dup /integertype eq exch /realtype eq or not |
| 626 |
{ |
| 627 |
/setresolution cvx /typecheck signalerror |
| 628 |
} if |
| 629 |
dup 2 array astore /HWResolution //.pair2dict exec { setpagedevice } stopped { |
| 630 |
pop /setresolution cvx $error /errorname get signalerror |
| 631 |
} if |
| 632 |
} .internalbind def |
| 633 |
%END PAGEDEVICE |
| 634 |
|
| 635 |
% The following are not implemented yet. |
| 636 |
%manualfeed |
| 637 |
%manualfeedtimeout |
| 638 |
%pagecount |
| 639 |
%pagestackorder |
| 640 |
%setpagestackorder |
| 641 |
|
| 642 |
% -------- ICC manager -------- % |
| 643 |
% All color management is going |
| 644 |
% through ICC flow. We need |
| 645 |
% to have the default device |
| 646 |
% spaces gray, RGB and CMYK |
| 647 |
% defined by ICC profiles |
| 648 |
|
| 649 |
//systemdict /ICCProfilesDir .knownget { |
| 650 |
% Set the directory sepcified by the command line option |
| 651 |
mark exch /ICCProfilesDir exch .dicttomark .setuserparams2 |
| 652 |
} { |
| 653 |
% First see if the current value is valid so we don't have to guess |
| 654 |
mark .currentuserparams .dicttomark /ICCProfilesDir get |
| 655 |
(default_gray.icc) concatstrings {status} //.internalstopped exec |
| 656 |
{pop //false} if |
| 657 |
{ |
| 658 |
pop pop pop pop % current value was OK. Just clean up stack |
| 659 |
} { |
| 660 |
% Search for valid (iccprofiles) directory as a sibling to (Resource) |
| 661 |
% and set it as a default if found. |
| 662 |
LIBPATH { |
| 663 |
(Resource) rsearch { |
| 664 |
exch pop exch pop (iccprofiles) concatstrings |
| 665 |
.file_name_separator concatstrings |
| 666 |
dup (default_gray.icc) concatstrings status { |
| 667 |
pop pop pop pop |
| 668 |
mark exch /ICCProfilesDir exch .dicttomark .setuserparams2 |
| 669 |
exit |
| 670 |
} { |
| 671 |
pop |
| 672 |
} ifelse |
| 673 |
} { |
| 674 |
pop |
| 675 |
} ifelse |
| 676 |
} forall |
| 677 |
} ifelse % if currentuserparams ICCProfilesDir |
| 678 |
} ifelse % ICCProfilesDir set in systemdict (command line option) |
| 679 |
|
| 680 |
mark % collect dict key value pairs for anything set in systemdict (command line options) |
| 681 |
[ /DefaultRGBProfile /DefaultGrayProfile /DefaultCMYKProfile /DeviceNProfile |
| 682 |
/NamedProfile /SourceObjectICC /OverrideICC |
| 683 |
] |
| 684 |
{ dup //systemdict exch .knownget not { |
| 685 |
pop % discard keys not in systemdict |
| 686 |
} if |
| 687 |
} forall |
| 688 |
.dicttomark .setuserparams2 |
| 689 |
|
| 690 |
pop % currentsystemparams |
| 691 |
|
| 692 |
% Flag the current dictionary so it will be swapped when we |
| 693 |
% change language levels. (See zmisc2.c for more information.) |
| 694 |
/statusdict currentdict def |
| 695 |
|
| 696 |
currentdict end |
| 697 |
currentdict exch /statusdict exch .forceput % statusdict is local, systemdict is global |
| 698 |
|
| 699 |
% The following compatibility operators are in systemdict. They are |
| 700 |
% defined here, rather than in gs_init.ps, because they require the |
| 701 |
% resource machinery. |
| 702 |
|
| 703 |
/devforall { % <proc> <scratch> devforall - |
| 704 |
exch { |
| 705 |
1 index currentdevparams |
| 706 |
/Type .knownget { /FileSystem eq } { //false } ifelse |
| 707 |
{ exec } { pop pop } ifelse |
| 708 |
} /exec load 3 packedarray cvx exch |
| 709 |
(*) 3 1 roll /IODevice resourceforall |
| 710 |
} odef |
| 711 |
/devstatus { % <(%disk*%)> devstatus <searchable> <writable> |
| 712 |
% <hasNames> <mounted> <removable> <searchOrder> |
| 713 |
% <freePages> <size> true |
| 714 |
% <string> devstatus false |
| 715 |
dup length 5 ge { |
| 716 |
dup 0 5 getinterval (%disk) eq { |
| 717 |
dup /IODevice resourcestatus { |
| 718 |
pop pop dup currentdevparams |
| 719 |
dup /Searchable get |
| 720 |
exch dup /Writeable get |
| 721 |
exch dup /HasNames get |
| 722 |
exch dup /Mounted get |
| 723 |
exch dup /Removable get |
| 724 |
exch dup /SearchOrder get |
| 725 |
exch dup /Free get |
| 726 |
exch /LogicalSize get |
| 727 |
9 -1 roll pop //true |
| 728 |
} { |
| 729 |
pop //false |
| 730 |
} ifelse |
| 731 |
} { |
| 732 |
pop //false |
| 733 |
} ifelse |
| 734 |
} { |
| 735 |
pop //false |
| 736 |
} ifelse |
| 737 |
} odef |
| 738 |
|
| 739 |
% ------ Color spaces ------ % |
| 740 |
% gs_res.ps uses these entries in colorspacedict |
| 741 |
% to populate the ColorSpaceFamily resource, so we need |
| 742 |
% to add the supported spaces. |
| 743 |
% |
| 744 |
systemdict /colorspacedict get begin |
| 745 |
/CIEBasedA [] def |
| 746 |
/CIEBasedABC [] def |
| 747 |
/DevicePixel [] def |
| 748 |
/Indexed [] def |
| 749 |
/Pattern [] def |
| 750 |
/Separation [] def |
| 751 |
end |
| 752 |
|
| 753 |
% ------ CIE color rendering ------ % |
| 754 |
|
| 755 |
% Define findcolorrendering and a default ColorRendering ProcSet. |
| 756 |
|
| 757 |
/findcolorrendering { % <intentname> findcolorrendering |
| 758 |
% <crdname> <found> |
| 759 |
% Adobe interpreters report /findcolorrendering (literal name), not the |
| 760 |
% operator itself, if an error occurs in findcolorrendering. |
| 761 |
/findcolorrendering { |
| 762 |
/ColorRendering /ProcSet findresource |
| 763 |
1 .argindex dup type /nametype eq { .namestring } if (.) concatstrings |
| 764 |
1 index /GetPageDeviceName get exec dup type /nametype eq { .namestring } if (.) concatstrings |
| 765 |
2 index /GetHalftoneName get exec dup type /nametype eq { .namestring } if |
| 766 |
concatstrings concatstrings cvn % stack: intentname procset crdname |
| 767 |
dup /ColorRendering resourcestatus { |
| 768 |
pop pop exch pop exch pop //true |
| 769 |
} { |
| 770 |
pop /GetSubstituteCRD get exec //false |
| 771 |
} ifelse |
| 772 |
} .errorexec |
| 773 |
} odef |
| 774 |
|
| 775 |
5 dict dup begin |
| 776 |
|
| 777 |
/GetPageDeviceName { % - GetPageDeviceName <name> |
| 778 |
currentpagedevice dup /PageDeviceName .knownget { |
| 779 |
exch pop dup //null eq { pop /none } if |
| 780 |
} { |
| 781 |
pop /none |
| 782 |
} ifelse |
| 783 |
} .internalbind def |
| 784 |
|
| 785 |
/GetHalftoneName { % - GetHalftoneName <name> |
| 786 |
currenthalftone /HalftoneName .knownget not { /none } if |
| 787 |
} .internalbind def |
| 788 |
|
| 789 |
/GetSubstituteCRD { % <intentname> GetSubstituteCRD <crdname> |
| 790 |
pop /DefaultColorRendering |
| 791 |
} .internalbind def |
| 792 |
|
| 793 |
end |
| 794 |
% The resource machinery hasn't been activated, so just save the ProcSet |
| 795 |
% and let .fixresources finish the installation process. |
| 796 |
/ColorRendering exch def |
| 797 |
|
| 798 |
% Define setcolorrendering. |
| 799 |
|
| 800 |
/.colorrenderingtypes 5 dict def |
| 801 |
|
| 802 |
/setcolorrendering { % <crd> setcolorrendering - |
| 803 |
dup /ColorRenderingType get |
| 804 |
dup type /integertype ne { |
| 805 |
/setcolorrendering .systemvar /typecheck signalerror |
| 806 |
} if |
| 807 |
//.colorrenderingtypes exch .knownget { |
| 808 |
exec |
| 809 |
} { |
| 810 |
/setcolorrendering .systemvar /rangecheck signalerror |
| 811 |
} ifelse |
| 812 |
} odef |
| 813 |
|
| 814 |
/.setcolorrendering1 where { pop } { (%END CRD) .skipeof } ifelse |
| 815 |
|
| 816 |
.colorrenderingtypes 1 { |
| 817 |
% Adobe ProcSet "Adobe_AGM_Core 2.0 0" places an /Intent key into CRD's |
| 818 |
dup /Intent .knownget { |
| 819 |
//.renderingintentdict exch .knownget { .setrenderingintent } if |
| 820 |
} if |
| 821 |
dup .buildcolorrendering1 .setcolorrendering1 |
| 822 |
} .forcebind put |
| 823 |
|
| 824 |
% Note: the value 101 in the next line must be the same as the value of |
| 825 |
% GX_DEVICE_CRD1_TYPE in gscrdp.h. |
| 826 |
.colorrenderingtypes 101 { |
| 827 |
dup .builddevicecolorrendering1 .setdevicecolorrendering1 |
| 828 |
} .forcebind put |
| 829 |
|
| 830 |
% sRGB output CRD, D65 white point |
| 831 |
mark |
| 832 |
/ColorRenderingType 1 |
| 833 |
/RangePQR [ -0.5 2 -0.5 2 -0.5 2 ] readonly |
| 834 |
|
| 835 |
% Bradford Cone Space |
| 836 |
/MatrixPQR [ 0.8951 -0.7502 0.0389 |
| 837 |
0.2664 1.7135 -0.0685 |
| 838 |
-0.1614 0.0367 1.0296] readonly |
| 839 |
|
| 840 |
/MatrixLMN [ 3.240449 -0.969265 0.055643 |
| 841 |
-1.537136 1.876011 -0.204026 |
| 842 |
-0.498531 0.041556 1.057229 ] readonly |
| 843 |
|
| 844 |
% Inverse sRGB gamma transform |
| 845 |
/EncodeABC [ { dup 0.00304 le |
| 846 |
{ 12.92321 mul } |
| 847 |
{ 1 2.4 div exp 1.055 mul 0.055 sub } |
| 848 |
ifelse |
| 849 |
} bind dup dup |
| 850 |
] readonly |
| 851 |
|
| 852 |
/WhitePoint [ 0.9505 1 1.0890 ] readonly % D65 |
| 853 |
/BlackPoint [ 0 0 0 ] readonly |
| 854 |
|
| 855 |
% VonKries-like transform in Bradford Cone Space |
| 856 |
/TransformPQR |
| 857 |
% The implementations have been moved to C for performance. |
| 858 |
[ { .TransformPQR_scale_WB0 } bind |
| 859 |
{ .TransformPQR_scale_WB1 } bind |
| 860 |
{ .TransformPQR_scale_WB2 } bind |
| 861 |
] readonly |
| 862 |
.dicttomark setcolorrendering |
| 863 |
|
| 864 |
%END CRD |
| 865 |
|
| 866 |
% Initialize a CIEBased color space for sRGB. |
| 867 |
/CIEsRGB [ /CIEBasedABC |
| 868 |
mark |
| 869 |
/DecodeLMN [ { |
| 870 |
dup 0.03928 le { 12.92321 div } { 0.055 add 1.055 div 2.4 exp } ifelse |
| 871 |
} .internalbind dup dup ] readonly |
| 872 |
/MatrixLMN [ |
| 873 |
0.412457 0.212673 0.019334 |
| 874 |
0.357576 0.715152 0.119192 |
| 875 |
0.180437 0.072175 0.950301 |
| 876 |
] readonly |
| 877 |
/WhitePoint [0.9505 1.0 1.0890] readonly |
| 878 |
.dicttomark readonly |
| 879 |
] readonly def |
| 880 |
|
| 881 |
% Special type to install |
| 882 |
% sRGB ICC profile color space |
| 883 |
/CIEsRGBICC [ /ICCBased |
| 884 |
mark |
| 885 |
/N 3 |
| 886 |
/DataSource (srgb) |
| 887 |
/Alternate [/DeviceRGB] |
| 888 |
/Name (srgb) |
| 889 |
.dicttomark |
| 890 |
] def |
| 891 |
|
| 892 |
% Special type to install |
| 893 |
% sGray ICC profile color space |
| 894 |
/CIEsGRAYICC [ /ICCBased |
| 895 |
mark |
| 896 |
/N 1 |
| 897 |
/DataSource (sgray) |
| 898 |
/Alternate [/DeviceGray] |
| 899 |
/Name (sgray) |
| 900 |
.dicttomark |
| 901 |
] def |
| 902 |
|
| 903 |
% Special type to install |
| 904 |
% e-sRGB ICC profile color space |
| 905 |
/CIEesRGBICC [ /ICCBased |
| 906 |
mark |
| 907 |
/N 3 |
| 908 |
/DataSource (esrgb) |
| 909 |
/Alternate [/DeviceRGB] |
| 910 |
/Name (esrgb) |
| 911 |
.dicttomark |
| 912 |
] def |
| 913 |
|
| 914 |
% Special type to install |
| 915 |
% rommRGB ICC profile color space |
| 916 |
/CIErommRGBICC [ /ICCBased |
| 917 |
mark |
| 918 |
/N 3 |
| 919 |
/DataSource (rommrgb) |
| 920 |
/Alternate [/DeviceRGB] |
| 921 |
/Name (rommrgb) |
| 922 |
.dicttomark |
| 923 |
] def |
| 924 |
|
| 925 |
% ------ Painting ------ % |
| 926 |
|
| 927 |
% A straightforward definition of execform that doesn't actually |
| 928 |
% do any caching. |
| 929 |
/.execform1 { |
| 930 |
% This is a separate operator so that the stacks will be restored |
| 931 |
% properly if an error occurs. |
| 932 |
%% High level forms need the CTM before the Form Matrix is applied |
| 933 |
/UNROLLFORMS where {/UNROLLFORMS get}{//false}ifelse not |
| 934 |
{matrix currentmatrix exch} if |
| 935 |
dup /Matrix get concat |
| 936 |
dup /BBox get aload pop |
| 937 |
exch 3 index sub exch 2 index sub rectclip |
| 938 |
dup /PaintProc get |
| 939 |
1 index /Implementation known not { |
| 940 |
1 index dup /Implementation //null .forceput readonly pop |
| 941 |
} executeonly if |
| 942 |
/UNROLLFORMS where {/UNROLLFORMS get}{//false}ifelse not |
| 943 |
%% [CTM] <<Form>> PaintProc .beginform - |
| 944 |
{ |
| 945 |
%% First,, check to see if we have no /Implementation already defined (see above) |
| 946 |
1 index /Implementation get //null eq |
| 947 |
{ |
| 948 |
%% We don't, so copy the form dictionary |
| 949 |
1 index 4 1 roll |
| 950 |
%% tell devices we're starting a form, run the PaintProc, and then tell the devices we've finished |
| 951 |
3 -1 roll 2 index |
| 952 |
.beginform exec |
| 953 |
|
| 954 |
%% This is all horrible code to deal with illegal forms which leave junk on the operand stack |
| 955 |
%% Starting from 1 (not 0, we don't want to look at the loop count) and going up to the |
| 956 |
%% number of objects on the stack, check each object to see if its the Form dict (it is |
| 957 |
%% *supposed* to be the top object after executing the PaintProc). I don't currently check to see if |
| 958 |
%% the PaintProc ate the dict, but if there are extra objects, remove them and tell |
| 959 |
%% the user. |
| 960 |
%% |
| 961 |
count 1 1 3 -1 roll { |
| 962 |
dup index |
| 963 |
dup type /dicttype eq { |
| 964 |
/Implementation known { |
| 965 |
2 sub 0 1 3 -1 roll { |
| 966 |
QUIET not { |
| 967 |
(\n WARNING - Form PaintProc left operands on the stack after execution.\n This is technically illegal and these have been removed, \n if output is incorrect run again with -dUNROLLFORMS.\n) = |
| 968 |
} if |
| 969 |
pop pop |
| 970 |
} for |
| 971 |
exit |
| 972 |
}if |
| 973 |
} { |
| 974 |
pop pop |
| 975 |
}ifelse |
| 976 |
} for |
| 977 |
|
| 978 |
.endform |
| 979 |
%% Ask devices if they have cached the form, and what ID to use if so |
| 980 |
%% returning -1 means 'no ID' |
| 981 |
.get_form_id dup -1 eq |
| 982 |
{pop pop} |
| 983 |
{ |
| 984 |
%% The form is cached with a specific ID. Make a dictionary (which we'll store in the |
| 985 |
%% Form dictioanry using the /Implementation key). |
| 986 |
1 dict dup /FormID 4 -1 roll put |
| 987 |
1 index exch /Implementation exch .forceput readonly pop |
| 988 |
} executeonly |
| 989 |
ifelse |
| 990 |
} |
| 991 |
{ |
| 992 |
%% We have a (non-null) Implementation, get the dictionary and pull the |
| 993 |
%% FormID key from it, then tell the device to use the stored form with the |
| 994 |
%% specified key. |
| 995 |
pop dup /Implementation get /FormID get .repeatform |
| 996 |
}ifelse |
| 997 |
} |
| 998 |
{exec} ifelse |
| 999 |
} .forcebind odef % must .internalbind .forceput |
| 1000 |
|
| 1001 |
/.formtypes 5 dict |
| 1002 |
dup 1 /.execform1 load put |
| 1003 |
def |
| 1004 |
|
| 1005 |
/execform { % <form> execform - |
| 1006 |
gsave { |
| 1007 |
dup /FormType get //.formtypes exch get exec |
| 1008 |
} stopped grestore { stop } if |
| 1009 |
} odef |
| 1010 |
|
| 1011 |
/.patterntypes 5 dict |
| 1012 |
dup 1 /.buildpattern1 load put |
| 1013 |
def |
| 1014 |
|
| 1015 |
/makepattern { % <proto_dict> <matrix> makepattern <pattern> |
| 1016 |
dup type /dicttype eq { |
| 1017 |
% "<dict> makepattern" reports /typecheck on Adobe |
| 1018 |
/makepattern .systemvar /typecheck signalerror |
| 1019 |
} if |
| 1020 |
//.patterntypes 2 .argindex /PatternType get .knownget not { |
| 1021 |
/makepattern .systemvar /rangecheck signalerror |
| 1022 |
} if |
| 1023 |
.currentglobal //false .setglobal exch |
| 1024 |
% Stack: proto matrix global buildproc |
| 1025 |
3 index dup length 1 add dict .copydict |
| 1026 |
% Stack: proto matrix global buildproc newdict |
| 1027 |
3 index 3 -1 roll exec |
| 1028 |
% Stack: proto matrix global newdict instance |
| 1029 |
% Create an 'Implementation' entry for the pattern dict. The PRLM 3rd says |
| 1030 |
% this about the contents of Implementation: "The type and value of this |
| 1031 |
% entry are implementation-dependent." The CET (page 2 of 18-02f) expects |
| 1032 |
% that this entry be an array and that the second element of the array be a |
| 1033 |
% gstate. We put our pattern instance struct into the first element of the |
| 1034 |
% array. |
| 1035 |
1 index /Implementation 3 -1 roll |
| 1036 |
.getCPSImode { gstate } { //null } ifelse 2 array astore |
| 1037 |
put % put Implementation into the pattern dict. |
| 1038 |
% Stack: proto matrix global newdict |
| 1039 |
readonly exch .setglobal exch pop exch pop |
| 1040 |
} odef |
| 1041 |
|
| 1042 |
/setpattern { % [<comp1> ...] <pattern> setpattern - |
| 1043 |
{ currentcolorspace 0 get /Pattern ne { |
| 1044 |
[ /Pattern currentcolorspace ] setcolorspace |
| 1045 |
} if setcolor |
| 1046 |
} stopped { |
| 1047 |
/setpattern .systemvar $error /errorname get signalerror |
| 1048 |
} if |
| 1049 |
} odef |
| 1050 |
|
| 1051 |
% The following functions emulate the actions of findcmykcustomcolor and |
| 1052 |
% setcustomcolor. These functions are described in Adobe's TN 5044. That |
| 1053 |
% same document also says "The following "operators" are not defined in the |
| 1054 |
% PostScript Language Reference Manual, but should be used as pseudo-operators |
| 1055 |
% in your PostScript language output. Separation applications from Adobe |
| 1056 |
% Systems and other vendors will redefine these convention operators to |
| 1057 |
% separate your documents. Your application should conditionally define |
| 1058 |
% procedures with these special names, as shown later in this document." |
| 1059 |
% |
| 1060 |
% We are providing these functions because we have found files created by |
| 1061 |
% "QuarkXPress: pictwpstops filter 1.0" which produce bad shading dictionaries |
| 1062 |
% if these operators are not defined. |
| 1063 |
|
| 1064 |
% Also we add a findrgbcustomcolor that was discovered in Adobe Illustrator |
| 1065 |
% AI5 (Adobe Illustrator (R) Version 7.0 Full Prolog) ProcSet that allows |
| 1066 |
% us to create Separation colorspace with a /DeviceRGB tint transform. |
| 1067 |
|
| 1068 |
% Conditionally disable the TN 5044 psuedo-ops if NO_TN5044 specified |
| 1069 |
/NO_TN5044 where { pop (%END TN 5044 psuedo-ops) .skipeof } if |
| 1070 |
|
| 1071 |
% TN 5044 does not define the contents of the array. We are simply putting |
| 1072 |
% the values given into an array. This is consistent with what we see when |
| 1073 |
% testing with Adobe Distiller 6.0. |
| 1074 |
% <cyan> <magenta> <yellow> <black> <key> findcmykcustomcolor <array> |
| 1075 |
/findcmykcustomcolor { 5 array astore } .internalbind def |
| 1076 |
% The following isn't documented by Adobe, but was found in Adobe Illustrator (R) |
| 1077 |
% Version 7.0 Full Prolog |
| 1078 |
/findrgbcustomcolor { 4 array astore } .internalbind def |
| 1079 |
|
| 1080 |
% Build a tint transform function for use by setcustomcolor. This function |
| 1081 |
% is for a Separation color space which has either a DeviceCMYK base color space |
| 1082 |
% (i.e. 1 input and 4 outputs) or a DeviceRGB colorspace (1 in, 3 out). |
| 1083 |
% The input to buildcustomtinttransform is the array created by findcmykcustomcolor |
| 1084 |
% and the length of the array is used to determine the alternate colorspace. |
| 1085 |
% The resulting function for CMYK is: |
| 1086 |
% { dup cyan mul exch dup magenta mul exch dup yellow mul exch black mul } |
| 1087 |
% Where cyan, magenta, yellow, and black are values from the array. |
| 1088 |
% For RGB, since the resulting function is: |
| 1089 |
% { dup red mul exch dup green mul exch blue mul } |
| 1090 |
/buildcustomtinttransform % <array> buildcustomtinttransform <function> |
| 1091 |
{ |
| 1092 |
dup length 5 eq { |
| 1093 |
% CMYK |
| 1094 |
[ /dup load 2 index 0 get /mul load |
| 1095 |
/exch load /dup load 6 index 1 get /mul load |
| 1096 |
/exch load /dup load 10 index 2 get /mul load |
| 1097 |
/exch load 13 index 3 get /mul load |
| 1098 |
] |
| 1099 |
} { |
| 1100 |
% RGB is assumed |
| 1101 |
[ /dup load 2 index 0 get /mul load |
| 1102 |
/exch load /dup load 6 index 1 get /mul load |
| 1103 |
/exch load 9 index 2 get /mul load |
| 1104 |
] |
| 1105 |
} ifelse |
| 1106 |
cvx bind exch pop % Make executable and remove the input array |
| 1107 |
} .internalbind def |
| 1108 |
|
| 1109 |
% Construct the colorspace array to be used by setcolorspace from the array |
| 1110 |
% result of either findcmykcustomcolor or findrgbcustomcolor. |
| 1111 |
/buildcolorspacearray % <array> buildcustomtinttransform <colorspace_array> |
| 1112 |
{ % as with buildcustomtinttransform, the length of the array is used to |
| 1113 |
% determine the alternate colorspace |
| 1114 |
dup length 5 eq { |
| 1115 |
% Start building Separation colorspace with CMYK alternate |
| 1116 |
[ /Separation 2 index 4 get % Get separation name from array's key |
| 1117 |
/DeviceCMYK |
| 1118 |
4 index //buildcustomtinttransform exec % build the tint transform function |
| 1119 |
] |
| 1120 |
} { |
| 1121 |
[ /Separation 2 index 3 get % Get separation name from array's key |
| 1122 |
/DeviceRGB |
| 1123 |
4 index //buildcustomtinttransform exec % build the tint transform function |
| 1124 |
] |
| 1125 |
} ifelse |
| 1126 |
exch pop % remove the input array |
| 1127 |
} .internalbind def |
| 1128 |
|
| 1129 |
% Set a custom color based upon a tint and array which describes the custom |
| 1130 |
% color. See findcmykcustomcolor. First we create and then set a Separation |
| 1131 |
% colorspace. Then we set the specified color. |
| 1132 |
% Note that older Adobe ProcSets apparently allow for 'null' as the tint |
| 1133 |
% for some reason, so an alternate operational mode is tolerated: |
| 1134 |
% null setcustomcolor - |
| 1135 |
/setcustomcolor % <array> <tint> setcustomcolor - |
| 1136 |
{ |
| 1137 |
dup //null eq { |
| 1138 |
pop pop |
| 1139 |
}{ |
| 1140 |
% Check that the tint is a number between 0 and 1 |
| 1141 |
dup type dup /integertype eq exch /realtype eq or not { |
| 1142 |
/setcustomcolor cvx /typecheck signalerror |
| 1143 |
} if |
| 1144 |
% Bug 703869. Apparently Adobe (at least Acrobat Pro) silently clamps values |
| 1145 |
dup 1 le not { |
| 1146 |
pop 1 |
| 1147 |
} if |
| 1148 |
dup 0 ge not { |
| 1149 |
pop 0 |
| 1150 |
} if |
| 1151 |
|
| 1152 |
% The array is supposed to be the result of fundcmykcustomcolor. Our |
| 1153 |
% implementation just pushes all the arguments into the array and that's |
| 1154 |
% what buildcolorspacearray expects. So check that now. |
| 1155 |
% Starting with the first N-1 elemenst which must be numbers where 0 <= x <= 1 |
| 1156 |
1 index |
| 1157 |
0 1 2 index length 2 sub |
| 1158 |
{ |
| 1159 |
1 index exch get dup |
| 1160 |
type dup /integertype eq exch /realtype eq or not { |
| 1161 |
/setcustomcolor cvx /typecheck signalerror |
| 1162 |
} if |
| 1163 |
dup |
| 1164 |
1 le not { |
| 1165 |
/setcustomcolor cvx /rangecheck signalerror |
| 1166 |
} if |
| 1167 |
0 ge not { |
| 1168 |
/setcustomcolor cvx /rangecheck signalerror |
| 1169 |
} if |
| 1170 |
} for |
| 1171 |
|
| 1172 |
% Finally, check the last element of the array, which must be a string. |
| 1173 |
dup length 1 sub get type /stringtype eq not { |
| 1174 |
/setcustomcolor cvx /typecheck signalerror |
| 1175 |
} if |
| 1176 |
|
| 1177 |
exch //buildcolorspacearray exec |
| 1178 |
setcolorspace % Set the Separation color space as current |
| 1179 |
setcolor % Set the tint as the current color |
| 1180 |
} ifelse |
| 1181 |
} .internalbind def |
| 1182 |
|
| 1183 |
% This proc is supposed to implement a version of overprinting. TN 5044 says |
| 1184 |
% that this proc is not used by any shipping host-based application. We have |
| 1185 |
% only found it being used in a proc set in files by Canvas from Deneba Systems. |
| 1186 |
% Even their proc set does not actually do any overprinting. However their |
| 1187 |
% files crash if this is not defined. Thus we have a copy of this proc but |
| 1188 |
% we are simply checking for inputs being -1 and if so then we set the value |
| 1189 |
% to 0. |
| 1190 |
/setcmykoverprint { |
| 1191 |
4 { dup -1 eq { pop 0 } if 4 1 roll } repeat setcmykcolor |
| 1192 |
} .internalbind def |
| 1193 |
|
| 1194 |
/separation_all [/Separation /All /DeviceCMYK { dup dup dup } .internalbind ] readonly def |
| 1195 |
|
| 1196 |
% Collect the arguments into the image dictionary |
| 1197 |
% <width> <height> <bits/sample> <matrix> <proc> args2dict <dict> |
| 1198 |
/args2dict { |
| 1199 |
10 dict begin |
| 1200 |
{1 0} 1 |
| 1201 |
{ /ImageType /Decode /DataSource /ImageMatrix /BitsPerComponent /Height /Width |
| 1202 |
} { exch def } forall |
| 1203 |
currentdict end |
| 1204 |
} .internalbind def |
| 1205 |
|
| 1206 |
% Prints (1-gray) on all separations. |
| 1207 |
% <gray> setseparationgray - |
| 1208 |
/setseparationgray { |
| 1209 |
//separation_all setcolorspace |
| 1210 |
1 exch sub setcolor |
| 1211 |
} .internalbind def |
| 1212 |
|
| 1213 |
% Renders an image whose sample values specify the amount of the custom color. |
| 1214 |
% <width> <height> <bits/sample> <matrix> <proc> <array> customcolorimage - |
| 1215 |
/customcolorimage { |
| 1216 |
gsave |
| 1217 |
//buildcolorspacearray exec setcolorspace |
| 1218 |
//args2dict exec image |
| 1219 |
grestore |
| 1220 |
} .internalbind def |
| 1221 |
|
| 1222 |
% Renders an image on all process and custom color plates. |
| 1223 |
% <width> <height> <bits/sample> <matrix> <proc> |
| 1224 |
/separationimage { |
| 1225 |
gsave |
| 1226 |
//separation_all setcolorspace |
| 1227 |
//args2dict exec image |
| 1228 |
grestore |
| 1229 |
} .internalbind def |
| 1230 |
|
| 1231 |
{ /buildcustomtinttransform /buildcolorspacearray /separation_all /args2dict } |
| 1232 |
{ currentdict exch undef } forall |
| 1233 |
|
| 1234 |
%END TN 5044 psuedo-ops |
| 1235 |
|
| 1236 |
end % level2dict |
| 1237 |
|
| 1238 |
% undefine things defined in this file and not referenced elsewhere |
| 1239 |
[ |
| 1240 |
/.checkprocesscomment |
| 1241 |
/.pair2dict |
| 1242 |
/.setcolorrendering1 |
| 1243 |
/.checkparamtype |
| 1244 |
/.checksetparams |
| 1245 |
] dup level2dict .undefinternalnames |
| 1246 |
systemdict .undefinternalnames |