]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiFontMetrics.h
* Painter.h:
[lyx.git] / src / frontends / qt4 / GuiFontMetrics.h
1 // -*- C++ -*-
2 /**
3  * \file FontMetrics.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef QT4_FONT_METRICS_H
13 #define QT4_FONT_METRICS_H
14
15 #include "frontends/FontMetrics.h"
16
17 #include "support/docstring.h"
18
19 #include <QFontMetrics>
20
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
25 #endif
26
27 namespace lyx {
28 namespace frontend {
29
30 class GuiFontMetrics: public FontMetrics
31 {
32 public:
33
34         GuiFontMetrics(QFont const & font);
35         GuiFontMetrics(QFont const & font, QFont const & smallcaps_font);
36
37         virtual ~GuiFontMetrics() {}
38
39         virtual int maxAscent() const;
40         virtual int maxDescent() const;
41         virtual int ascent(lyx::char_type c) const;
42         int descent(lyx::char_type c) const;
43         virtual int lbearing(lyx::char_type c) const;
44         virtual int rbearing(lyx::char_type c) const;
45         virtual int width(lyx::char_type const * s, size_t n) const;
46         virtual int signedWidth(lyx::docstring const & s) const;
47         virtual void rectText(lyx::docstring const & str,
48                 int & width,
49                 int & ascent,
50                 int & descent) const;
51         virtual void buttonText(lyx::docstring const & str,
52                 int & width,
53                 int & ascent,
54                 int & descent) const;
55         ///
56         int width(QString const & str) const;
57
58 private:
59         int smallcapsWidth(QString const & s) const;
60
61         /// Metrics on the font
62         QFontMetrics metrics_;
63         QFontMetrics smallcaps_metrics_;
64
65         bool smallcaps_shape_;
66
67 #ifndef USE_LYX_FONTCACHE
68         /// Return pixel width for the given unicode char
69         int width(unsigned short val) const { return metrics_.width(QChar(val)); }
70
71 #else
72         /// Return pixel width for the given unicode char
73         int width(unsigned short val) const;
74
75         /// Cache of char widths
76         mutable int widthcache_[65536];
77 #endif // USE_LYX_FONTCACHE
78 };
79
80 } // namespace frontend
81 } // namespace lyx
82
83 #endif // QT4_FONT_METRICS_H