]> git.lyx.org Git - lyx.git/blob - src/frontends/font_metrics.h
add <string> and other small fixes to make
[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 <string>
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 ascent of the char in the font
50         int ascent(char c, LyXFont const & f);
51         /// return the descent of the char in the font
52         int descent(char c, LyXFont const & f);
53         /// return the left bearing of the char in the font
54         int lbearing(char c, LyXFont const & f);
55         /// return the right bearing of the char in the font
56         int rbearing(char c, LyXFont const & f);
57         /// return the width of the string in the font
58         int width(char const * s, size_t n, LyXFont const & f);
59         /// return the width of the char in the font
60         inline int width(char c, LyXFont const & f) {
61                 return width(&c, 1, f);
62         }
63         /// return the width of the string in the font
64         inline int width(std::string const & s, LyXFont const & f) {
65                 if (s.empty()) return 0;
66                 return width(s.data(), s.length(), f);
67         }
68         /// FIXME ??
69         int signedWidth(std::string const & s, LyXFont const & f);
70         /**
71          * fill in width,ascent,descent with the values for the
72          * given string in the font.
73          */
74         void rectText(std::string const & str, LyXFont const & font,
75                 int & width,
76                 int & ascent,
77                 int & descent);
78         /**
79          * fill in width,ascent,descent with the values for the
80          * given string in the font for a button.
81          */
82         void buttonText(std::string const & str, LyXFont const & font,
83                 int & width,
84                 int & ascent,
85                 int & descent);
86 }
87
88 #endif // FONT_METRICS_H