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
30 size_t const MaxCharType = 65536;
40 class GuiFontMetrics: public FontMetrics
44 GuiFontMetrics(QFont const & font);
45 GuiFontMetrics(QFont const & font, QFont const & smallcaps_font);
47 virtual ~GuiFontMetrics() {}
49 virtual int maxAscent() const;
50 virtual int maxDescent() const;
51 #ifndef USE_LYX_FONTCACHE
52 virtual int width(char_type c) const {
53 return metrics_.width(QChar(static_cast<short int>(c)));
56 virtual int width(char_type c) const;
58 virtual int ascent(char_type c) const;
59 virtual int descent(char_type c) const;
60 virtual int lbearing(char_type c) const;
61 virtual int rbearing(char_type c) const;
62 virtual int width(char_type const * s, size_t n) const;
63 virtual int signedWidth(docstring const & s) const;
64 virtual void rectText(docstring const & str,
68 virtual void buttonText(docstring const & str,
73 int width(QString const & str) const;
76 int smallcapsWidth(QString const & s) const;
78 /// Metrics on the font
79 QFontMetrics metrics_;
80 QFontMetrics smallcaps_metrics_;
82 bool smallcaps_shape_;
84 #ifdef USE_LYX_FONTCACHE
85 /// fill in \c metrics_cache_ at specified value.
86 void fillCache(unsigned short val) const;
87 /// Cache of char widths
88 /** This cache adds 20Mo of memory to the LyX executable when
89 * loading UserGuide.lyx which contains a good number of fonts. If
90 * this turns out to be too much, we can switch to a \c QHash based
93 mutable CharMetrics metrics_cache_[MaxCharType];
94 #endif // USE_LYX_FONTCACHE
97 } // namespace frontend
100 #endif // QT4_FONT_METRICS_H