fontaccel.c revision 23a0898a
1/* $Xorg: fontaccel.c,v 1.4 2001/02/09 02:04:04 xorgcvs Exp $ */
2
3/*
4
5Copyright 1990, 1998  The Open Group
6
7Permission to use, copy, modify, distribute, and sell this software and its
8documentation for any purpose is hereby granted without fee, provided that
9the above copyright notice appear in all copies and that both that
10copyright notice and this permission notice appear in supporting
11documentation.
12
13The above copyright notice and this permission notice shall be included
14in all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
20OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22OTHER DEALINGS IN THE SOFTWARE.
23
24Except as contained in this notice, the name of The Open Group shall
25not be used in advertising or otherwise to promote the sale, use or
26other dealings in this Software without prior written authorization
27from The Open Group.
28
29*/
30/* $XFree86: xc/lib/font/util/fontaccel.c,v 1.6 2001/01/17 19:43:33 dawes Exp $ */
31
32/*
33 * Author:  Keith Packard, MIT X Consortium
34 */
35
36#ifdef HAVE_CONFIG_H
37#include <config.h>
38#endif
39#include    <X11/fonts/fontmisc.h>
40#include    <X11/fonts/fontstruct.h>
41#include    <X11/fonts/fontutil.h>
42
43void
44FontComputeInfoAccelerators(FontInfoPtr pFontInfo)
45{
46    pFontInfo->noOverlap = FALSE;
47    if (pFontInfo->maxOverlap <= pFontInfo->minbounds.leftSideBearing)
48	pFontInfo->noOverlap = TRUE;
49
50    if ((pFontInfo->minbounds.ascent == pFontInfo->maxbounds.ascent) &&
51	    (pFontInfo->minbounds.descent == pFontInfo->maxbounds.descent) &&
52	    (pFontInfo->minbounds.leftSideBearing ==
53	     pFontInfo->maxbounds.leftSideBearing) &&
54	    (pFontInfo->minbounds.rightSideBearing ==
55	     pFontInfo->maxbounds.rightSideBearing) &&
56	    (pFontInfo->minbounds.characterWidth ==
57	     pFontInfo->maxbounds.characterWidth) &&
58      (pFontInfo->minbounds.attributes == pFontInfo->maxbounds.attributes)) {
59	pFontInfo->constantMetrics = TRUE;
60	if ((pFontInfo->maxbounds.leftSideBearing == 0) &&
61		(pFontInfo->maxbounds.rightSideBearing ==
62		 pFontInfo->maxbounds.characterWidth) &&
63		(pFontInfo->maxbounds.ascent == pFontInfo->fontAscent) &&
64		(pFontInfo->maxbounds.descent == pFontInfo->fontDescent))
65	    pFontInfo->terminalFont = TRUE;
66	else
67	    pFontInfo->terminalFont = FALSE;
68    } else {
69	pFontInfo->constantMetrics = FALSE;
70	pFontInfo->terminalFont = FALSE;
71    }
72    if (pFontInfo->minbounds.characterWidth == pFontInfo->maxbounds.characterWidth)
73	pFontInfo->constantWidth = TRUE;
74    else
75	pFontInfo->constantWidth = FALSE;
76
77    if ((pFontInfo->minbounds.leftSideBearing >= 0) &&
78	    (pFontInfo->maxOverlap <= 0) &&
79	    (pFontInfo->minbounds.ascent >= -pFontInfo->fontDescent) &&
80	    (pFontInfo->maxbounds.ascent <= pFontInfo->fontAscent) &&
81	    (-pFontInfo->minbounds.descent <= pFontInfo->fontAscent) &&
82	    (pFontInfo->maxbounds.descent <= pFontInfo->fontDescent))
83	pFontInfo->inkInside = TRUE;
84    else
85	pFontInfo->inkInside = FALSE;
86}
87
88int
89FontCouldBeTerminal(FontInfoPtr pFontInfo)
90{
91    if ((pFontInfo->minbounds.leftSideBearing >= 0) &&
92	    (pFontInfo->maxbounds.rightSideBearing <= pFontInfo->maxbounds.characterWidth) &&
93	    (pFontInfo->minbounds.characterWidth == pFontInfo->maxbounds.characterWidth) &&
94	    (pFontInfo->maxbounds.ascent <= pFontInfo->fontAscent) &&
95	    (pFontInfo->maxbounds.descent <= pFontInfo->fontDescent) &&
96	    (pFontInfo->maxbounds.leftSideBearing != 0 ||
97	     pFontInfo->minbounds.rightSideBearing != pFontInfo->minbounds.characterWidth ||
98	     pFontInfo->minbounds.ascent != pFontInfo->fontAscent ||
99	     pFontInfo->minbounds.descent != pFontInfo->fontDescent)) {
100	/* blow off font with nothing but a SPACE */
101	if (pFontInfo->maxbounds.ascent == 0 &&
102	    pFontInfo->maxbounds.descent == 0)
103		return FALSE;
104	return TRUE;
105    }
106    return FALSE;
107}
108