1 % Copyright (C) 1990, 1996, 1997, 1998, 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_dps2.ps,v 1.5 2002/02/21 21:49:28 giles Exp $
17 % Initialization file for basic Display PostScript functions
18 % that are also included in Level 2.
22 % ------ Halftones ------ %
25 { { counttomark -1 roll } forall .dicttomark
27 /currenthalftone % - currenthalftone <dict>
28 { mark .currenthalftone
29 { { exch pop } % halftone
30 { /HalftoneType 1 % screen
31 { /Frequency /Angle /SpotFunction }
34 { /HalftoneType 2 % colorscreen
35 { /RedFrequency /RedAngle /RedSpotFunction
36 /GreenFrequency /GreenAngle /GreenSpotFunction
37 /BlueFrequency /BlueAngle /BlueSpotFunction
38 /GrayFrequency /GrayAngle /GraySpotFunction
45 % Define sethalftone so it converts types 1-4 to type 5.
46 /.makehalftoneRGBV { % <dict> <type> <keys> <keysRGBV>
47 4 -1 roll exch { 1 index exch get exch } forall 15 1 roll
48 14 -2 roll mark 15 1 roll { /Gray /Blue /Green /Red } {
49 % stack: v0 v1 v2 type keys comp
51 2 index 0 get 8 -1 roll
52 4 index 1 get 9 -1 roll
53 6 index 2 get 10 -1 roll
54 % stack: type keys comp mark k0 v0 k1 v1 k2 v2
55 /HalftoneType 10 index .dicttomark
58 /Default 1 index .dicttomark exch pop { .sethalftone5 }
61 % The value of each entry in .halftonetypes is a procedure:
62 % <setdict> <htdict> <<proc>> <setdict'> <htdict'> <sethalftoneproc>
63 % This allows us to use these procedures both for actually implementing
64 % sethalftone and for converting subsidiary dictionaries of HalftoneType 5
67 15 dict /.halftonetypes 1 index def begin
69 mark exch /Default exch .dicttomark { .sethalftone5 }
72 1 { /Frequency /Angle /SpotFunction } {
73 /RedFrequency /RedAngle /RedSpotFunction
74 /GreenFrequency /GreenAngle /GreenSpotFunction
75 /BlueFrequency /BlueAngle /BlueSpotFunction
76 /GrayFrequency /GrayAngle /GraySpotFunction
80 mark exch /Default exch .dicttomark { .sethalftone5 }
83 3 { /Width /Height /Thresholds } {
84 /RedWidth /RedHeight /RedThresholds
85 /GreenWidth /GreenHeight /GreenThresholds
86 /BlueWidth /BlueHeight /BlueThresholds
87 /GrayWidth /GrayHeight /GrayThresholds
91 pop dup length dict copy
93 % Even HalftoneType 5 dictionaries have entries other than
94 % subsidiary halftone dictionaries.
95 dup type /dicttype ne {
98 dup /HalftoneType .knownget not { 0 } if
100 % Stack: dict mark ... keyN dictN httypeN
101 % Assume that all HalftoneTypes > 5 convert to 5.
103 //.halftonetypes exch get exec pop /Default get
104 % Stack: dict mark ... keyN setdict'N htdict'N
105 counttomark 1 add index 3 index 4 -1 roll put
109 } forall .dicttomark { .sethalftone5 }
113 /sethalftone { % <dict> sethalftone -
114 % We must create the new dictionary in the same VM as the
115 % operand; otherwise, invalidaccess errors may occur.
116 .currentglobal 1 index dup gcheck .setglobal
117 dup //.halftonetypes 1 index /HalftoneType get get exec exec
120 % Redefine setscreen and setcolorscreen to recognize halftone dictionaries,
121 % and to insert the Frequency and Angle into Type 1 halftones, per
123 /.fixsethalftonescreen % <freq> <angle> <dict> .fix...screen
124 % <freq> <angle> <dict> <dict'>
125 { dup dup /HalftoneType get 1 eq
126 { dup wcheck not { dup length .copydict } if
127 dup /Frequency 5 index put
128 dup /Angle 4 index put
132 /setscreen % <ignore*2> <dict> setscreen -
133 { dup type /dicttype eq
134 { .fixsethalftonescreen sethalftone pop pop pop }
138 /setcolorscreen % <ignore*11> <dict> setcolorscreen -
139 { dup type /dicttype eq
140 { .fixsethalftonescreen sethalftone 12 { pop } repeat }
144 % Redefine currentscreen and currentcolorscreen to extract the Frequency
145 % and Angle from Type 1 halftones, per Adobe TN 5085.
146 /.fixcurrenthalftonescreen % <dict> .fix... <freq> <angle> <proc>
147 { dup /HalftoneType get 1 eq
148 { dup /Frequency get 1 index /Angle get }
152 /currentscreen % - currentscreen 60 0 <dict>
154 { { .fixcurrenthalftonescreen } % halftone
156 { 12 3 roll 9 { pop } repeat % colorscreen
157 dup type /dicttype eq { .fixcurrenthalftonescreen } if
162 /currentcolorscreen % - currentcolorscreen (60 0 <dict>)*4
164 { { .fixcurrenthalftonescreen 3 copy 6 copy } % halftone
165 { 3 copy 6 copy } % screen
171 % ------ User objects ------ %
174 .userdict /UserObjects
176 % In order to get proper error recovery behavior, we need to be careful
177 % not to pop any operands from the stack until we're done.
178 % The code below faithfully duplicates the apparent array-growing
179 % behavior of Adobe interpreters.
180 /defineuserobject { % <index> <value> defineuserobject -
181 .UserObjects .knownget {
182 length dup 3 index le {
183 % Stack: index value len
184 2 index eq { 1 index 2 mul } { 1 index 1 add } ifelse
185 .localvmarray .UserObjects get
187 .UserObjects 3 -1 roll put
192 .UserObjects 3 index 1 add 10 .max .localvmarray put
194 .UserObjects get 2 index 2 index put pop pop
196 /execuserobject { % <index> execuserobject -
197 .UserObjects get 1 index get exch pop exec
199 /undefineuserobject { % <index> undefineuserobject -
200 .UserObjects get 1 index null put pop
203 % ------ Cache control ------ %
205 % Dummy definitions for cache control operators
207 /ucachestatus { % - ucachestatus -mark- ? ? ? ? <size>
208 mark 0 0 0 0 .userdict /.ucachesize .knownget not { 0 } if
210 /setucacheparams { % -mark- ... <size> setucacheparams -
211 % Provoke an appropriate error if needed.
212 counttomark 1 lt { () 0 get } if
213 0 or .userdict /.ucachesize 2 index 0 .max put cleartomark