1 /* Copyright (C) 2000 artofcode LLC.  All rights reserved.
2 
3   This program is free software; you can redistribute it and/or modify it
4   under the terms of the GNU General Public License as published by the
5   Free Software Foundation; either version 2 of the License, or (at your
6   option) any later version.
7 
8   This program is distributed in the hope that it will be useful, but
9   WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11   General Public License for more details.
12 
13   You should have received a copy of the GNU General Public License along
14   with this program; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA, 02111-1307.
16 
17 */
18 
19 /*$Id: gxchrout.c,v 1.2.6.1.2.1 2003/01/17 00:49:03 giles Exp $ */
20 #include "math_.h"
21 #include "gx.h"
22 #include "gxchrout.h"
23 #include "gxfarith.h"
24 #include "gxistate.h"
25 
26 /*
27  * Determine the flatness for rendering a character in an outline font.
28  * This may be less than the flatness in the imager state.
29  * The second argument is the default scaling for the font: 0.001 for
30  * Type 1 fonts, 1.0 for TrueType fonts.
31  */
32 double
gs_char_flatness(const gs_imager_state * pis,floatp default_scale)33 gs_char_flatness(const gs_imager_state *pis, floatp default_scale)
34 {
35     /*
36      * Set the flatness to a value that is likely to produce reasonably
37      * good-looking curves, regardless of its current value in the
38      * graphics state.  If the character is very small, set the flatness
39      * to zero, which will produce very accurate curves.
40      */
41     double cxx = fabs(pis->ctm.xx), cyy = fabs(pis->ctm.yy);
42 
43     if (is_fzero(cxx) || (cyy < cxx && !is_fzero(cyy)))
44 	cxx = cyy;
45     if (!is_xxyy(&pis->ctm)) {
46 	double cxy = fabs(pis->ctm.xy), cyx = fabs(pis->ctm.yx);
47 
48 	if (is_fzero(cxx) || (cxy < cxx && !is_fzero(cxy)))
49 	    cxx = cxy;
50 	if (is_fzero(cxx) || (cyx < cxx && !is_fzero(cyx)))
51 	    cxx = cyx;
52     }
53     /* Correct for the default scaling. */
54     cxx *= 0.001 / default_scale;
55     /* Don't let the flatness be worse than the default. */
56     if (cxx > pis->flatness)
57 	cxx = pis->flatness;
58     /* If the character is tiny, force accurate curves. */
59     if (cxx < 0.2)
60 	cxx = 0;
61     return cxx;
62 }
63