]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiFontMetrics.h
a2c57ecc8bdf3d25282ca7e756e5671e073a9489
[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 <map>
20
21 #include <QFontMetrics>
22 #include <QHash>
23
24 namespace lyx {
25 namespace frontend {
26
27 class GuiFontMetrics : public FontMetrics
28 {
29 public:
30         GuiFontMetrics(QFont const & font);
31
32         virtual ~GuiFontMetrics() {}
33
34         virtual int maxAscent() const;
35         virtual int maxDescent() const;
36         virtual Dimension const defaultDimension() const;
37         virtual int width(char_type c) const;
38         virtual int ascent(char_type c) const;
39         virtual int descent(char_type c) const;
40         virtual int lbearing(char_type c) const;
41         virtual int rbearing(char_type c) const;
42         virtual int width(docstring const & s) const;
43         virtual int signedWidth(docstring const & s) const;
44         virtual Dimension const dimension(char_type c) const;
45
46         virtual void rectText(docstring const & str,
47                 int & width,
48                 int & ascent,
49                 int & descent) const;
50         virtual void buttonText(docstring const & str,
51                 int & width,
52                 int & ascent,
53                 int & descent) const;
54         ///
55         int width(QString const & str) const;
56
57 private:
58         /// Metrics on the font
59         QFontMetrics metrics_;
60
61         /// Cache of char widths
62         mutable QHash<char_type, int> width_cache_;
63
64         /// Cache of string widths
65         /// FIXME Try to use a QHash (this requires to define qHash(docstring))
66         mutable std::map<docstring, int> strwidth_cache_;
67
68         struct AscendDescend {
69                 int ascent;
70                 int descent;
71         };
72         /// Cache of char ascends and descends
73         mutable QHash<char_type, AscendDescend> metrics_cache_;
74         /// fill in \c metrics_cache_ at specified value.
75         AscendDescend const fillMetricsCache(char_type) const;
76
77         /// Cache of char right bearings
78         mutable QHash<char_type, int> rbearing_cache_;
79 };
80
81 } // namespace frontend
82 } // namespace lyx
83
84 #endif // GUI_FONT_METRICS_H