4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
10 * Full author contact details are available in file CREDITS.
13 #ifndef FONT_METRICS_H
14 #define FONT_METRICS_H
22 * A namespace holding helper functions for determining
23 * the screen dimensions of fonts.
25 * The geometry is the standard typographical geometry,
28 * --------------+------------------<maxAscent
30 * <-------> (right bearing)
34 * origin>____ | oo oo | oo oo
36 * --------------+---ooooo--|--oooo-<baseline
39 * descent>______| oooo |
41 * --------------+----------+-------<maxDescent
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);
53 /// return the ascent of the char in the font
54 int ascent(char c, LyXFont const & f);
55 /// return the descent of the char in the font
56 int descent(char c, LyXFont const & f);
57 /// return the descent of the char in the font
58 inline int height(char c, LyXFont const & f) {
59 return ascent(c, f) + descent(c, f);
61 /// return the left bearing of the char in the font
62 int lbearing(char c, LyXFont const & f);
63 /// return the right bearing of the char in the font
64 int rbearing(char c, LyXFont const & f);
65 /// return the inner width of the char in the font
66 inline int center(char c, LyXFont const & f) {
67 return (rbearing(c, f) - lbearing(c, f)) / 2;
69 /// return the width of the string in the font
70 int width(char const * s, size_t n, LyXFont const & f);
71 /// return the width of the char in the font
72 inline int width(char c, LyXFont const & f) {
73 return width(&c, 1, f);
75 /// return the width of the string in the font
76 inline int width(std::string const & s, LyXFont const & f) {
77 return s.empty() ? 0 : width(s.data(), s.length(), f);
80 int signedWidth(std::string const & s, LyXFont const & f);
82 * fill in width,ascent,descent with the values for the
83 * given string in the font.
85 void rectText(std::string const & str, LyXFont const & font,
90 * fill in width,ascent,descent with the values for the
91 * given string in the font for a button.
93 void buttonText(std::string const & str, LyXFont const & font,
99 #endif // FONT_METRICS_H