]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiFontLoader.h
Move Color::color enum to ColorCode.h
[features.git] / src / frontends / qt4 / GuiFontLoader.h
1 // -*- C++ -*-
2 /**
3  * \file GuiFontLoader.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef QT4_FONTLOADER_H
13 #define QT4_FONTLOADER_H
14
15 #include "frontends/FontLoader.h"
16
17 #include "GuiFontMetrics.h"
18
19 #include "Encoding.h"
20 #include "Font.h"
21
22 #include <QFont>
23
24 #include <boost/scoped_ptr.hpp>
25
26 namespace lyx {
27 namespace frontend {
28
29 /**
30  * Qt font loader for LyX. Matches Fonts against
31  * actual QFont instances, and also caches metrics.
32  */
33 class GuiFontInfo
34 {
35 public:
36         GuiFontInfo(Font const & f);
37
38         /// The font instance
39         QFont font;
40         /// Metrics on the font
41         boost::scoped_ptr<GuiFontMetrics> metrics;
42 };
43
44
45 /// Hold info about a particular font
46 class GuiFontLoader : public FontLoader
47 {
48 public:
49         ///
50         GuiFontLoader();
51
52         /// Destructor
53         virtual ~GuiFontLoader() {}
54
55         virtual void update();
56         virtual bool available(Font const & f);
57         inline virtual FontMetrics const & metrics(Font const & f) {
58                 return *fontinfo(f).metrics.get();
59         }
60
61         /// Get the QFont for this Font
62         QFont const & get(Font const & f) {
63                 return fontinfo(f).font;
64         }
65
66
67         /// Get font info (font + metrics) for the given LyX font.
68         GuiFontInfo & fontinfo(Font const & f) {
69                 // fi is a reference to the pointer type (GuiFontInfo *) in the
70                 // fontinfo_ table.
71                 GuiFontInfo * & fi =
72                         fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
73                 if (!fi)
74                         fi = new GuiFontInfo(f);
75                 return *fi;
76         }
77
78 private:
79         /// BUTT ugly !
80         GuiFontInfo * fontinfo_[Font::NUM_FAMILIES][2][4][10];
81 };
82
83
84 } // namespace frontend
85 } // namespace lyx
86
87 #endif // QT4_FONTLOADER_H