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
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 virtual int ascent(lyx::char_type c) const;
43 int descent(lyx::char_type c) const;
44 virtual int lbearing(lyx::char_type c) const;
45 virtual int rbearing(lyx::char_type c) const;
46 virtual int width(lyx::char_type const * s, size_t n) const;
47 virtual int signedWidth(lyx::docstring const & s) const;
48 virtual void rectText(lyx::docstring const & str,
52 virtual void buttonText(lyx::docstring const & str,
58 int smallcapsWidth(QString const & s) const;
60 /// Metrics on the font
61 QFontMetrics metrics_;
62 QFontMetrics smallcaps_metrics_;
64 bool smallcaps_shape_;
66 #ifndef USE_LYX_FONTCACHE
67 /// Return pixel width for the given unicode char
68 int width(unsigned short val) const { return metrics_.width(QChar(val)); }
71 /// Return pixel width for the given unicode char
72 int width(unsigned short val) const;
74 typedef std::map<unsigned short, int> WidthCache;
75 /// Cache of char widths
76 mutable WidthCache widthcache;
77 #endif // USE_LYX_FONTCACHE
80 } // namespace frontend
83 #endif // QT4_FONT_METRICS_H