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
16 #include "support/types.h"
24 * A namespace holding helper functions for determining
25 * the screen dimensions of fonts.
27 * The geometry is the standard typographical geometry,
30 * --------------+------------------<maxAscent
32 * <-------> (right bearing)
36 * origin>____ | oo oo | oo oo
38 * --------------+---ooooo--|--oooo-<baseline
41 * descent>______| oooo |
43 * --------------+----------+-------<maxDescent
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);
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)
62 return ascent(c, f) + descent(c, f);
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;
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)
77 lyx::char_type tmp[2] = { c, L'\0'};
78 return width(tmp, 1, f);
80 /// return the width of the string in the font
81 inline int width(lyx::docstring const & s, LyXFont const & f)
83 return s.empty() ? 0 : width(s.data(), s.length(), f);
86 int signedWidth(lyx::docstring const & s, LyXFont const & f);
88 * fill in width,ascent,descent with the values for the
89 * given string in the font.
91 void rectText(lyx::docstring const & str, LyXFont const & font,
96 * fill in width,ascent,descent with the values for the
97 * given string in the font for a button.
99 void buttonText(lyx::docstring const & str, LyXFont const & font,
105 #endif // FONT_METRICS_H