xref: /plan9/sys/src/cmd/gs/src/gxchrout.c (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 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: gxchrout.c,v 1.4 2002/02/21 22:24:53 giles Exp $ */
18 #include "math_.h"
19 #include "gx.h"
20 #include "gxchrout.h"
21 #include "gxfarith.h"
22 #include "gxistate.h"
23 
24 /*
25  * Determine the flatness for rendering a character in an outline font.
26  * This may be less than the flatness in the imager state.
27  * The second argument is the default scaling for the font: 0.001 for
28  * Type 1 fonts, 1.0 for TrueType fonts.
29  */
30 double
gs_char_flatness(const gs_imager_state * pis,floatp default_scale)31 gs_char_flatness(const gs_imager_state *pis, floatp default_scale)
32 {
33     /*
34      * Set the flatness to a value that is likely to produce reasonably
35      * good-looking curves, regardless of its current value in the
36      * graphics state.  If the character is very small, set the flatness
37      * to zero, which will produce very accurate curves.
38      */
39     double cxx = fabs(pis->ctm.xx), cyy = fabs(pis->ctm.yy);
40 
41     if (is_fzero(cxx) || (cyy < cxx && !is_fzero(cyy)))
42 	cxx = cyy;
43     if (!is_xxyy(&pis->ctm)) {
44 	double cxy = fabs(pis->ctm.xy), cyx = fabs(pis->ctm.yx);
45 
46 	if (is_fzero(cxx) || (cxy < cxx && !is_fzero(cxy)))
47 	    cxx = cxy;
48 	if (is_fzero(cxx) || (cyx < cxx && !is_fzero(cyx)))
49 	    cxx = cyx;
50     }
51     /* Correct for the default scaling. */
52     cxx *= 0.001 / default_scale;
53     /* Don't let the flatness be worse than the default. */
54     if (cxx > pis->flatness)
55 	cxx = pis->flatness;
56     /* If the character is tiny, force accurate curves. */
57     if (cxx < 0.2)
58 	cxx = 0;
59     return cxx;
60 }
61