]> git.lyx.org Git - lyx.git/blob - src/frontends/font_metrics.h
minimal effort implementation of:
[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/types.h"
17
18 #include <string>
19
20
21 class LyXFont;
22
23 /**
24  * A namespace holding helper functions for determining
25  * the screen dimensions of fonts.
26  *
27  * The geometry is the standard typographical geometry,
28  * as follows :
29  *
30  * --------------+------------------<maxAscent
31  *               |          |
32  *               <-------> (right bearing)
33  *               <-> (left bearing)
34  * char ascent>___          |
35  *               ^   oooo   |  oooo
36  *   origin>____ |  oo  oo  | oo  oo
37  *              \|  oo  oo  | oo  oo
38  * --------------+---ooooo--|--oooo-<baseline
39  *               |      oo  |
40  * char          |  oo  oo  |
41  * descent>______|   oooo   |
42  *               <-  width ->
43  * --------------+----------+-------<maxDescent
44  *
45  */
46 namespace font_metrics {
47         /// return the maximum ascent of the font
48         int maxAscent(LyXFont const & f);
49         /// return the maximum descent of the font
50         int maxDescent(LyXFont const & f);
51         /// return the maximum descent of the font
52         inline int maxHeight(LyXFont const & f) {
53                 return maxAscent(f) + maxDescent(f);
54         }
55         /// return the ascent of the char in the font
56         int ascent(lyx::char_type c, LyXFont const & f);
57         /// return the descent of the char in the font
58         int descent(lyx::char_type c, LyXFont const & f);
59         /// return the descent of the char in the font
60         inline int height(lyx::char_type c, LyXFont const & f)
61         {
62                 return ascent(c, f) + descent(c, f);
63         }
64         /// return the left bearing of the char in the font
65         int lbearing(lyx::char_type c, LyXFont const & f);
66         /// return the right bearing of the char in the font
67         int rbearing(lyx::char_type c, LyXFont const & f);
68         /// return the inner width of the char in the font
69         inline int center(lyx::char_type c, LyXFont const & f) {
70                 return (rbearing(c, f) - lbearing(c, f)) / 2;
71         }
72         /// return the width of the string in the font
73         int width(lyx::char_type const * s, size_t n, LyXFont const & f);
74         /// return the width of the char in the font
75         inline int width(lyx::char_type c, LyXFont const & f)
76         {
77                 lyx::char_type tmp[2] = { c, L'\0'};
78                 return width(tmp, 1, f);
79         }
80         /// return the width of the string in the font
81         inline int width(lyx::docstring const & s, LyXFont const & f)
82         {
83             return s.empty() ? 0 : width(s.data(), s.length(), f);
84         }
85         /// FIXME ??
86         int signedWidth(lyx::docstring const & s, LyXFont const & f);
87         /**
88          * fill in width,ascent,descent with the values for the
89          * given string in the font.
90          */
91         void rectText(lyx::docstring const & str, LyXFont const & font,
92                 int & width,
93                 int & ascent,
94                 int & descent);
95         /**
96          * fill in width,ascent,descent with the values for the
97          * given string in the font for a button.
98          */
99         void buttonText(lyx::docstring const & str, LyXFont const & font,
100                 int & width,
101                 int & ascent,
102                 int & descent);
103 }
104
105 #endif // FONT_METRICS_H