1 % Copyright (C) 1997, 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_ll3.ps,v 1.20 2003/10/22 11:22:29 alexcher Exp $
17 % Initialization file for PostScript LanguageLevel 3 functions.
18 % This file must be loaded after gs_lev2.ps and gs_res.ps.
19 % These definitions go into ll3dict or various ProcSets.
20 % NOTE: the interpreter creates ll3dict.
24 % We need LanguageLevel 2 or higher in order to have setuserparams and
26 languagelevel dup 2 .max .setlanguagelevel
28 % ------ Idiom recognition ------ %
30 /IdiomRecognition false .definepsuserparam
32 % Modify `bind' to apply idiom recognition afterwards.
33 /.bindscratch 128 string def
34 % Note that since this definition of `bind' may get bound in,
35 % it has to function properly even at lower language levels,
36 % where IdiomRecognition may not be defined.
37 /.bind { % <proc> .bind <proc'>
38 //.bind currentuserparams /IdiomRecognition
39 .knownget not { false } if {
41 /IdiomSet findresource
43 % Stack: proc false dummykey [template substitute]
44 exch pop dup 1 get exch 0 get
45 % Stack: proc false substitute template
47 2 index gcheck 1 index gcheck not and {
50 3 -1 roll pop exch not exit
56 } //.bindscratch /IdiomSet resourceforall
59 currentdict /.bindscratch .undef
61 DELAYBIND NOBIND or not {
65 % ------ HalftoneTypes 6, 10, 16 and HalftoneMode ------ %
67 % This code depends on an internal HalftoneType 7 with the following keys:
68 % Width, Height, Width2, Height2, TransferFunction:
69 % as for HalftoneType 16.
70 % Thresholds: a string or bytestring holding the thresholds,
71 % (Width x Height + Width2 x Height2) x BitsPerSample / 8 bytes,
72 % as for HalftoneType 16 except that the samples may be either
74 % BitsPerSample: 8 or 16.
76 % Note that this HalftoneType never appears in halftone dictionaries given
77 % to sethalftone, only as a component in those given to .sethalftone5,
78 % so its numeric value can be chosen ad lib as long as it differs from the
79 % other values that are legal in component dictionaries for .sethalftone5
80 % (currently only 1 and 3).
82 /.makehalftone7 { % <dict> <dict> <source> <Width> <Height>
83 % (<Width2> <Height2> | null) <BPS> .makehalftone7
84 % <setdict> <dict5> { .sethalftone5 }
87 /BitsPerSample exch def
91 /Height2 1 index def /Width2 2 index def mul
95 mul add BitsPerSample 8 idiv mul .bigstring
96 % Stack: dict dict source str
97 dup type /stringtype eq { readstring } { .readbytestring } ifelse
98 not { /sethalftone load /rangecheck signalerror exit } if
99 readonly /Thresholds exch def
100 /TransferFunction .knownget { /TransferFunction exch def } if
101 % If the original Thresholds was a file, replace it with
103 dup /Thresholds get type /filetype eq {
104 dup /Thresholds [ Thresholds ] cvx 0 () .subfiledecode put
106 mark /HalftoneType 5 /Default currentdict end .dicttomark
110 /.bigstring { % <size> .bigstring <string|bytestring>
111 dup 65400 gt { .bytestring } { string } ifelse
114 /.readbytestring { % <source> <bytestring> .readbytestring
115 % <bytestring> <filled>
116 % Note that since bytestrings don't implement getinterval,
117 % if filled is false, there is no way to tell how much
119 true exch 0 1 2 index length 1 sub {
120 % Stack: source true str index
121 3 index read not { pop exch not exch exit } if
123 } for 3 -1 roll pop exch
126 /.sethalftone6 { % <dict> <dict> .sethalftone6 <setdict> <dict5>
128 % Keys: Width, Height, Thresholds, T'Function
130 1 index /Width get 2 index /Height get
131 null 8 .makehalftone7
134 /.sethalftone10 { % <dict> <dict> .sethalftone10 <setdict> <dict5>
136 % Keys: Xsquare, Ysquare, Thresholds, T'Function
137 % Note that this is the only one of these three HalftoneTypes
138 % that allows either a file or a string for Thresholds.
139 dup /Thresholds get dup type /stringtype eq { 0 () .subfiledecode } if
140 1 index /Xsquare get dup 3 index /Ysquare get dup
144 /.sethalftone16 { % <dict> <dict> .sethalftone16 <setdict> <dict5>
146 % Keys: Width, Height, Width2, Height2,
147 % Thresholds, T'Function
149 1 index /Width get 2 index /Height get
150 3 index /Width2 .knownget { % 2-rectangle case
152 } { % 1-rectangle case
154 } ifelse 16 .makehalftone7
158 6 /.sethalftone6 load def
159 10 /.sethalftone10 load def
160 16 /.sethalftone16 load def
163 % Redefine the halftone-setting operators to honor HalftoneMode.
165 /HalftoneMode getuserparam 0 eq {
168 12 { pop } repeat .getdefaulthalftone
170 { .setdefaulthalftone }
175 /HalftoneMode getuserparam 0 eq {
178 pop pop pop .getdefaulthalftone
180 { .setdefaulthalftone }
185 /HalftoneMode getuserparam 0 eq {
188 pop .getdefaulthalftone
190 { .setdefaulthalftone }
195 % ------ ImageTypes 3 and 4 (masked images) ------ %
198 dup 3 /.image3 load put
199 dup 4 /.image4 load put
200 % We also detect ImageType 103 here: it isn't worth making a separate file
202 /.image3x where { pop dup 103 /.image3x load put } if
205 % ------ Functions ------ %
207 % Define the FunctionType resource category.
208 /Generic /Category findresource dup maxlength 3 add dict .copydict begin
209 /InstanceType /integertype def
210 /FunctionType currentdict end /Category defineresource pop
212 {0 2 3} { dup /FunctionType defineresource pop } forall
214 % ------ Smooth shading ------ %
216 % Define the ShadingType resource category.
217 /Generic /Category findresource dup maxlength 3 add dict .copydict begin
218 /InstanceType /integertype def
219 /ShadingType currentdict end /Category defineresource pop
221 systemdict /.shadingtypes mark % not ll3dict
222 1 /.buildshading1 load
223 2 /.buildshading2 load
224 3 /.buildshading3 load
225 4 /.buildshading4 load
226 5 /.buildshading5 load
227 6 /.buildshading6 load
228 7 /.buildshading7 load
231 systemdict /.reuseparamdict mark
235 .dicttomark readonly put
236 /.buildshading { % <shadingdict> .buildshading <shading>
237 % Unfortunately, we always need to make the DataSource reusable,
238 % because if clipping is involved, even shfill may need to read
239 % the source data multiple times. If it weren't for this,
240 % we would only need to create a reusable stream if the ultimate
241 % source of the data is a procedure (since the library can't
242 % suspend shading to do a procedure callout).
243 dup /DataSource .knownget {
244 dup type /filetype eq {
245 //.reuseparamdict /ReusableStreamDecode filter
246 .currentglobal 1 index gcheck .setglobal
247 % Stack: shdict rsdfile saveglobal
248 2 index dup length dict copy exch .setglobal
249 dup /DataSource 4 -1 roll put exch pop
254 % The .buildshading operators use the current color space
256 dup /ShadingType get //.shadingtypes exch get
257 1 index /ColorSpace get setcolorspace exec
259 systemdict /.reuseparamdict undef
261 /.buildpattern2 { % <template> <matrix> .buildpattern2
262 % <template> <pattern>
263 % We want to build the pattern without doing gsave/grestore,
264 % since we want it to load the CIE caches.
266 mark currentcolor currentcolorspace
267 counttomark 4 add -3 roll mark 4 1 roll
268 % Stack: -mark- ..color.. cspace -mark- template matrix shadingdict
269 { .buildshading } stopped {
270 cleartomark setcolorspace setcolor pop stop
273 3 -1 roll pop counttomark 1 add 2 roll setcolorspace setcolor pop
277 2 /.buildpattern2 load put
279 /shfill { % <shadingdict> shfill -
280 % Currently, .shfill requires that the color space
281 % in the pattern be the current color space.
282 % Disable overprintmode for shfill
284 0 .setoverprintmode { .buildshading .shfill } stopped
289 % Establish an initial smoothness value that matches Adobe RIPs.
292 % ------ DeviceN color space ------ %
294 %% Replace 1 (gs_ciecs3.ps)
295 (gs_ciecs3.ps) runlibfile
297 %% Replace 1 (gs_devn.ps)
298 (gs_devn.ps) runlibfile
300 % ------ Miscellaneous ------ %
302 % Make the setoverprintmode and currentoverprintmode operators visible (3015)
303 % Because of the requirements of PDF, the .currentoverprintmode and
304 % .setoverprintmode operators have integer parameters. Thus wee need to
305 % convert the Postscript bool parameters to integers.
307 /setoverprintmode % bool setoverprint -
309 { 1 } { 0 } ifelse % convert bool to integer
313 /currentoverprintmode % - currentoverprintmode bool
315 //.currentoverprintmode
316 0 ne % convert integers to bool
319 % Define additional user and system parameters.
320 /HalftoneMode 0 .definepsuserparam
321 /MaxSuperScreen 1016 .definepsuserparam
322 pssystemparams begin % read-only, so use .forcedef
323 /MaxDisplayAndSourceList 160000 .forcedef
326 % Define the IdiomSet resource category.
328 /Generic /Category findresource dup maxlength 3 add dict .copydict begin
329 /InstanceType /dicttype def
330 currentdict end /Category defineresource pop
334 % When running in LanguageLevel 3 mode, this interpreter is supposed to be
335 % compatible with Adobe version 3010.
336 /version (3010) readonly def