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>
21 // Starting with version 3.1.0, Qt/X11 does its own caching of
22 // character width, so it is not necessary to provide ours.
23 #if defined(Q_WS_MACX) || defined(Q_WS_WIN32)
24 #define USE_LYX_FONTCACHE
38 class GuiFontMetrics: public FontMetrics
42 GuiFontMetrics(QFont const & font);
43 GuiFontMetrics(QFont const & font, QFont const & smallcaps_font);
45 virtual ~GuiFontMetrics() {}
47 virtual int maxAscent() const;
48 virtual int maxDescent() const;
49 #ifndef USE_LYX_FONTCACHE
50 virtual int width(char_type c) const {
51 return metrics_.width(QChar(static_cast<short int>(c)));
54 virtual int width(char_type c) const;
56 virtual int ascent(char_type c) const;
57 virtual int descent(char_type c) const;
58 virtual int lbearing(char_type c) const;
59 virtual int rbearing(char_type c) const;
60 virtual int width(char_type const * s, size_t n) const;
61 virtual int signedWidth(docstring const & s) const;
62 virtual void rectText(docstring const & str,
66 virtual void buttonText(docstring const & str,
71 int width(QString const & str) const;
74 int smallcapsWidth(QString const & s) const;
76 /// Metrics on the font
77 QFontMetrics metrics_;
78 QFontMetrics smallcaps_metrics_;
80 bool smallcaps_shape_;
82 #ifdef USE_LYX_FONTCACHE
83 /// fill in \c metrics_cache_ at specified value.
84 void fillCache(unsigned short val) const;
85 /// Cache of char widths
86 /** This cache adds 20Mo of memory to the LyX executable when
87 * loading UserGuide.lyx which contains a good number of fonts. If
88 * this turns out to be too much, we can switch to a \c QHash based
91 mutable CharMetrics metrics_cache_[65536];
92 #endif // USE_LYX_FONTCACHE
95 } // namespace frontend
98 #endif // QT4_FONT_METRICS_H