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