1
1
% Copyright (C) 1990, 2000 Aladdin Enterprises. All rights reserved.
3
3
% This software is provided AS-IS with no warranty, either express or
6
6
% This software is distributed under license and may not be copied,
7
7
% modified or distributed except as expressly authorized under the terms
8
8
% of the license contained in the file LICENSE in this distribution.
10
10
% For more information about licensing, please refer to
11
11
% http://www.ghostscript.com/licensing/. For information on
12
12
% commercial licensing, go to http://www.artifex.com/licensing/ or
13
13
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14
14
% San Rafael, CA 94903, U.S.A., +1(415)492-9861.
16
% $Id: gs_lev2.ps 12268 2011-03-10 06:19:17Z alexcher $
17
17
% Initialization file for Level 2 functions.
18
18
% When this is run, systemdict is still writable,
19
19
% but (almost) everything defined here goes into level2dict.
51
51
/.checksetparams { % <newdict> <opname> <checkdict>
52
% .checksetparams <newdict>
52
% .checksetparams <newdict>
54
% Stack: newdict opname checkdict key newvalue
54
% Stack: newdict opname checkdict key newvalue
55
55
3 copy 3 1 roll .knownget {
57
pop pop pop load /typecheck signalerror
57
pop pop pop load /typecheck signalerror
59
59
dup type /stringtype eq {
61
pop pop pop load /invalidaccess signalerror
61
pop pop pop load /invalidaccess signalerror
75
75
% be changed. Also be careful to preserve 'executable' state.
76
76
/.copyparam { % <value> .copyparam <value'>
77
77
dup type /arraytype eq {
78
.currentglobal //true .setglobal exch
78
.currentglobal //true .setglobal exch
79
79
dup wcheck exch dup xcheck exch % original attributes
80
80
dup length array exch dup { % stack: destination_array original_array original_array
81
81
dup type /arraytype eq {
82
dup 2 index ne { % avoid recursion
82
dup 2 index ne { % avoid recursion
83
83
.copyparam % recurse to handle composite array elements
85
% this array self referenced, do it again (yuk!)
86
pop 1 index % get copy of destination array
85
% this array self referenced, do it again (yuk!)
86
pop 1 index % get copy of destination array
89
89
dup type /stringtype eq {
93
93
ifelse 3 1 roll % keep arrays on top
94
94
} forall pop astore
128
128
% We break out setuserparams into a separate procedure so that setvmxxx
129
129
% can use it without affecting the command in case of an error.
130
130
/.setuserparams2 {
131
% Check that we will be able to set the PostScript-level
131
% Check that we will be able to set the PostScript-level
133
133
/setuserparams /psuserparams .systemvar .checksetparams
134
% Set the C-level user params. If this succeeds, we know that
135
% the password check succeeded.
134
% Set the C-level user params. If this succeeds, we know that
135
% the password check succeeded.
136
136
dup .setuserparams
137
% Now set the PostScript-level params.
138
% The interpreter may have adjusted the values of some of the
139
% parameters, so we have to read them back.
137
% Now set the PostScript-level params.
138
% The interpreter may have adjusted the values of some of the
139
% parameters, so we have to read them back.
141
141
/userparams .systemvar 2 index known {
142
142
psuserparams 2 index known not {
143
pop dup .getuserparam
143
pop dup .getuserparam
146
146
% special protection for the security related parameters
147
147
[ /PermitFileReading /PermitFileWriting /PermitFileControl ]
148
148
{ 2 index eq { % force all strings to readonly but make sure the
149
% array is in the correct VM space (local/global).
150
currentglobal exch dup gcheck setglobal
151
dup length array exch { readonly exch } forall astore
149
% array is in the correct VM space (local/global).
150
currentglobal exch dup gcheck setglobal
151
dup length array exch { readonly exch } forall astore
155
155
% protect top level of parameters that we copied
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.
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.
168
168
/setuserparams { % <dict> setuserparams -
191
191
mark .currentsystemparams //pssystemparams { } forall .dicttomark
193
193
/setsystemparams { % <dict> setsystemparams -
194
% Check that we will be able to set the PostScript-level
194
% Check that we will be able to set the PostScript-level
196
196
dup pop % check # of args
197
197
/SAFETY .systemvar /safe get {
198
198
% SAFER mode disallows some changes
199
199
[ /GenericResourceDir /FontResourceDir /GenericResourcePathSep ] {
200
200
2 copy .knownget {
201
exch //pssystemparams exch .knownget {
201
exch //pssystemparams exch .knownget {
202
202
ne { /setsystemparams /invalidaccess signalerror } if
211
211
/setsystemparams //pssystemparams mark exch {
212
212
type cvlit /.checkparamtype cvx 2 packedarray cvx
213
213
} forall .dicttomark .checksetparams
214
% Set the C-level system params. If this succeeds, we know that
215
% the password check succeeded.
214
% Set the C-level system params. If this succeeds, we know that
215
% the password check succeeded.
216
216
dup .setsystemparams
217
% Now set the PostScript-level params. We must copy local strings
217
% Now set the PostScript-level params. We must copy local strings
220
220
{ //pssystemparams 2 index known
221
221
{ % Stack: key newvalue
223
% protect top level parameters that we copied
223
% protect top level parameters that we copied
224
224
dup type dup /arraytype eq exch /stringtype eq or { readonly } if
225
//pssystemparams 3 1 roll .forceput % pssystemparams is read-only
225
//pssystemparams 3 1 roll .forceput % pssystemparams is read-only
248
248
/setcacheparams {
249
% The MaxFontCache parameter is a system parameter, which we might
250
% not be able to set. Fortunately, this doesn't matter, because
251
% system parameters don't have to be synchronized between this code
249
% The MaxFontCache parameter is a system parameter, which we might
250
% not be able to set. Fortunately, this doesn't matter, because
251
% system parameters don't have to be synchronized between this code
253
253
counttomark 1 add copy setcacheparams
254
254
currentcacheparams % mark size lower upper
463
463
%**************** The definition of startjob is not complete yet, since
464
464
% it doesn't reset stdin/stdout.
465
465
/.startnewjob { % <exit_bool> <password_level>
467
467
serverdict /.jobsave get dup //null eq { pop } { restore } ifelse
470
470
serverdict /.jobsave //null put
471
471
serverdict /.jobsavelevel 0 put
472
472
serverdict /.adminjob 3 -1 roll 1 gt put
476
476
serverdict /.jobsave save put
477
477
serverdict /.jobsavelevel 1 put
478
478
.userdict /quit { stop } .bind put % CET 28-10 requires a procedure
480
% Reset the interpreter state.
480
% Reset the interpreter state.
481
481
clear cleardictstack
483
483
//false setglobal
484
484
2 vmreclaim % Make sure GC'ed memory is reclaimed and freed.
486
486
/.startjob { % <exit_bool> <password> <finish_proc>
487
% .startjob <ok_bool>
487
% .startjob <ok_bool>
488
488
vmstatus pop pop serverdict /.jobsavelevel get eq
489
489
2 .argindex .checkpassword 0 gt and {
490
490
exch .checkpassword exch count 3 roll count 3 sub { pop } repeat
492
% Reset the e-stack back to the 2 .stopped in .runexec,
493
% passing the finish_proc to be executed afterwards.
492
% Reset the e-stack back to the 2 .stopped in .runexec,
493
% passing the finish_proc to be executed afterwards.
495
495
} { % Password check failed
496
496
pop pop pop //false
499
499
/startjob { % <exit_bool> <password> startjob <ok_bool>
500
% This is a hack. We really need some way to indicate explicitly
501
% to the interpreter that we are under control of a job server.
500
% This is a hack. We really need some way to indicate explicitly
501
% to the interpreter that we are under control of a job server.
502
502
1 .argindex type /booleantype ne {
503
503
/startjob .systemvar /typecheck signalerror
505
505
{ .startnewjob //true } .startjob
508
% The procedure to undo the job encapsulation
508
% The procedure to undo the job encapsulation
510
510
clear cleardictstack
511
511
serverdict /.jobsave get dup //null eq { pop } { restore } ifelse
646
645
mark .currentuserparams .dicttomark /ICCProfilesDir get
647
646
(default_gray.icc) concatstrings status {
648
647
pop pop pop pop % current value was OK. Just clean up stack
650
649
% Search for valid (iccprofiles) directory as a sibling to (Resource)
651
650
% and set it as a default if found.
653
652
(Resource) search {
654
653
exch pop exch pop (iccprofiles) concatstrings
655
654
.file_name_separator concatstrings
704
//systemdict /SourceObjectICC .knownget{
705
mark exch /SourceObjectICC exch .dicttomark
709
//systemdict /OverrideICC .knownget{
710
mark exch /OverrideICC exch .dicttomark
714
//systemdict /OverrideRI .knownget{
715
mark exch /OverrideRI exch .dicttomark
705
719
pop % currentsystemparams
707
721
% Flag the current dictionary so it will be swapped when we
724
738
(*) 3 1 roll /IODevice resourceforall
726
740
/devstatus { % <(%disk*%)> devstatus <searchable> <writable>
727
% <hasNames> <mounted> <removable> <searchOrder>
728
% <freePages> <size> true
729
% <string> devstatus false
741
% <hasNames> <mounted> <removable> <searchOrder>
742
% <freePages> <size> true
743
% <string> devstatus false
730
744
dup length 5 ge {
731
745
dup 0 5 getinterval (%disk) eq {
732
746
dup /IODevice resourcestatus {
733
pop pop dup currentdevparams
735
exch dup /Writeable get
736
exch dup /HasNames get
737
exch dup /Mounted get
738
exch dup /Removable get
739
exch dup /SearchOrder get
741
exch /LogicalSize get
747
pop pop dup currentdevparams
749
exch dup /Writeable get
750
exch dup /HasNames get
751
exch dup /Mounted get
752
exch dup /Removable get
753
exch dup /SearchOrder get
755
exch /LogicalSize get
765
779
/Separation [] def
770
782
% ------ CIE color rendering ------ %
772
784
% Define findcolorrendering and a default ColorRendering ProcSet.
774
786
/findcolorrendering { % <intentname> findcolorrendering
776
788
% Adobe interpreters report /findcolorrendering (literal name), not the
777
789
% operator itself, if an error occurs in findcolorrendering.
778
790
/findcolorrendering {
779
/ColorRendering /ProcSet findresource
780
1 .argindex dup type /nametype eq { .namestring } if (.) concatstrings
781
1 index /GetPageDeviceName get exec dup type /nametype eq { .namestring } if (.) concatstrings
782
2 index /GetHalftoneName get exec dup type /nametype eq { .namestring } if
783
concatstrings concatstrings cvn % stack: intentname procset crdname
784
dup /ColorRendering resourcestatus {
785
pop pop exch pop exch pop //true
787
pop /GetSubstituteCRD get exec //false
791
/ColorRendering /ProcSet findresource
792
1 .argindex dup type /nametype eq { .namestring } if (.) concatstrings
793
1 index /GetPageDeviceName get exec dup type /nametype eq { .namestring } if (.) concatstrings
794
2 index /GetHalftoneName get exec dup type /nametype eq { .namestring } if
795
concatstrings concatstrings cvn % stack: intentname procset crdname
796
dup /ColorRendering resourcestatus {
797
pop pop exch pop exch pop //true
799
pop /GetSubstituteCRD get exec //false
831
843
/.setcolorrendering1 where { pop } { (%END CRD) .skipeof } ifelse
833
845
.colorrenderingtypes 1 {
834
% Adobe ProcSet "Adobe_AGM_Core 2.0 0" places an /Intent key into CRD's
846
% Adobe ProcSet "Adobe_AGM_Core 2.0 0" places an /Intent key into CRD's
835
847
dup /Intent .knownget {
836
848
//.renderingintentdict exch .knownget { .setrenderingintent } if
852
864
% Bradford Cone Space
853
865
/MatrixPQR [ 0.8951 -0.7502 0.0389
854
0.2664 1.7135 -0.0685
855
-0.1614 0.0367 1.0296] readonly
866
0.2664 1.7135 -0.0685
867
-0.1614 0.0367 1.0296] readonly
857
869
/MatrixLMN [ 3.240449 -0.969265 0.055643
858
-1.537136 1.876011 -0.204026
859
-0.498531 0.041556 1.057229 ] readonly
870
-1.537136 1.876011 -0.204026
871
-0.498531 0.041556 1.057229 ] readonly
861
873
% Inverse sRGB gamma transform
862
874
/EncodeABC [ { dup 0.00304 le
874
886
% The implementations have been moved to C for performance.
875
887
[ { .TransformPQR_scale_WB0 } bind
876
{ .TransformPQR_scale_WB1 } bind
888
{ .TransformPQR_scale_WB1 } bind
877
889
{ .TransformPQR_scale_WB2 } bind
879
891
.dicttomark setcolorrendering
895
907
.dicttomark readonly
899
910
% Special type to install
900
911
% sRGB ICC profile color space
901
912
/CIEsRGBICC [ /ICCBased
904
915
/DataSource (srgb)
905
916
/Alternate [/DeviceRGB]
910
921
% Special type to install
911
922
% sGray ICC profile color space
912
923
/CIEsGRAYICC [ /ICCBased
915
926
/DataSource (sgray)
916
927
/Alternate [/DeviceGray]
921
932
% ------ Painting ------ %
923
934
% A straightforward definition of execform that doesn't actually
924
935
% do any caching.
926
% This is a separate operator so that the stacks will be restored
927
% properly if an error occurs.
937
% This is a separate operator so that the stacks will be restored
938
% properly if an error occurs.
928
939
dup /Matrix get concat
929
940
dup /BBox get aload pop
930
941
exch 3 index sub exch 2 index sub rectclip
958
969
/makepattern .systemvar /rangecheck signalerror
960
971
.currentglobal //false .setglobal exch
961
% Stack: proto matrix global buildproc
972
% Stack: proto matrix global buildproc
962
973
3 index dup length 1 add dict .copydict
963
% Stack: proto matrix global buildproc newdict
974
% Stack: proto matrix global buildproc newdict
964
975
3 index 3 -1 roll exec
965
% Stack: proto matrix global newdict instance
976
% Stack: proto matrix global newdict instance
966
977
% Create an 'Implementation' entry for the pattern dict. The PRLM 3rd says
967
978
% this about the contents of Implementation: "The type and value of this
968
979
% entry are implementation-dependent." The CET (page 2 of 18-02f) expects
972
983
1 index /Implementation 3 -1 roll
973
984
.getCPSImode { gstate } { //null } ifelse 2 array astore
974
985
put % put Implementation into the pattern dict.
975
% Stack: proto matrix global newdict
986
% Stack: proto matrix global newdict
976
987
readonly exch .setglobal exch pop exch pop
997
1008
% We are providing these functions because we have found files created by
998
1009
% "QuarkXPress: pictwpstops filter 1.0" which produce bad shading dictionaries
999
% if these operators are not defined.
1010
% if these operators are not defined.
1001
1012
% Conditionally disable the TN 5044 psuedo-ops if NO_TN5044 specified
1002
1013
/NO_TN5044 where { pop (%END TN 5044 psuedo-ops) .skipeof } if