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 em() const;
39 virtual int width(char_type c) const;
40 virtual int ascent(char_type c) const;
41 virtual int descent(char_type c) const;
42 virtual int lbearing(char_type c) const;
43 virtual int rbearing(char_type c) const;
44 virtual int width(docstring const & s) const;
45 virtual int signedWidth(docstring const & s) const;
46 virtual int pos2x(docstring const & s, int pos, bool rtl) const;
47 virtual int x2pos(docstring const & s, int & x, bool rtl) const;
48 virtual bool breakAt(docstring & s, int & x, bool rtl, bool force) const;
49 virtual Dimension const dimension(char_type c) const;
51 virtual void rectText(docstring const & str,
55 virtual void buttonText(docstring const & str,
60 int width(QString const & str) const;
66 /// Metrics on the font
67 QFontMetrics metrics_;
69 /// Cache of char widths
70 mutable QHash<char_type, int> width_cache_;
72 /// Cache of string widths
73 /// FIXME Try to use a QHash (this requires to define qHash(docstring))
74 mutable std::map<docstring, int> strwidth_cache_;
76 struct AscendDescend {
80 /// Cache of char ascends and descends
81 mutable QHash<char_type, AscendDescend> metrics_cache_;
82 /// fill in \c metrics_cache_ at specified value.
83 AscendDescend const fillMetricsCache(char_type) const;
85 /// Cache of char right bearings
86 mutable QHash<char_type, int> rbearing_cache_;
89 } // namespace frontend
92 #endif // GUI_FONT_METRICS_H