]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiFontMetrics.h
Rely on Qt to handle small caps text
[lyx.git] / src / frontends / qt4 / GuiFontMetrics.h
1 // -*- C++ -*-
2 /**
3  * \file GuiFontMetrics.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 GUI_FONT_METRICS_H
13 #define GUI_FONT_METRICS_H
14
15 #include "frontends/FontMetrics.h"
16
17 #include "support/docstring.h"
18
19 #include <QFontMetrics>
20 #include <QHash>
21
22 namespace lyx {
23 namespace frontend {
24
25 class GuiFontMetrics : public FontMetrics
26 {
27 public:
28         GuiFontMetrics(QFont const & font);
29
30         virtual ~GuiFontMetrics() {}
31
32         virtual int maxAscent() const;
33         virtual int maxDescent() const;
34         virtual Dimension const defaultDimension() const;
35         virtual int width(char_type c) const;
36         virtual int ascent(char_type c) const;
37         virtual int descent(char_type c) const;
38         virtual int lbearing(char_type c) const;
39         virtual int rbearing(char_type c) const;
40         virtual int width(docstring const & s) const;
41         virtual int signedWidth(docstring const & s) const;
42         virtual Dimension const dimension(char_type c) const;
43
44         virtual void rectText(docstring const & str,
45                 int & width,
46                 int & ascent,
47                 int & descent) const;
48         virtual void buttonText(docstring const & str,
49                 int & width,
50                 int & ascent,
51                 int & descent) const;
52         ///
53         int width(QString const & str) const;
54
55 private:
56         /// Metrics on the font
57         QFontMetrics metrics_;
58
59         /// Cache of char widths
60         mutable QHash<char_type, int> width_cache_;
61
62         struct AscendDescend {
63                 int ascent;
64                 int descent;
65         };
66         /// Cache of char ascends and descends
67         mutable QHash<char_type, AscendDescend> metrics_cache_;
68         /// fill in \c metrics_cache_ at specified value.
69         AscendDescend const fillMetricsCache(char_type) const;
70
71         /// Cache of char right bearings
72         mutable QHash<char_type, int> rbearing_cache_;
73 };
74
75 } // namespace frontend
76 } // namespace lyx
77
78 #endif // GUI_FONT_METRICS_H