xref: /plan9/sys/src/cmd/gs/src/gxpaint.c (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1995, 1996, 1998, 1999 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: gxpaint.c,v 1.5 2004/09/09 21:01:31 igor Exp $ */
18 /* Graphics-state-aware fill and stroke procedures */
19 #include "gx.h"
20 #include "gzstate.h"
21 #include "gxdevice.h"
22 #include "gxhttile.h"
23 #include "gxpaint.h"
24 #include "gxpath.h"
25 #include "gxfont.h"
26 
caching_an_outline_font(const gs_state * pgs)27 private bool caching_an_outline_font(const gs_state * pgs)
28 {
29     return pgs->in_cachedevice > 1 &&
30 	    pgs->font != NULL &&
31 	    pgs->font->FontType != ft_user_defined &&
32 	    pgs->font->FontType != ft_CID_user_defined;
33 }
34 
35 /* Fill a path. */
36 int
gx_fill_path(gx_path * ppath,gx_device_color * pdevc,gs_state * pgs,int rule,fixed adjust_x,fixed adjust_y)37 gx_fill_path(gx_path * ppath, gx_device_color * pdevc, gs_state * pgs,
38 	     int rule, fixed adjust_x, fixed adjust_y)
39 {
40     gx_device *dev = gs_currentdevice_inline(pgs);
41     gx_clip_path *pcpath;
42     int code = gx_effective_clip_path(pgs, &pcpath);
43     gx_fill_params params;
44 
45     if (code < 0)
46 	return code;
47     params.rule = rule;
48     params.adjust.x = adjust_x;
49     params.adjust.y = adjust_y;
50     params.flatness = (caching_an_outline_font(pgs) ? 0.0 : pgs->flatness);
51     params.fill_zero_width = (adjust_x | adjust_y) != 0;
52     return (*dev_proc(dev, fill_path))
53 	(dev, (const gs_imager_state *)pgs, ppath, &params, pdevc, pcpath);
54 }
55 
56 /* Stroke a path for drawing or saving. */
57 int
gx_stroke_fill(gx_path * ppath,gs_state * pgs)58 gx_stroke_fill(gx_path * ppath, gs_state * pgs)
59 {
60     gx_device *dev = gs_currentdevice_inline(pgs);
61     gx_clip_path *pcpath;
62     int code = gx_effective_clip_path(pgs, &pcpath);
63     gx_stroke_params params;
64 
65     if (code < 0)
66 	return code;
67     params.flatness = (caching_an_outline_font(pgs) ? 0.0 : pgs->flatness);
68     return (*dev_proc(dev, stroke_path))
69 	(dev, (const gs_imager_state *)pgs, ppath, &params,
70 	 pgs->dev_color, pcpath);
71 }
72 
73 int
gx_stroke_add(gx_path * ppath,gx_path * to_path,const gs_state * pgs)74 gx_stroke_add(gx_path * ppath, gx_path * to_path,
75 	      const gs_state * pgs)
76 {
77     gx_stroke_params params;
78 
79     params.flatness = (caching_an_outline_font(pgs) ? 0.0 : pgs->flatness);
80     return gx_stroke_path_only(ppath, to_path, pgs->device,
81 			       (const gs_imager_state *)pgs,
82 			       &params, NULL, NULL);
83 }
84 
85 int
gx_imager_stroke_add(gx_path * ppath,gx_path * to_path,gx_device * dev,const gs_imager_state * pis)86 gx_imager_stroke_add(gx_path *ppath, gx_path *to_path,
87 		     gx_device *dev, const gs_imager_state *pis)
88 {
89     gx_stroke_params params;
90 
91     params.flatness = pis->flatness;
92     return gx_stroke_path_only(ppath, to_path, dev, pis,
93 			       &params, NULL, NULL);
94 }
95