3 * \file GuiFontMetrics.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
12 #ifndef GUI_FONT_METRICS_H
13 #define GUI_FONT_METRICS_H
15 #include "frontends/FontMetrics.h"
17 #include "support/docstring.h"
21 #include <QFontMetrics>
27 class GuiFontMetrics : public FontMetrics
30 GuiFontMetrics(QFont const & font);
32 virtual ~GuiFontMetrics() {}
34 virtual int maxAscent() const;
35 virtual int maxDescent() const;
36 virtual Dimension const defaultDimension() const;
37 virtual int width(char_type c) const;
38 virtual int ascent(char_type c) const;
39 virtual int descent(char_type c) const;
40 virtual int lbearing(char_type c) const;
41 virtual int rbearing(char_type c) const;
42 virtual int width(docstring const & s) const;
43 virtual int signedWidth(docstring const & s) const;
44 virtual Dimension const dimension(char_type c) const;
46 virtual void rectText(docstring const & str,
50 virtual void buttonText(docstring const & str,
55 int width(QString const & str) const;
58 /// Metrics on the font
59 QFontMetrics metrics_;
61 /// Cache of char widths
62 mutable QHash<char_type, int> width_cache_;
64 /// Cache of string widths
65 /// FIXME Try to use a QHash (this requires to define qHash(docstring))
66 mutable std::map<docstring, int> strwidth_cache_;
68 struct AscendDescend {
72 /// Cache of char ascends and descends
73 mutable QHash<char_type, AscendDescend> metrics_cache_;
74 /// fill in \c metrics_cache_ at specified value.
75 AscendDescend const fillMetricsCache(char_type) const;
77 /// Cache of char right bearings
78 mutable QHash<char_type, int> rbearing_cache_;
81 } // namespace frontend
84 #endif // GUI_FONT_METRICS_H