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"
22 #include <QFontMetrics>
28 class GuiFontMetrics : public FontMetrics
31 GuiFontMetrics(QFont const & font);
33 virtual ~GuiFontMetrics() {}
35 virtual int maxAscent() const;
36 virtual int maxDescent() const;
37 virtual Dimension const defaultDimension() const;
38 virtual int width(char_type c) const;
39 virtual int ascent(char_type c) const;
40 virtual int descent(char_type c) const;
41 virtual int lbearing(char_type c) const;
42 virtual int rbearing(char_type c) const;
43 virtual int width(docstring const & s) const;
44 virtual int signedWidth(docstring const & s) const;
45 virtual int pos2x(docstring const & s, int pos, bool rtl) const;
46 virtual int x2pos(docstring const & s, int & x, bool rtl) const;
47 virtual Dimension const dimension(char_type c) const;
49 virtual void rectText(docstring const & str,
53 virtual void buttonText(docstring const & str,
58 int width(QString const & str) const;
64 /// Metrics on the font
65 QFontMetrics metrics_;
67 /// Cache of char widths
68 mutable QHash<char_type, int> width_cache_;
70 /// Cache of string widths
71 /// FIXME Try to use a QHash (this requires to define qHash(docstring))
72 mutable std::map<docstring, int> strwidth_cache_;
74 struct AscendDescend {
78 /// Cache of char ascends and descends
79 mutable QHash<char_type, AscendDescend> metrics_cache_;
80 /// fill in \c metrics_cache_ at specified value.
81 AscendDescend const fillMetricsCache(char_type) const;
83 /// Cache of char right bearings
84 mutable QHash<char_type, int> rbearing_cache_;
87 } // namespace frontend
90 #endif // GUI_FONT_METRICS_H