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