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 QT4_FONT_METRICS_H
13 #define QT4_FONT_METRICS_H
15 #include "frontends/FontMetrics.h"
17 #include "support/docstring.h"
19 #include <QFontMetrics>
22 #if defined(Q_WS_MACX) || defined(Q_WS_WIN32)
23 #define USE_LYX_FONTCACHE
29 class GuiFontMetrics: public FontMetrics
33 GuiFontMetrics(QFont const & font);
34 GuiFontMetrics(QFont const & font, QFont const & smallcaps_font);
36 virtual ~GuiFontMetrics() {}
38 virtual int maxAscent() const;
39 virtual int maxDescent() const;
40 #ifndef USE_LYX_FONTCACHE
41 virtual int width(char_type c) const {
42 return metrics_.width(QChar(static_cast<short int>(c)));
45 virtual int width(char_type c) const;
47 virtual int ascent(char_type c) const;
48 virtual int descent(char_type c) const;
49 virtual int lbearing(char_type c) const;
50 virtual int rbearing(char_type c) const;
51 virtual int width(char_type const * s, size_t n) const;
52 virtual int signedWidth(docstring const & s) const;
53 virtual void rectText(docstring const & str,
57 virtual void buttonText(docstring const & str,
62 int width(QString const & str) const;
65 int smallcapsWidth(QString const & s) const;
67 /// Metrics on the font
68 QFontMetrics metrics_;
69 QFontMetrics smallcaps_metrics_;
71 bool smallcaps_shape_;
73 #ifdef USE_LYX_FONTCACHE
75 /// Cache of char widths
76 mutable QHash<char_type, int> width_cache_;
78 struct AscendDescend {
82 /// Cache of char ascends and descends
83 mutable QHash<char_type, AscendDescend> metrics_cache_;
84 /// fill in \c metrics_cache_ at specified value.
85 void fillMetricsCache(char_type) const;
87 #endif // USE_LYX_FONTCACHE
90 } // namespace frontend
93 #endif // QT4_FONT_METRICS_H