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) {
61 return ascent(c, f) + descent(c, f);
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;
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);
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);
82 int signedWidth(std::string const & s, LyXFont const & f);
84 * fill in width,ascent,descent with the values for the
85 * given string in the font.
87 void rectText(std::string const & str, LyXFont const & font,
92 * fill in width,ascent,descent with the values for the
93 * given string in the font for a button.
95 void buttonText(std::string const & str, LyXFont const & font,
101 #endif // FONT_METRICS_H