1 % Copyright (C) 2001, 2002 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_patrn.ps,v 1.2 2002/11/13 20:23:10 alexcher Exp $
17 % Pattern color space method dictionary.
20 % verify that Pattern color spaces are supported
21 /.setpatternspace where
23 { currentfile closefile }
26 .currentglobal true .setglobal
30 % <name1 | array1> get_pattern_base_cspace <null | name2 | array2>
32 % If the Pattern color space has a base color space, push that base
33 % color space onto the stack. Otherwise, push a null object.
35 /get_pattern_base_cspace
51 % <dict> has_base_color <bool>
53 % Determine if a Pattern "color" includes a base color. This is the case
54 % if the pattern dictionary has PatternType 1 and PaintType 2.
61 dup /PatternType get 1 eq
62 { /PaintType get 2 eq }
71 % <c1> ... <cn> <pattern_dict> <pattern_cspace>
72 % get_pattern_base_color
73 % <c1> ... <cn> <base_cspace> true
75 % <?c1?> ... <?cn?> <dict> <pattern>
76 % get_pattern_base_color
79 % If a pattern dictionary has a base color, set up that base color and
80 % color space, and push true. Otherwise, just push false. It is assumed
81 % that if the pattern includes a base color, the Pattern color space
82 % has a base color space.
84 /get_pattern_base_color
86 exch //has_base_color exec
97 /cs_potential_indexed_base false
98 /cs_potential_pattern_base false
99 /cs_potential_alternate false
100 /cs_potential_icc_alternate false
103 % We employ the same convention for describing the number of
104 % components in a Pattern color space as is used by the graphic
105 % library. For pattern spaces with no underlying color space,
106 % the result is -1. If a Pattern space has an underlying color
107 % space with n components, the result is -(n + 1).
111 //get_pattern_base_cspace exec dup //null eq
119 % there is no "range" for a Pattern color space
120 /cs_get_range { {} cvlit } bind
122 /cs_get_default_color { pop //null } bind
126 //get_pattern_base_color exec
127 //.cs_get_currentgray
135 //get_pattern_base_color exec
144 //get_pattern_base_color exec
145 //.cs_get_currentcmyk
153 dup //get_pattern_base_cspace exec dup //null eq
156 //.cs_validate exec //.cs_potential_pattern_base exec not
157 //setcspace_rangecheck
164 % substitute the base space if appropriate
167 dup //get_pattern_base_cspace exec dup //null eq
170 //.cs_substitute exec 2 copy eq
173 % retain only the new alternate space
176 % build all new structures in local VM
177 .currentglobal 3 1 roll //false .setglobal
179 % construct a new array and insert the new base color space
180 1 index dup length array copy dup 1 4 -1 roll put
194 % Install the current color space.
196 % The current Ghostscript color space implementation requires that
197 % color spaces that provide a base or alternative color space set
198 % that base/alternative color space to be the current color space
199 % before attempting to set the original color space.
201 % In principle, the only errors that are possible for .setpatternspace
202 % (given that setcolorspace itself is legal) are limitcheck and/or
203 % VMerror. The Ghostscript implementation allows a few others, so
204 % we go through the full code to restore the current color space in
205 % the event of an error.
209 dup //get_pattern_base_cspace exec dup //null eq
212 dup type /nametype eq
213 { pop { /Pattern } cvlit }
218 % save the current color space
221 % set the base color space as the current color space
222 exch //forcesetcolorspace
224 % set the pattern color space; restore the earlier space on error
228 { cleartomark setcolorspace stop }
238 % Pattern dictionaries generated by makepattern will include an
239 % Implementation entry whose value is an internal data structure.
240 % Such structures are given executable type names that match their
241 % internal structure names. The names used for pattern
242 % implementations are gs_pattern1_instance_t and
243 % gs_pattern2_instance_t. It is unfortunate to have to expose such
244 % internal names at this level, but not easily avoided.
248 % verify that the topmost operand is a pattern dictionary
249 1 index dup type /dicttype ne
252 //setcspace_typecheck
257 dup /Implementation .knownget
260 /gs_pattern1_instance_t ne exch /gs_pattern2_instance_t ne and
263 //setcspace_typecheck
266 //setcspace_typecheck
269 % check if base color space operands are present
270 dup /PatternType get 1 eq
274 % verify that a base color space exists
275 //get_pattern_base_cspace exec dup //null eq
276 //setcspace_rangecheck
278 exch 1 index //.cs_get_ncomps exec
279 exch 1 index 3 add 1 roll
280 //check_num_stack exec
281 //.cs_get_ncomps exec 1 add -1 roll
293 /cs_complete_setcolor //pop_1