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 // Starting with version 3.1.0, Qt/X11 does its own caching of
23 // character width, so it is not necessary to provide ours.
24 #if defined(Q_WS_MACX) || defined(Q_WS_WIN32)
25 #define USE_LYX_FONTCACHE
31 class GuiFontMetrics: public FontMetrics
35 GuiFontMetrics(QFont const & font);
36 GuiFontMetrics(QFont const & font, QFont const & smallcaps_font);
38 virtual ~GuiFontMetrics() {}
40 virtual int maxAscent() const;
41 virtual int maxDescent() const;
42 #ifndef USE_LYX_FONTCACHE
43 virtual int width(char_type c) const {
44 return metrics_.width(QChar(static_cast<short int>(c)));
47 virtual int width(char_type c) const;
49 virtual int ascent(char_type c) const;
50 virtual int descent(char_type c) const;
51 virtual int lbearing(char_type c) const;
52 virtual int rbearing(char_type c) const;
53 virtual int width(char_type const * s, size_t n) const;
54 virtual int signedWidth(docstring const & s) const;
55 virtual void rectText(docstring const & str,
59 virtual void buttonText(docstring const & str,
64 int width(QString const & str) const;
67 int smallcapsWidth(QString const & s) const;
69 /// Metrics on the font
70 QFontMetrics metrics_;
71 QFontMetrics smallcaps_metrics_;
73 bool smallcaps_shape_;
75 #ifdef USE_LYX_FONTCACHE
77 /// Cache of char widths
78 /** This cache adds 20Mo of memory to the LyX executable when
79 * loading UserGuide.lyx which contains a good number of fonts. If
80 * this turns out to be too much, we can switch to a \c QHash based
83 mutable QHash<char_type, int> width_cache_;
85 struct AscendDescend {
89 mutable QHash<char_type, AscendDescend> metrics_cache_;
90 /// fill in \c metrics_cache_ at specified value.
91 void fillMetricsCache(char_type) const;
93 #endif // USE_LYX_FONTCACHE
96 } // namespace frontend
99 #endif // QT4_FONT_METRICS_H