]> git.lizzy.rs Git - plan9front.git/blob - sys/lib/ghostscript/gs_ll3.ps
merge
[plan9front.git] / sys / lib / ghostscript / gs_ll3.ps
1 %    Copyright (C) 1997, 2000 Aladdin Enterprises.  All rights reserved.
2
3 % This software is provided AS-IS with no warranty, either express or
4 % implied.
5
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.
9
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.
15
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.
21
22 ll3dict begin
23
24 % We need LanguageLevel 2 or higher in order to have setuserparams and
25 % defineresource.
26 languagelevel dup 2 .max .setlanguagelevel
27
28 % ------ Idiom recognition ------ %
29
30 /IdiomRecognition false .definepsuserparam
31
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 {
40     (*) {
41       /IdiomSet findresource
42       false exch {
43                 % Stack: proc false dummykey [template substitute]
44         exch pop dup 1 get exch 0 get
45                 % Stack: proc false substitute template
46         3 index .eqproc {
47           2 index gcheck 1 index gcheck not and {
48             pop
49           } {
50             3 -1 roll pop exch not exit
51           } ifelse
52         } {
53           pop
54         } ifelse
55       } forall { exit } if
56     } //.bindscratch /IdiomSet resourceforall
57   } if
58 } odef
59 currentdict /.bindscratch .undef
60
61 DELAYBIND NOBIND or not { 
62   /bind /.bind load def
63 } if
64
65 % ------ HalftoneTypes 6, 10, 16 and HalftoneMode ------ %
66
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
73 %         8 or 16 bits wide.
74 %       BitsPerSample: 8 or 16.
75
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).
81
82 /.makehalftone7 {       % <dict> <dict> <source> <Width> <Height>
83                         %   (<Width2> <Height2> | null) <BPS> .makehalftone7
84                         %   <setdict> <dict5> { .sethalftone5 }
85   8 dict begin
86   /HalftoneType 7 def
87   /BitsPerSample exch def
88   dup null eq {
89     pop 0
90   } {
91     /Height2 1 index def /Width2 2 index def mul
92   } ifelse 3 1 roll
93   /Height 1 index def
94   /Width 2 index def
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
102                 % a new one.
103   dup /Thresholds get type /filetype eq {
104     dup /Thresholds [ Thresholds ] cvx 0 () .subfiledecode put
105   } if
106   mark /HalftoneType 5 /Default currentdict end .dicttomark
107   { .sethalftone5 }
108 } bind def
109
110 /.bigstring {   % <size> .bigstring <string|bytestring>
111   dup 65400 gt { .bytestring } { string } ifelse
112 } bind def
113
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
118                 % was read.
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
122     3 copy put pop pop
123   } for 3 -1 roll pop exch
124 } bind def
125
126 /.sethalftone6 {        % <dict> <dict> .sethalftone6 <setdict> <dict5>
127                         %   { .sethalftone5 }
128                         % Keys: Width, Height, Thresholds, T'Function
129   dup /Thresholds get
130   1 index /Width get 2 index /Height get
131   null 8 .makehalftone7
132 } bind def
133
134 /.sethalftone10 {       % <dict> <dict> .sethalftone10 <setdict> <dict5>
135                         %   { .sethalftone5 }
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
141   8 .makehalftone7
142 } bind def
143
144 /.sethalftone16 {       % <dict> <dict> .sethalftone16 <setdict> <dict5>
145                         %   { .sethalftone5 }
146                         % Keys: Width, Height, Width2, Height2,
147                         %   Thresholds, T'Function
148   dup /Thresholds get
149   1 index /Width get 2 index /Height get
150   3 index /Width2 .knownget {  % 2-rectangle case
151     4 index /Height2 get
152   } {                   % 1-rectangle case
153     null
154   } ifelse 16 .makehalftone7
155 } bind def
156
157 .halftonetypes begin
158   6 /.sethalftone6 load def
159   10 /.sethalftone10 load def
160   16 /.sethalftone16 load def
161 end
162
163 % Redefine the halftone-setting operators to honor HalftoneMode.
164 /setcolorscreen {
165   /HalftoneMode getuserparam 0 eq {
166     //setcolorscreen
167   } {
168     12 { pop } repeat .getdefaulthalftone
169     { //sethalftone }
170     { .setdefaulthalftone }
171     ifelse
172   } ifelse
173 } odef
174 /setscreen {
175   /HalftoneMode getuserparam 0 eq {
176     //setscreen
177   } {
178     pop pop pop .getdefaulthalftone
179     { //sethalftone }
180     { .setdefaulthalftone }
181     ifelse
182   } ifelse
183 } odef
184 /sethalftone {
185   /HalftoneMode getuserparam 0 eq {
186     //sethalftone
187   } {
188     pop .getdefaulthalftone
189     { //sethalftone }
190     { .setdefaulthalftone }
191     ifelse
192   } ifelse
193 } odef
194
195 % ------ ImageTypes 3 and 4 (masked images) ------ %
196
197 .imagetypes
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
201 % just for this.
202   /.image3x where { pop dup 103 /.image3x load put } if
203 pop
204
205 % ------ Functions ------ %
206
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
211
212 {0 2 3} { dup /FunctionType defineresource pop } forall
213
214 % ------ Smooth shading ------ %
215
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
220
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
229 .dicttomark put
230
231 systemdict /.reuseparamdict mark
232   /Intent 2
233   /AsyncRead false
234   /CloseSource true
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
250     } {
251       pop
252     } ifelse
253   } if
254         % The .buildshading operators use the current color space
255         % for ColorSpace.
256   dup /ShadingType get //.shadingtypes exch get
257   1 index /ColorSpace get setcolorspace exec
258 } bind def
259 systemdict /.reuseparamdict undef
260
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.
265   1 index /Shading get
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
271   } if
272   .buildshadingpattern
273   3 -1 roll pop counttomark 1 add 2 roll setcolorspace setcolor pop
274 } bind def
275
276 .patterntypes
277   2 /.buildpattern2 load put
278
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
283   dup gsave
284   0 .setoverprintmode { .buildshading .shfill } stopped
285   grestore { stop } if
286   pop
287 } odef
288
289 % Establish an initial smoothness value that matches Adobe RIPs.
290 0.02 setsmoothness
291
292 % ------ DeviceN color space ------ %
293
294 %% Replace 1 (gs_ciecs3.ps)
295 (gs_ciecs3.ps) runlibfile
296
297 %% Replace 1 (gs_devn.ps)
298 (gs_devn.ps) runlibfile
299
300 % ------ Miscellaneous ------ %
301
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.
306 %
307 /setoverprintmode               % bool setoverprint -
308 {
309   { 1 } { 0 } ifelse            % convert bool to integer
310   //.setoverprintmode
311 } odef
312
313 /currentoverprintmode           % - currentoverprintmode bool
314 {
315   //.currentoverprintmode
316   0 ne                          % convert integers to bool
317 } odef
318
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
324 end
325
326 % Define the IdiomSet resource category.
327 { /IdiomSet } {
328   /Generic /Category findresource dup maxlength 3 add dict .copydict begin
329     /InstanceType /dicttype def
330   currentdict end /Category defineresource pop
331 } forall
332
333 /languagelevel 3 def
334 % When running in LanguageLevel 3 mode, this interpreter is supposed to be
335 % compatible with Adobe version 3010.
336 /version (3010) readonly def
337
338 .setlanguagelevel
339
340 end                     % ll3dict