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