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"
19 #include <QFontMetrics>
25 class GuiFontMetrics : public FontMetrics
28 GuiFontMetrics(QFont const & font);
29 GuiFontMetrics(QFont const & font, QFont const & smallcaps_font);
31 virtual ~GuiFontMetrics() {}
33 virtual int maxAscent() const;
34 virtual int maxDescent() const;
35 virtual Dimension const defaultDimension() const;
36 virtual int width(char_type c) const;
37 virtual int ascent(char_type c) const;
38 virtual int descent(char_type c) const;
39 virtual int lbearing(char_type c) const;
40 virtual int rbearing(char_type c) const;
41 virtual int width(docstring const & s) const;
42 virtual int signedWidth(docstring const & s) const;
43 virtual Dimension const dimension(char_type c) const;
45 virtual void rectText(docstring const & str,
49 virtual void buttonText(docstring const & str,
54 int width(QString const & str) const;
57 int smallcapsWidth(char_type c) const;
59 /// Metrics on the font
60 QFontMetrics metrics_;
61 QFontMetrics smallcaps_metrics_;
63 bool smallcaps_shape_;
65 /// Cache of char widths
66 mutable QHash<char_type, int> width_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