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,
57 int width(QString const & str) const;
60 int smallcapsWidth(QString const & s) const;
62 /// Metrics on the font
63 QFontMetrics metrics_;
64 QFontMetrics smallcaps_metrics_;
66 bool smallcaps_shape_;
68 #ifndef USE_LYX_FONTCACHE
69 /// Return pixel width for the given unicode char
70 int width(unsigned short val) const { return metrics_.width(QChar(val)); }
73 /// Return pixel width for the given unicode char
74 int width(unsigned short val) const;
76 typedef std::map<unsigned short, int> WidthCache;
77 /// Cache of char widths
78 mutable WidthCache widthcache;
79 #endif // USE_LYX_FONTCACHE
82 } // namespace frontend
85 #endif // QT4_FONT_METRICS_H