Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
%    Copyright (C) 2001, 2002 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_patrn.ps,v 1.2 2002/11/13 20:23:10 alexcher Exp $
17
% Pattern color space method dictionary.
18
 
19
 
20
% verify that Pattern color spaces are supported
21
/.setpatternspace where
22
  { pop }
23
  { currentfile closefile }
24
ifelse
25
 
26
.currentglobal true .setglobal
27
.cspace_util begin
28
 
29
%
30
%   <name1 | array1>   get_pattern_base_cspace   <null | name2 | array2>
31
%
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.
34
%
35
/get_pattern_base_cspace
36
  {
37
    dup type /nametype eq
38
      { pop //null }
39
      {
40
        dup length 1 gt
41
          { 1 get }
42
          { pop //null }
43
        ifelse
44
      }
45
    ifelse
46
  }
47
bind def
48
 
49
 
50
%
51
%   <dict>   has_base_color   <bool>
52
%
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.
55
%
56
/has_base_color
57
  {
58
    dup //null eq
59
      { pop //false }
60
      {
61
        dup /PatternType get 1 eq
62
          { /PaintType get 2 eq }
63
          { pop //false }
64
        ifelse
65
      }
66
    ifelse
67
  }
68
bind def
69
 
70
%
71
%   <c1> ... <cn>  <pattern_dict>  <pattern_cspace>
72
%   get_pattern_base_color
73
%   <c1> ... <cn>  <base_cspace>  true
74
% or
75
%   <?c1?> ... <?cn?>  <dict>  <pattern>
76
%   get_pattern_base_color
77
%   false
78
%
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.
83
%
84
/get_pattern_base_color
85
  {
86
    exch //has_base_color exec
87
      { 1 get //true }
88
      { pop //false }
89
    ifelse
90
  }
91
bind def
92
 
93
 
94
colorspacedict
95
/Pattern
96
  mark
97
    /cs_potential_indexed_base false
98
    /cs_potential_pattern_base false
99
    /cs_potential_alternate false
100
    /cs_potential_icc_alternate false
101
 
102
    %
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).
108
    %
109
    /cs_get_ncomps
110
      {
111
        //get_pattern_base_cspace exec dup //null eq
112
          { pop 0 }
113
          //.cs_get_ncomps
114
        ifelse
115
        1 add neg
116
      }
117
    bind
118
 
119
    % there is no "range" for a Pattern color space
120
    /cs_get_range { {} cvlit } bind
121
 
122
    /cs_get_default_color { pop //null } bind
123
 
124
    /cs_get_currentgray
125
      {
126
        //get_pattern_base_color exec
127
          //.cs_get_currentgray
128
          { 0 }
129
        ifelse
130
      }
131
    bind
132
 
133
    /cs_get_currentrgb
134
      {
135
        //get_pattern_base_color exec
136
          //.cs_get_currentrgb
137
          { 0 0 0 }
138
        ifelse
139
      }
140
    bind
141
 
142
    /cs_get_currentcmyk
143
      {
144
        //get_pattern_base_color exec
145
          //.cs_get_currentcmyk
146
          { 0 0 0 1.0 }
147
        ifelse
148
      }
149
    bind
150
 
151
    /cs_validate
152
      {
153
        dup //get_pattern_base_cspace exec dup //null eq
154
          { pop }
155
          {
156
            //.cs_validate exec //.cs_potential_pattern_base exec not
157
              //setcspace_rangecheck
158
            if
159
          }
160
        ifelse
161
      }
162
    bind
163
 
164
    % substitute the base space if appropriate
165
    /cs_substitute
166
      {
167
        dup //get_pattern_base_cspace exec dup //null eq
168
          { pop dup }
169
          {
170
            //.cs_substitute exec 2 copy eq
171
              { pop pop dup }
172
              {
173
                % retain only the new alternate space
174
                exch pop
175
 
176
                % build all new structures in local VM
177
               .currentglobal 3 1 roll //false .setglobal
178
 
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
181
 
182
                % restore VM mode
183
                3 -1 roll .setglobal
184
              }
185
            ifelse
186
          }
187
        ifelse
188
      }
189
    bind
190
 
191
    /cs_prepare {}
192
 
193
    %
194
    % Install the current color space.
195
    %
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.
200
    %
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.
206
    %
207
    /cs_install
208
      {
209
        dup //get_pattern_base_cspace exec dup //null eq
210
          {
211
            pop
212
            dup type /nametype eq
213
              { pop { /Pattern } cvlit }
214
            if
215
            .setpatternspace
216
          }
217
          {
218
            % save the current color space
219
            currentcolorspace
220
 
221
            % set the base color space as the current color space
222
            exch //forcesetcolorspace
223
 
224
            % set the pattern color space; restore the earlier space on error
225
            mark 2 index
226
              { .setpatternspace }
227
            stopped
228
              { cleartomark setcolorspace stop }
229
              { pop pop pop }
230
            ifelse
231
          }
232
        ifelse
233
      }
234
    bind
235
 
236
 
237
    %
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.
245
    %
246
    /cs_prepare_color
247
      {
248
        % verify that the topmost operand is a pattern dictionary
249
        1 index dup type /dicttype ne
250
          {
251
            //null ne
252
              //setcspace_typecheck
253
            if
254
            pop
255
          }
256
          {
257
            dup /Implementation .knownget
258
              {
259
                type dup dup
260
                /gs_pattern1_instance_t ne exch /gs_pattern2_instance_t ne and
261
                exch xcheck not
262
                or
263
                  //setcspace_typecheck
264
                if
265
              }
266
              //setcspace_typecheck
267
            ifelse
268
 
269
            % check if base color space operands are present
270
            dup /PatternType get 1 eq
271
              {
272
                /PaintType get 2 eq
273
                  {
274
                    % verify that a base color space exists
275
                    //get_pattern_base_cspace exec dup //null eq
276
                      //setcspace_rangecheck
277
                    if
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
282
                  }
283
                  { pop }
284
                ifelse
285
              }
286
              { pop pop }
287
            ifelse
288
          }
289
        ifelse
290
      }
291
    bind
292
 
293
    /cs_complete_setcolor //pop_1
294
 
295
  .dicttomark
296
put
297
 
298
end     % .cspace_util
299
.setglobal