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
17 /* $Id: gscolor3.c,v 1.9 2004/09/15 07:59:18 igor Exp $ */
18 /* "Operators" for LanguageLevel 3 color facilities */
19 #include "gx.h"
20 #include "gserrors.h"
21 #include "gsmatrix.h" /* for gscolor2.h */
22 #include "gscolor3.h"
23 #include "gsptype2.h"
24 #include "gxcolor2.h" /* for gxpcolor.h */
25 #include "gxcspace.h" /* for gs_cspace_init */
26 #include "gxdcolor.h" /* for gxpcolor.h */
27 #include "gxpcolor.h" /* for gs_color_space_type_Pattern */
28 #include "gzstate.h"
29 #include "gzpath.h"
30 #include "gxpaint.h" /* (requires gx_path) */
31 #include "gxshade.h"
32
33 /* setsmoothness */
34 int
gs_setsmoothness(gs_state * pgs,floatp smoothness)35 gs_setsmoothness(gs_state * pgs, floatp smoothness)
36 {
37 pgs->smoothness =
38 (smoothness < 0 ? 0 : smoothness > 1 ? 1 : smoothness);
39 return 0;
40 }
41
42 /* currentsmoothness */
43 float
gs_currentsmoothness(const gs_state * pgs)44 gs_currentsmoothness(const gs_state * pgs)
45 {
46 return pgs->smoothness;
47 }
48
49 /* shfill */
50 int
gs_shfill(gs_state * pgs,const gs_shading_t * psh)51 gs_shfill(gs_state * pgs, const gs_shading_t * psh)
52 {
53 /*
54 * shfill is equivalent to filling the current clipping path (or, if
55 * clipping, its bounding box) with the shading, disregarding the
56 * Background if any. In order to produce reasonable high-level output,
57 * we must actually implement this by calling gs_fill rather than
58 * gs_shading_fill_path. However, filling with a shading pattern does
59 * paint the Background, so if necessary, we construct a copy of the
60 * shading with Background removed.
61 */
62 gs_pattern2_template_t pat;
63 gx_path cpath;
64 gs_matrix imat;
65 gs_client_color cc;
66 gs_color_space cs;
67 gx_device_color devc;
68 int code;
69
70 gs_pattern2_init(&pat);
71 pat.Shading = psh;
72 gs_make_identity(&imat);
73 code = gs_make_pattern(&cc, (gs_pattern_template_t *)&pat, &imat, pgs,
74 pgs->memory);
75 if (code < 0)
76 return code;
77 code = gs_pattern2_set_shfill(&cc);
78 if (code < 0)
79 return code;
80 gs_cspace_init(&cs, &gs_color_space_type_Pattern, pgs->memory, false);
81 cs.params.pattern.has_base_space = false;
82 code = cs.type->remap_color(&cc, &cs, &devc, (gs_imager_state *)pgs,
83 pgs->device, gs_color_select_texture);
84 if (code >= 0) {
85 gx_path_init_local(&cpath, pgs->memory);
86 code = gx_cpath_to_path(pgs->clip_path, &cpath);
87 if (code >= 0)
88 code = gx_fill_path(&cpath, &devc, pgs, gx_rule_winding_number,
89 fixed_0, fixed_0);
90 gx_path_free(&cpath, "gs_shfill");
91 }
92 gs_pattern_reference(&cc, -1);
93 return code;
94 }
95