]> git.lyx.org Git - lyx.git/blob - src/frontends/font_metrics.h
Extracted from r14281
[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                 return ascent(c, f) + descent(c, f);
62         }
63         /// return the left bearing of the char in the font
64         int lbearing(lyx::char_type c, LyXFont const & f);
65         /// return the right bearing of the char in the font
66         int rbearing(lyx::char_type c, LyXFont const & f);
67         /// return the inner width of the char in the font
68         inline int center(lyx::char_type c, LyXFont const & f) {
69                 return (rbearing(c, f) - lbearing(c, f)) / 2;
70         }
71         /// return the width of the string in the font
72         int width(char const * s, size_t n, LyXFont const & f);
73         /// return the width of the char in the font
74         inline int width(lyx::char_type c, LyXFont const & f) {
75                 return width(&c, 1, f);
76         }
77         /// return the width of the string in the font
78         inline int width(std::string const & s, LyXFont const & f) {
79                 return s.empty() ? 0 : width(s.data(), s.length(), f);
80         }
81         /// FIXME ??
82         int signedWidth(std::string const & s, LyXFont const & f);
83         /**
84          * fill in width,ascent,descent with the values for the
85          * given string in the font.
86          */
87         void rectText(std::string const & str, LyXFont const & font,
88                 int & width,
89                 int & ascent,
90                 int & descent);
91         /**
92          * fill in width,ascent,descent with the values for the
93          * given string in the font for a button.
94          */
95         void buttonText(std::string const & str, LyXFont const & font,
96                 int & width,
97                 int & ascent,
98                 int & descent);
99 }
100
101 #endif // FONT_METRICS_H