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
41 * Caution: All char_type and docstring arguments of any method of this class
42 * are no UCS4 chars or strings if the font is a symbol font. They simply
43 * denote the code points of the font instead. You have to keep this in mind
44 * when you implement the methods in a frontend. You must not pass these
45 * parameters to a unicode conversion function in particular.
55 virtual ~FontMetrics() {}
57 /// return the maximum ascent of the font
58 virtual int maxAscent() const = 0;
59 /// return the maximum descent of the font
60 virtual int maxDescent() const = 0;
61 /// return the width of the char in the font
62 virtual int width(char_type c) const = 0;
63 /// return the ascent of the char in the font
64 virtual int ascent(char_type c) const = 0;
65 /// return the descent of the char in the font
66 virtual int descent(char_type c) const = 0;
67 /// return the left bearing of the char in the font
68 virtual int lbearing(char_type c) const = 0;
69 /// return the right bearing of the char in the font
70 virtual int rbearing(char_type c) const = 0;
71 /// return the width of the string in the font
72 virtual int width(char_type const * s, size_t n) const = 0;
74 virtual int signedWidth(docstring const & s) const = 0;
76 * fill in width,ascent,descent with the values for the
77 * given string in the font.
79 virtual void rectText(docstring const & str,
82 int & descent) const = 0;
84 * fill in width,ascent,descent with the values for the
85 * given string in the font for a button.
87 virtual void buttonText(docstring const & str,
90 int & descent) const = 0;
92 /// return the maximum descent of the font
93 inline int maxHeight() const {
94 return maxAscent() + maxDescent();
97 /// return the descent of the char in the font
98 inline int height(char_type c) const
100 return ascent(c) + descent(c);
103 /// return the inner width of the char in the font
104 inline int center(char_type c) const {
105 return (rbearing(c) - lbearing(c)) / 2;
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