]> git.lyx.org Git - lyx.git/blob - src/frontends/font_metrics.h
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / font_metrics.h
1 // -*- C++ -*-
2 /**
3  * \file font_metrics.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author unknown
8  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef FONT_METRICS_H
14 #define FONT_METRICS_H
15
16 #include "support/docstring.h"
17
18
19 class LyXFont;
20
21 /**
22  * A namespace holding helper functions for determining
23  * the screen dimensions of fonts.
24  *
25  * The geometry is the standard typographical geometry,
26  * as follows :
27  *
28  * --------------+------------------<maxAscent
29  *               |          |
30  *               <-------> (right bearing)
31  *               <-> (left bearing)
32  * char ascent>___          |
33  *               ^   oooo   |  oooo
34  *   origin>____ |  oo  oo  | oo  oo
35  *              \|  oo  oo  | oo  oo
36  * --------------+---ooooo--|--oooo-<baseline
37  *               |      oo  |
38  * char          |  oo  oo  |
39  * descent>______|   oooo   |
40  *               <-  width ->
41  * --------------+----------+-------<maxDescent
42  *
43  */
44 namespace font_metrics {
45         /// return the maximum ascent of the font
46         int maxAscent(LyXFont const & f);
47         /// return the maximum descent of the font
48         int maxDescent(LyXFont const & f);
49         /// return the maximum descent of the font
50         inline int maxHeight(LyXFont const & f) {
51                 return maxAscent(f) + maxDescent(f);
52         }
53         /// return the ascent of the char in the font
54         int ascent(lyx::char_type c, LyXFont const & f);
55         /// return the descent of the char in the font
56         int descent(lyx::char_type c, LyXFont const & f);
57         /// return the descent of the char in the font
58         inline int height(lyx::char_type c, LyXFont const & f)
59         {
60                 return ascent(c, f) + descent(c, f);
61         }
62         /// return the left bearing of the char in the font
63         int lbearing(lyx::char_type c, LyXFont const & f);
64         /// return the right bearing of the char in the font
65         int rbearing(lyx::char_type c, LyXFont const & f);
66         /// return the inner width of the char in the font
67         inline int center(lyx::char_type c, LyXFont const & f) {
68                 return (rbearing(c, f) - lbearing(c, f)) / 2;
69         }
70         /// return the width of the string in the font
71         int width(lyx::char_type const * s, size_t n, LyXFont const & f);
72         /// return the width of the char in the font
73         inline int width(lyx::char_type c, LyXFont const & f)
74         {
75                 lyx::char_type tmp[2] = { c, L'\0'};
76                 return width(tmp, 1, f);
77         }
78         /// return the width of the string in the font
79         inline int width(lyx::docstring const & s, LyXFont const & f)
80         {
81             return s.empty() ? 0 : width(s.data(), s.length(), f);
82         }
83         /// FIXME ??
84         int signedWidth(lyx::docstring const & s, LyXFont const & f);
85         /**
86          * fill in width,ascent,descent with the values for the
87          * given string in the font.
88          */
89         void rectText(lyx::docstring const & str, LyXFont const & font,
90                 int & width,
91                 int & ascent,
92                 int & descent);
93         /**
94          * fill in width,ascent,descent with the values for the
95          * given string in the font for a button.
96          */
97         void buttonText(lyx::docstring const & str, LyXFont const & font,
98                 int & width,
99                 int & ascent,
100                 int & descent);
101 }
102
103 #endif // FONT_METRICS_H