4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * \author Abdelrazak Younes
11 * Full author contact details are available in file CREDITS.
14 #ifndef FONT_METRICS_H
15 #define FONT_METRICS_H
17 #include "support/docstring.h"
20 * A class holding helper functions for determining
21 * the screen dimensions of fonts.
23 * The geometry is the standard typographical geometry,
26 * --------------+------------------<maxAscent
28 * <-------> (right bearing)
32 * origin>____ | oo oo | oo oo
34 * --------------+---ooooo--|--oooo-<baseline
37 * descent>______| oooo |
39 * --------------+----------+-------<maxDescent
50 virtual ~FontMetrics() {}
52 /// return the maximum ascent of the font
53 virtual int maxAscent() const = 0;
54 /// return the maximum descent of the font
55 virtual int maxDescent() const = 0;
56 /// return the ascent of the char in the font
57 virtual int ascent(char_type c) const = 0;
58 /// return the descent of the char in the font
59 virtual int descent(char_type c) const = 0;
60 /// return the left bearing of the char in the font
61 virtual int lbearing(char_type c) const = 0;
62 /// return the right bearing of the char in the font
63 virtual int rbearing(char_type c) const = 0;
64 /// return the width of the string in the font
65 virtual int width(char_type const * s, size_t n) const = 0;
67 virtual int signedWidth(docstring const & s) const = 0;
69 * fill in width,ascent,descent with the values for the
70 * given string in the font.
72 virtual void rectText(docstring const & str,
75 int & descent) const = 0;
77 * fill in width,ascent,descent with the values for the
78 * given string in the font for a button.
80 virtual void buttonText(docstring const & str,
83 int & descent) const = 0;
85 /// return the maximum descent of the font
86 inline int maxHeight() const {
87 return maxAscent() + maxDescent();
90 /// return the descent of the char in the font
91 inline int height(char_type c) const
93 return ascent(c) + descent(c);
96 /// return the inner width of the char in the font
97 inline int center(char_type c) const {
98 return (rbearing(c) - lbearing(c)) / 2;
101 /// return the width of the char in the font
102 inline int width(char_type c) const
104 char_type tmp[2] = { c, L'\0'};
105 return width(tmp, 1);
108 /// return the width of the string in the font
109 inline int width(docstring const & s) const
111 return s.empty() ? 0 : width(s.data(), s.length());
116 } // namespace frontend
120 /// Implementation is in Application.C
121 frontend::FontMetrics const & theFontMetrics(LyXFont const & f);
125 #endif // FONT_METRICS_H